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
|