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
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,

View file

@ -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

View file

@ -367,7 +367,8 @@ def main():
watchers[static_path] = folder_watcher(static_path, [''], pelican.ignore_files)
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:
if args.autoreload:

View file

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

View file

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