1.1 --- a/moinformat/themes/default/html.py Mon Nov 26 16:10:17 2018 +0100
1.2 +++ b/moinformat/themes/default/html.py Mon Nov 26 16:52:43 2018 +0100
1.3 @@ -19,69 +19,15 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from moinformat.themes.common import Theme
1.8 -from os import listdir
1.9 -from os.path import splitext
1.10 +from moinformat.themes.html import HTMLTheme
1.11
1.12 -class DefaultHTMLTheme(Theme):
1.13 +class DefaultHTMLTheme(HTMLTheme):
1.14
1.15 - "A default theme."
1.16 + "A default HTML theme."
1.17
1.18 name = "html"
1.19 origin = __file__
1.20
1.21 - link = '<link rel="stylesheet" type="text/css" charset="utf-8" media="%(media)s" href="%(root)s/_css/%(filename)s" />\n'
1.22 -
1.23 - def get_links(self, subs):
1.24 -
1.25 - "Using 'subs', return a string containing markup linking to resources."
1.26 -
1.27 - d = {}
1.28 - d.update(subs)
1.29 -
1.30 - links = []
1.31 -
1.32 - for filename in listdir(self.get_resource("css")):
1.33 -
1.34 - # Only link to CSS files.
1.35 -
1.36 - if splitext(filename)[-1] != ".css":
1.37 - continue
1.38 -
1.39 - # Filenames can have the form <media>_<name>.css to set the media
1.40 - # type.
1.41 -
1.42 - t = filename.split("_")
1.43 -
1.44 - d["media"] = len(t) > 1 and t[0] or "all"
1.45 - d["filename"] = filename
1.46 -
1.47 - links.append(self.link % d)
1.48 -
1.49 - return "".join(links)
1.50 -
1.51 - # Public methods.
1.52 -
1.53 - def apply(self, text):
1.54 -
1.55 - "Apply this theme to the given 'text', returning a themed version."
1.56 -
1.57 - template = self.load_resource("template.html")
1.58 - subs = {
1.59 - "encoding" : self.output.encoding,
1.60 - "root" : self.linker.get_top_level() or ".",
1.61 - "text" : text,
1.62 - "title" : self.metadata.get("pagename"),
1.63 - }
1.64 - subs["links"] = self.get_links(subs)
1.65 - return template % subs
1.66 -
1.67 - def install_resources(self):
1.68 -
1.69 - "Install resources for this theme."
1.70 -
1.71 - self.install_resource("css", "_css")
1.72 -
1.73 theme = DefaultHTMLTheme
1.74
1.75 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/moinformat/themes/html.py Mon Nov 26 16:52:43 2018 +0100
2.3 @@ -0,0 +1,84 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"""
2.7 +Common HTML theme functionality.
2.8 +
2.9 +Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
2.10 +
2.11 +This program is free software; you can redistribute it and/or modify it under
2.12 +the terms of the GNU General Public License as published by the Free Software
2.13 +Foundation; either version 3 of the License, or (at your option) any later
2.14 +version.
2.15 +
2.16 +This program is distributed in the hope that it will be useful, but WITHOUT
2.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
2.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
2.19 +details.
2.20 +
2.21 +You should have received a copy of the GNU General Public License along with
2.22 +this program. If not, see <http://www.gnu.org/licenses/>.
2.23 +"""
2.24 +
2.25 +from moinformat.themes.common import Theme
2.26 +from os import listdir
2.27 +from os.path import splitext
2.28 +
2.29 +class HTMLTheme(Theme):
2.30 +
2.31 + "A common HTML theme abstraction."
2.32 +
2.33 + # Support a collection of links to stylesheets provided by each theme.
2.34 +
2.35 + link = '<link rel="stylesheet" type="text/css" charset="utf-8" media="%(media)s" href="%(root)s/_css/%(filename)s" />\n'
2.36 +
2.37 + def get_links(self, subs):
2.38 +
2.39 + "Using 'subs', return a string containing markup linking to resources."
2.40 +
2.41 + d = {}
2.42 + d.update(subs)
2.43 +
2.44 + links = []
2.45 +
2.46 + for filename in listdir(self.get_resource("css")):
2.47 +
2.48 + # Only link to CSS files.
2.49 +
2.50 + if splitext(filename)[-1] != ".css":
2.51 + continue
2.52 +
2.53 + # Filenames can have the form <media>_<name>.css to set the media
2.54 + # type.
2.55 +
2.56 + t = filename.split("_")
2.57 +
2.58 + d["media"] = len(t) > 1 and t[0] or "all"
2.59 + d["filename"] = filename
2.60 +
2.61 + links.append(self.link % d)
2.62 +
2.63 + return "".join(links)
2.64 +
2.65 + # Public methods.
2.66 +
2.67 + def apply(self, text):
2.68 +
2.69 + "Apply this theme to the given 'text', returning a themed version."
2.70 +
2.71 + template = self.load_resource("template.html")
2.72 + subs = {
2.73 + "encoding" : self.output.encoding,
2.74 + "root" : self.linker.get_top_level() or ".",
2.75 + "text" : text,
2.76 + "title" : self.metadata.get("pagename"),
2.77 + }
2.78 + subs["links"] = self.get_links(subs)
2.79 + return template % subs
2.80 +
2.81 + def install_resources(self):
2.82 +
2.83 + "Install resources for this theme."
2.84 +
2.85 + self.install_resource("css", "_css")
2.86 +
2.87 +# vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/moinformat/themes/manifest.py Mon Nov 26 16:10:17 2018 +0100
3.2 +++ b/moinformat/themes/manifest.py Mon Nov 26 16:52:43 2018 +0100
3.3 @@ -21,10 +21,18 @@
3.4
3.5 from moinformat.imports import get_extensions, get_mapping, get_modules
3.6
3.7 +ignore = ["html"]
3.8 +
3.9 # Define an attribute mapping names to modules.
3.10
3.11 modules = get_modules(__file__, __name__)
3.12
3.13 +# Filter out modules in this package that provide common functionality.
3.14 +
3.15 +for m in ignore:
3.16 + if modules.has_key(m):
3.17 + del modules[m]
3.18 +
3.19 # Obtain all themes.
3.20
3.21 # Use module paths to register the contexts: