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

Unified Diff: cms/sources.py

Issue 29327966: Issue 3084 - [cms] Show full tracebacks for exceptions passing template code (Closed)
Patch Set: Created Sept. 15, 2015, 5:37 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
« cms/converters.py ('K') | « cms/converters.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/sources.py
===================================================================
--- a/cms/sources.py
+++ b/cms/sources.py
@@ -26,6 +26,18 @@
import zipfile
import logging
+import jinja2
+
+TEMPLATE_SUFFIX = '.tmpl'
+
+class SuffixTemplateLoader(jinja2.BaseLoader):
+ def __init__(self, loader, suffix=TEMPLATE_SUFFIX):
+ self.loader = loader
+ self.suffix = suffix
+
+ def get_source(self, environment, template):
+ return self.loader.get_source(environment, template + self.suffix)
+
class Source:
def resolve_link(self, url, locale):
parsed = urlparse.urlparse(url)
@@ -187,11 +199,14 @@
@staticmethod
def template_filename(template):
- return "templates/%s.tmpl" % template
+ return "templates/%s%s" % (template, TEMPLATE_SUFFIX)
def read_template(self, template):
return self.read_file(self.template_filename(template))
+ def get_template_loader(self):
+ return SuffixTemplateLoader(jinja2.FunctionLoader(self.read_file))
+
#
# Include helpers
#
@@ -294,3 +309,6 @@
def get_cache_dir(self):
return os.path.join(self._dir, "cache")
+
+ def get_template_loader(self):
+ return SuffixTemplateLoader(jinja2.FileSystemLoader(self._dir))
Sebastian Noack 2015/09/15 17:48:36 We need a loader that is aware of the filename for
« cms/converters.py ('K') | « cms/converters.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld