From 2d5fa81e055a9886f5ec652ea2fac4851dac655b Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 18 Dec 2012 00:50:42 +0100 Subject: [PATCH] Add theme inheritance with a default theme that will contain base templates. --- .../templates/analytics.html | 0 .../themes/galleria/templates/analytics.html | 13 ------------ sigal/writer.py | 21 ++++++++++++++----- 3 files changed, 16 insertions(+), 18 deletions(-) rename sigal/themes/{colorbox => default}/templates/analytics.html (100%) delete mode 100644 sigal/themes/galleria/templates/analytics.html diff --git a/sigal/themes/colorbox/templates/analytics.html b/sigal/themes/default/templates/analytics.html similarity index 100% rename from sigal/themes/colorbox/templates/analytics.html rename to sigal/themes/default/templates/analytics.html diff --git a/sigal/themes/galleria/templates/analytics.html b/sigal/themes/galleria/templates/analytics.html deleted file mode 100644 index 889a824..0000000 --- a/sigal/themes/galleria/templates/analytics.html +++ /dev/null @@ -1,13 +0,0 @@ -{% if settings.google_analytics %} - -{% endif %} diff --git a/sigal/writer.py b/sigal/writer.py index c491e6b..2467cde 100644 --- a/sigal/writer.py +++ b/sigal/writer.py @@ -34,7 +34,8 @@ import sys from clint.textui import colored from distutils.dir_util import copy_tree -from jinja2 import Environment, PackageLoader +from jinja2 import (Environment, PackageLoader, FileSystemLoader, ChoiceLoader, + PrefixLoader) from jinja2.exceptions import TemplateNotFound from os.path import abspath @@ -69,10 +70,20 @@ class Writer(): raise Exception("Impossible to find the theme %s" % self.theme) self.logger.info("Theme path : %s", self.theme) - theme_relpath = os.path.relpath(os.path.join(self.theme, 'templates'), - os.path.dirname(__file__)) - env = Environment(loader=PackageLoader('sigal', theme_relpath), - trim_blocks=True) + theme_relpath = os.path.join(self.theme, 'templates') + theme_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), + 'themes') + default_loader = FileSystemLoader(os.path.join(theme_path, 'default', + 'templates')) + + env = Environment( + loader=ChoiceLoader([ + FileSystemLoader(theme_relpath), + default_loader, # implicit inheritance + PrefixLoader({'!default': default_loader}) # explicit one + ]), + trim_blocks=True, + ) try: self.template = env.get_template(INDEX_PAGE)