# HG changeset patch # User Paul Boddie # Date 1543245017 -3600 # Node ID 47af441b48bf2be41ff5b720cad588e1cf9ad42d # Parent 6425c9e2744f21d5779eab1d1465644f0a96104f Support linking to stylesheets based on the collection of available files. diff -r 6425c9e2744f -r 47af441b48bf moinformat/themes/default/html.py --- a/moinformat/themes/default/html.py Mon Nov 26 16:05:50 2018 +0100 +++ b/moinformat/themes/default/html.py Mon Nov 26 16:10:17 2018 +0100 @@ -20,6 +20,8 @@ """ from moinformat.themes.common import Theme +from os import listdir +from os.path import splitext class DefaultHTMLTheme(Theme): @@ -28,6 +30,38 @@ name = "html" origin = __file__ + link = '\n' + + def get_links(self, subs): + + "Using 'subs', return a string containing markup linking to resources." + + d = {} + d.update(subs) + + links = [] + + for filename in listdir(self.get_resource("css")): + + # Only link to CSS files. + + if splitext(filename)[-1] != ".css": + continue + + # Filenames can have the form _.css to set the media + # type. + + t = filename.split("_") + + d["media"] = len(t) > 1 and t[0] or "all" + d["filename"] = filename + + links.append(self.link % d) + + return "".join(links) + + # Public methods. + def apply(self, text): "Apply this theme to the given 'text', returning a themed version." @@ -39,6 +73,7 @@ "text" : text, "title" : self.metadata.get("pagename"), } + subs["links"] = self.get_links(subs) return template % subs def install_resources(self): diff -r 6425c9e2744f -r 47af441b48bf moinformat/themes/default/template.html --- a/moinformat/themes/default/template.html Mon Nov 26 16:05:50 2018 +0100 +++ b/moinformat/themes/default/template.html Mon Nov 26 16:10:17 2018 +0100 @@ -2,7 +2,7 @@ %(title)s - +%(links)s