Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/cms/converters.py

Issue 6439145228468224: Added custom template loader to CMS in order to enable {% include %} and {% import %} in jinja temp… (Closed)
Patch Set: Addressed comments Created Dec. 11, 2013, 7:21 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sitescripts/utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/cms/converters.py
===================================================================
--- a/sitescripts/cms/converters.py
+++ b/sitescripts/cms/converters.py
@@ -172,6 +172,16 @@
return result
class TemplateConverter(Converter):
+ class _SourceLoader(jinja2.BaseLoader):
+ def __init__(self, source):
+ self.source = source
+
+ def get_source(self, environment, template):
+ try:
+ return self.source.read_include(template, "tmpl"), None, None
+ except Exception:
+ raise jinja2.TemplateNotFound(template)
+
def __init__(self, *args, **kwargs):
Converter.__init__(self, *args, **kwargs)
@@ -197,7 +207,7 @@
filters[func] = getattr(module, func)
filters[func].module_ref = module # Prevent garbage collection
- self._env = get_custom_template_environment(filters)
+ self._env = get_custom_template_environment(filters, self._SourceLoader(self._params["source"]))
def get_html(self, source):
template = self._env.from_string(source)
« no previous file with comments | « no previous file | sitescripts/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld