Add theme inheritance with a default theme that will contain base templates.
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
{% if settings.google_analytics %}
|
||||
<script>
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', '{{ settings.google_analytics }}']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
{% endif %}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user