From 5642f113679b6dc24db34e284383f2ed5729db29 Mon Sep 17 00:00:00 2001 From: Ondrej Grover Date: Wed, 5 Nov 2014 11:05:33 +0100 Subject: [PATCH] fix theme path construction --- docs/settings.rst | 2 +- docs/themes.rst | 2 +- pelican/generators.py | 17 ++++------------- pelican/settings.py | 17 +++++++++++++---- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 7d20a962..e2e938af 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -720,7 +720,7 @@ Setting name (followed by default value, if any) What does it do? the paths defined in this settings, they will be progressively overwritten. ``CSS_FILE = 'main.css'`` Specify the CSS file you want to load. -``THEMES = ['simple', ('!simple', 'simple')]`` Extra themes that can be inherited from, either +``THEMES = ['simple', ['!simple', 'simple']]`` Extra themes that can be inherited from, either implicitly (just a path to the theme) or explicitly using a prefix marker (tuple of prefix and path to theme). They can also inherit from each other, diff --git a/docs/themes.rst b/docs/themes.rst index 72923ff4..2076ad91 100644 --- a/docs/themes.rst +++ b/docs/themes.rst @@ -377,7 +377,7 @@ extra explicitly inherited theme .. code-block:: python - THEMES = ['simple', ('!simple', 'simple'), ('!foo', 'foo')] + THEMES = ['simple', ['!simple', 'simple'], ['!foo', 'foo']] You can extend parent (inherited) or sibling (your own theme) templates diff --git a/pelican/generators.py b/pelican/generators.py index a523663b..33d4b0d1 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -54,27 +54,18 @@ class Generator(object): os.path.join(self.theme, 'templates'))) self._templates_path += self.settings['EXTRA_TEMPLATES_PATHS'] - pelican_theme_path = os.path.dirname(os.path.abspath(__file__)) - simple_theme_path = os.path.join(pelican_theme_path, - "themes", "simple", "templates") - explicit_themes = {} themes = [FileSystemLoader(self._templates_path)] for theme in self.themes: - if isinstance(theme, tuple): # explicit inheritance + if isinstance(theme, list): # explicit inheritance prefix, theme_path = theme - if prefix == '!simple': - theme_path = simple_theme_path templates_path = os.path.join(theme_path, "templates") logger.debug('Template path for prefix %s: %s', prefix, templates_path) explicit_themes[prefix] = FileSystemLoader(templates_path) else: # implicit inheritance - if theme == 'simple': - templates_path = simple_theme_path - else: - templates_path = os.path.join(theme, "templates") - logger.debug('Implicit template path: %s', templates_path) + templates_path = os.path.join(theme, "templates") + logger.debug('Implicit template path: %s', templates_path) themes.append(FileSystemLoader(templates_path)) themes.append(PrefixLoader(explicit_themes)) @@ -738,7 +729,7 @@ class StaticGenerator(Generator): os.curdir) for theme in self.themes: - theme = theme[1] if isinstance(theme, tuple) else theme + theme = theme[1] if isinstance(theme, list) else theme self._copy_paths(self.settings['THEME_STATIC_PATHS'], theme, self.settings['THEME_STATIC_DIR'], self.output_path, os.curdir) diff --git a/pelican/settings.py b/pelican/settings.py index f6385589..d4a271ee 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -27,6 +27,11 @@ logger = logging.getLogger(__name__) DEFAULT_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'themes', 'notmyidea') + + +SIMPLE_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)), + 'themes', 'simple') + DEFAULT_CONFIG = { 'PATH': os.curdir, 'ARTICLE_PATHS': [''], @@ -34,7 +39,7 @@ DEFAULT_CONFIG = { 'PAGE_PATHS': ['pages'], 'PAGE_EXCLUDES': [], 'THEME': DEFAULT_THEME, - 'THEMES': [DEFAULT_THEME, ('!simple', DEFAULT_THEME)], + 'THEMES': [SIMPLE_THEME, ['!simple', SIMPLE_THEME]], 'OUTPUT_PATH': 'output', 'READERS': {}, 'STATIC_PATHS': ['images'], @@ -168,7 +173,7 @@ def read_settings(path=None, override=None): if 'THEMES' in local_settings and local_settings['THEMES']: for i, p in enumerate(local_settings['THEMES']): - explicit = isinstance(p, tuple) + explicit = isinstance(p, list) p = p[1] if explicit else p if not isabs(p): absp = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(path), p))) @@ -237,13 +242,17 @@ def configure_settings(settings): % settings['THEME']) for i, theme in enumerate(settings['THEMES']): - theme = theme[1] if isinstance(theme, tuple) else theme + explicit = isinstance(theme, list) + theme = theme[1] if explicit else theme if not os.path.isdir(theme): theme_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'themes', theme) if os.path.exists(theme_path): - settings['THEMES'][i] = theme_path + if explicit: + settings['THEMES'][i][1] = theme_path + else: + settings['THEMES'][i] = theme_path else: raise Exception("Could not find the theme %s" % theme)