# HG changeset patch # User Paul Boddie # Date 1543247563 -3600 # Node ID 38038aca413367c2bf8fa93b418b29f00f9aec92 # Parent 47af441b48bf2be41ff5b720cad588e1cf9ad42d Moved common HTML theming functionality into a separate module. diff -r 47af441b48bf -r 38038aca4133 moinformat/themes/default/html.py --- a/moinformat/themes/default/html.py Mon Nov 26 16:10:17 2018 +0100 +++ b/moinformat/themes/default/html.py Mon Nov 26 16:52:43 2018 +0100 @@ -19,69 +19,15 @@ this program. If not, see . """ -from moinformat.themes.common import Theme -from os import listdir -from os.path import splitext +from moinformat.themes.html import HTMLTheme -class DefaultHTMLTheme(Theme): +class DefaultHTMLTheme(HTMLTheme): - "A default theme." + "A default HTML theme." 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." - - template = self.load_resource("template.html") - subs = { - "encoding" : self.output.encoding, - "root" : self.linker.get_top_level() or ".", - "text" : text, - "title" : self.metadata.get("pagename"), - } - subs["links"] = self.get_links(subs) - return template % subs - - def install_resources(self): - - "Install resources for this theme." - - self.install_resource("css", "_css") - theme = DefaultHTMLTheme # vim: tabstop=4 expandtab shiftwidth=4 diff -r 47af441b48bf -r 38038aca4133 moinformat/themes/html.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/moinformat/themes/html.py Mon Nov 26 16:52:43 2018 +0100 @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +""" +Common HTML theme functionality. + +Copyright (C) 2018 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from moinformat.themes.common import Theme +from os import listdir +from os.path import splitext + +class HTMLTheme(Theme): + + "A common HTML theme abstraction." + + # Support a collection of links to stylesheets provided by each theme. + + 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." + + template = self.load_resource("template.html") + subs = { + "encoding" : self.output.encoding, + "root" : self.linker.get_top_level() or ".", + "text" : text, + "title" : self.metadata.get("pagename"), + } + subs["links"] = self.get_links(subs) + return template % subs + + def install_resources(self): + + "Install resources for this theme." + + self.install_resource("css", "_css") + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 47af441b48bf -r 38038aca4133 moinformat/themes/manifest.py --- a/moinformat/themes/manifest.py Mon Nov 26 16:10:17 2018 +0100 +++ b/moinformat/themes/manifest.py Mon Nov 26 16:52:43 2018 +0100 @@ -21,10 +21,18 @@ from moinformat.imports import get_extensions, get_mapping, get_modules +ignore = ["html"] + # Define an attribute mapping names to modules. modules = get_modules(__file__, __name__) +# Filter out modules in this package that provide common functionality. + +for m in ignore: + if modules.has_key(m): + del modules[m] + # Obtain all themes. # Use module paths to register the contexts: