Add Multi-theme support

Adds multi-theme support using the new THEMES setting.
You can specify all the themes that you will be using in python
dicionary form. You can then inherit from the themes specified
in THEMES using the corresponding key in the dictionary.
This commit is contained in:
th3aftermath 2014-04-23 23:39:12 -04:00 committed by Ondrej Grover
commit b00d9ef6d1
8 changed files with 119 additions and 41 deletions

View file

@ -33,12 +33,13 @@ logger = logging.getLogger(__name__)
class Generator(object):
"""Baseclass generator"""
def __init__(self, context, settings, path, theme, output_path,
def __init__(self, context, settings, path, theme, themes, output_path,
readers_cache_name='', **kwargs):
self.context = context
self.settings = settings
self.path = path
self.theme = theme
self.themes = themes
self.output_path = output_path
for arg, value in kwargs.items():
@ -57,14 +58,25 @@ class Generator(object):
simple_loader = FileSystemLoader(os.path.join(theme_path,
"themes", "simple", "templates"))
themes = {}
for theme in self.themes:
templates_path = os.path.join(self.themes[theme], "templates")
logger.debug('Template path for theme %s: %s', theme,
templates_path)
themes[theme] = FileSystemLoader(templates_path)
loader=ChoiceLoader([
FileSystemLoader(self._templates_path),
simple_loader, # implicit inheritance
PrefixLoader({'!simple':simple_loader}),
PrefixLoader(themes) # explicit one
])
self.env = Environment(
trim_blocks=True,
lstrip_blocks=True,
loader=ChoiceLoader([
FileSystemLoader(self._templates_path),
simple_loader, # implicit inheritance
PrefixLoader({'!simple': simple_loader}) # explicit one
]),
loader=loader,
extensions=self.settings['JINJA_EXTENSIONS'],
)
@ -717,6 +729,12 @@ class StaticGenerator(Generator):
self._copy_paths(self.settings['THEME_STATIC_PATHS'], self.theme,
self.settings['THEME_STATIC_DIR'], self.output_path,
os.curdir)
for theme in self.themes:
self._copy_paths(self.settings['THEME_STATIC_PATHS'], self.themes[theme],
self.settings['THEME_STATIC_DIR'], self.output_path,
os.curdir)
# copy all Static files
for sc in self.context['staticfiles']:
source_path = os.path.join(self.path, sc.source_path)