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: Adressed comments Created Dec. 12, 2013, 12:11 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
@@ -126,7 +126,7 @@
return converter()
raise Exception("Failed to resolve include %s in page %s" % (name, self._params["page"]))
- return re.sub(r'<\?\s*include\s+([^\s<>"]+)\s*\?>', resolve_include, text)
+ return re.sub(r'(?:<|\&lt\;)\?\s*include\s+([^\s<>"]+)\s*\?(?:>|\&gt\;)', resolve_include, text)
Wladimir Palant 2013/12/12 12:51:06 Nope, we really don't want to do this in raw HTML
Sebastian Noack 2013/12/12 13:54:39 I agree that we should do that only for markdown.
Wladimir Palant 2013/12/13 14:01:45 The other regexp applied to processing instruction
def __call__(self):
result = self.get_html(self._params[self._key])
@@ -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_file(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