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

Unified Diff: sitescripts/cms/sources.py

Issue 6439145228468224: Added custom template loader to CMS in order to enable {% include %} and {% import %} in jinja temp… (Closed)
Patch Set: Created Dec. 11, 2013, 6:31 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 | « sitescripts/cms/converters.py ('k') | sitescripts/utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/cms/sources.py
===================================================================
--- a/sitescripts/cms/sources.py
+++ b/sitescripts/cms/sources.py
@@ -18,6 +18,7 @@
import sys, os, subprocess, zipfile, json, urlparse, codecs
from StringIO import StringIO
from ConfigParser import SafeConfigParser
+import jinja2
class Source:
def resolve_link(self, url, locale):
@@ -166,6 +167,9 @@
def read_template(self, template):
return self.read_file(self.template_filename(template))
+ def get_template_loader(self):
+ return SourceLoader(self)
+
#
# Include helpers
#
@@ -259,3 +263,13 @@
do_list(path, relpath + filename + "/")
do_list(self.get_path(subdir), "")
return result
+
+class SourceLoader(jinja2.BaseLoader):
Wladimir Palant 2013/12/11 18:46:02 I don't think that Jinja-specific functionality be
+ def __init__(self, source):
+ self.source = source
+
+ def get_source(self, environment, template):
+ try:
+ return self.source.read_file(template + '.tmpl'), None, None
Wladimir Palant 2013/12/11 18:46:02 I think this should be self.source.read_include(te
Sebastian Noack 2013/12/11 22:20:14 I've already addressed that, but I would like to u
Wladimir Palant 2013/12/12 07:16:54 Yes, you are right. We might want to extend the de
+ except Exception:
+ raise jinja2.TemplateNotFound(template)
« no previous file with comments | « sitescripts/cms/converters.py ('k') | sitescripts/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld