diff options
| author | 2014-06-13 21:51:02 -0300 | |
|---|---|---|
| committer | 2014-06-13 21:51:02 -0300 | |
| commit | 58c4878526dec5510f23c812274686787d8724ba (patch) | |
| tree | 5f2374bc17adb10e15f7e5b4576595d9cc2ef17e /nikola/plugins/template | |
| parent | fa50632a9d87c3989566fed3e49c160a132e0d14 (diff) | |
Imported Upstream version 7.0.1upstream/7.0.1
Diffstat (limited to 'nikola/plugins/template')
| -rw-r--r-- | nikola/plugins/template/jinja.py | 16 | ||||
| -rw-r--r-- | nikola/plugins/template/mako.py | 22 |
2 files changed, 33 insertions, 5 deletions
diff --git a/nikola/plugins/template/jinja.py b/nikola/plugins/template/jinja.py index f14adfe..097ec96 100644 --- a/nikola/plugins/template/jinja.py +++ b/nikola/plugins/template/jinja.py @@ -51,6 +51,8 @@ class JinjaTemplates(TemplateSystem): if jinja2 is None: return self.lookup = jinja2.Environment() + self.lookup.trim_blocks = True + self.lookup.lstrip_blocks = True self.lookup.filters['tojson'] = json.dumps self.lookup.globals['enumerate'] = enumerate @@ -58,7 +60,19 @@ class JinjaTemplates(TemplateSystem): """Create a template lookup.""" if jinja2 is None: req_missing(['jinja2'], 'use this theme') - self.lookup.loader = jinja2.FileSystemLoader(directories, + self.directories = directories + self.create_lookup() + + def inject_directory(self, directory): + """if it's not there, add the directory to the lookup with lowest priority, and + recreate the lookup.""" + if directory not in self.directories: + self.directories.append(directory) + self.create_lookup() + + def create_lookup(self): + """Create a template lookup object.""" + self.lookup.loader = jinja2.FileSystemLoader(self.directories, encoding='utf-8') def set_site(self, site): diff --git a/nikola/plugins/template/mako.py b/nikola/plugins/template/mako.py index 5a23230..b9d856e 100644 --- a/nikola/plugins/template/mako.py +++ b/nikola/plugins/template/mako.py @@ -50,6 +50,8 @@ class MakoTemplates(TemplateSystem): lookup = None cache = {} filters = {} + directories = [] + cache_dir = None def get_deps(self, filename): text = util.read_file(filename) @@ -65,7 +67,7 @@ class MakoTemplates(TemplateSystem): return deps def set_directories(self, directories, cache_folder): - """Create a template lookup.""" + """Set directories and create a template lookup.""" cache_dir = os.path.join(cache_folder, '.mako.tmp') # Workaround for a Mako bug, Issue #825 if sys.version_info[0] == 2: @@ -74,12 +76,24 @@ class MakoTemplates(TemplateSystem): except UnicodeEncodeError: cache_dir = tempfile.mkdtemp() LOGGER.warning('Because of a Mako bug, setting cache_dir to {0}'.format(cache_dir)) - if os.path.exists(cache_dir): shutil.rmtree(cache_dir) + self.directories = directories + self.cache_dir = cache_dir + self.create_lookup() + + def inject_directory(self, directory): + """if it's not there, add the directory to the lookup with lowest priority, and + recreate the lookup.""" + if directory not in self.directories: + self.directories.append(directory) + self.create_lookup() + + def create_lookup(self): + """Create a template lookup object.""" self.lookup = TemplateLookup( - directories=directories, - module_directory=cache_dir, + directories=self.directories, + module_directory=self.cache_dir, output_encoding='utf-8') def set_site(self, site): |
