1.1 --- a/moinformat/themes/html.py Fri Jul 12 21:54:20 2019 +0200
1.2 +++ b/moinformat/themes/html.py Fri Jul 12 22:04:11 2019 +0200
1.3 @@ -29,18 +29,27 @@
1.4
1.5 # Support a collection of links to stylesheets provided by each theme.
1.6
1.7 - link = '<link rel="stylesheet" type="text/css" charset="utf-8" media="%(media)s" href="%(root)s/_css/%(filename)s" />\n'
1.8 + link = '<link rel="stylesheet" type="text/css" charset="utf-8"' \
1.9 + ' media="%(media)s" href="%(root)s/_css/%(filename)s" />\n'
1.10 +
1.11 + bundled_link = '<style type="text/css" media="%(media)s">\n%(data)s' \
1.12 + '</style>\n'
1.13
1.14 - def get_links(self, subs):
1.15 + def get_links(self, subs, bundle=False):
1.16
1.17 - "Using 'subs', return a string containing markup linking to resources."
1.18 + """
1.19 + Using 'subs', return a string containing markup linking to resources if
1.20 + 'bundle' is a false value or omitted. If 'bundle' is a true value,
1.21 + incorporate resources within the document.
1.22 + """
1.23
1.24 d = {}
1.25 d.update(subs)
1.26
1.27 + css = self.get_resource("css")
1.28 links = []
1.29
1.30 - for filename in listdir(self.get_resource("css")):
1.31 + for filename in listdir(css):
1.32
1.33 # Only link to CSS files.
1.34
1.35 @@ -56,7 +65,11 @@
1.36 d["media"] = t[0] or "all"
1.37 d["filename"] = filename
1.38
1.39 - links.append(self.link % d)
1.40 + if bundle:
1.41 + d["data"] = self.load_resource(filename, css)
1.42 +
1.43 + template = bundle and self.bundled_link or self.link
1.44 + links.append(template % d)
1.45
1.46 return "".join(links)
1.47
1.48 @@ -73,13 +86,14 @@
1.49 "text" : text,
1.50 "title" : self.metadata.get("title") or self.metadata.get("pagename"),
1.51 }
1.52 - subs["links"] = self.get_links(subs)
1.53 + subs["links"] = self.get_links(subs, self.bundle)
1.54 return template % subs
1.55
1.56 def install_resources(self):
1.57
1.58 "Install resources for this theme."
1.59
1.60 - self.install_resource("css", "_css")
1.61 + if not self.bundle:
1.62 + self.install_resource("css", "_css")
1.63
1.64 # vim: tabstop=4 expandtab shiftwidth=4