fix special handling of THEMES paths

This commit is contained in:
Ondrej Grover 2014-11-05 10:16:12 +01:00
commit ad6b483746
5 changed files with 24 additions and 15 deletions

View file

@ -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 the paths defined in this settings, they will be
progressively overwritten. progressively overwritten.
``CSS_FILE = 'main.css'`` Specify the CSS file you want to load. ``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 implicitly (just a path to the theme) or explicitly
using a prefix marker (tuple of prefix and path to using a prefix marker (tuple of prefix and path to
theme). They can also inherit from each other, theme). They can also inherit from each other,

View file

@ -377,7 +377,7 @@ extra explicitly inherited theme
.. code-block:: python .. 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 You can extend parent (inherited) or sibling (your own theme) templates

View file

@ -367,7 +367,8 @@ def main():
watchers[static_path] = folder_watcher(static_path, [''], pelican.ignore_files) watchers[static_path] = folder_watcher(static_path, [''], pelican.ignore_files)
for theme in pelican.themes: for theme in pelican.themes:
watchers[theme] = folder_watcher(pelican.themes[theme], [''], pelican.ignore_files) theme = theme[1] if isinstance(theme, tuple) else theme
watchers[theme] = folder_watcher(theme, [''], pelican.ignore_files)
try: try:
if args.autoreload: if args.autoreload:

View file

@ -71,8 +71,11 @@ class Generator(object):
explicit_themes[prefix] = FileSystemLoader(templates_path) explicit_themes[prefix] = FileSystemLoader(templates_path)
else: # implicit inheritance else: # implicit inheritance
if theme == 'simple': if theme == 'simple':
theme = simple_theme_path templates_path = simple_theme_path
themes.append(FileSystemLoader(theme)) else:
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)) themes.append(PrefixLoader(explicit_themes))
loader=ChoiceLoader(themes) loader=ChoiceLoader(themes)

View file

@ -34,7 +34,7 @@ DEFAULT_CONFIG = {
'PAGE_PATHS': ['pages'], 'PAGE_PATHS': ['pages'],
'PAGE_EXCLUDES': [], 'PAGE_EXCLUDES': [],
'THEME': DEFAULT_THEME, 'THEME': DEFAULT_THEME,
'THEMES': ('simple', ('!simple', 'simple')), 'THEMES': ['simple', ('!simple', 'simple')],
'OUTPUT_PATH': 'output', 'OUTPUT_PATH': 'output',
'READERS': {}, 'READERS': {},
'STATIC_PATHS': ['images'], 'STATIC_PATHS': ['images'],
@ -167,11 +167,16 @@ def read_settings(path=None, override=None):
if not isabs(pluginpath) else pluginpath for pluginpath in local_settings['PLUGIN_PATHS']] if not isabs(pluginpath) else pluginpath for pluginpath in local_settings['PLUGIN_PATHS']]
if 'THEMES' in local_settings and local_settings['THEMES']: if 'THEMES' in local_settings and local_settings['THEMES']:
for p in local_settings['THEMES']: for i, p in enumerate(local_settings['THEMES']):
if not isabs(local_settings['THEMES'][p]): explicit = isinstance(p, tuple)
absp = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(path), local_settings['THEMES'][p]))) 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)))
if os.path.exists(absp): if os.path.exists(absp):
local_settings['THEMES'][p] = absp if explicit:
local_settings['THEMES'][i][1] = absp
else:
local_settings['THEMES'][i] = absp
else: else:
local_settings = copy.deepcopy(DEFAULT_CONFIG) local_settings = copy.deepcopy(DEFAULT_CONFIG)
@ -231,14 +236,14 @@ def configure_settings(settings):
raise Exception("Could not find the theme %s" raise Exception("Could not find the theme %s"
% settings['THEME']) % settings['THEME'])
for theme in settings['THEMES']: for i, theme in enumerate(settings['THEMES']):
if not os.path.isdir(settings['THEMES'][theme]): theme = theme[1] if isinstance(theme, tuple) else theme
if not os.path.isdir(theme):
theme_path = os.path.join( theme_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.path.dirname(os.path.abspath(__file__)),
'themes', 'themes', theme)
settings['THEMES'][theme])
if os.path.exists(theme_path): if os.path.exists(theme_path):
settings['THEMES'][theme] = theme_path settings['THEMES'][i] = theme_path
else: else:
raise Exception("Could not find the theme %s" raise Exception("Could not find the theme %s"
% theme) % theme)