1
0
Fork 0
forked from github/pelican

fix theme path construction

This commit is contained in:
Ondrej Grover 2014-11-05 11:05:33 +01:00
commit 5642f11367
4 changed files with 19 additions and 19 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

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

View file

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