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

Side by Side 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: Created Dec. 11, 2013, 6:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sitescripts/cms/sources.py » ('j') | sitescripts/cms/sources.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2013 Eyeo GmbH 4 # Copyright (C) 2006-2013 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 code = self._params["source"].read_file(path) 190 code = self._params["source"].read_file(path)
191 module = imp.new_module(root.replace("/", ".")) 191 module = imp.new_module(root.replace("/", "."))
192 exec code in module.__dict__ 192 exec code in module.__dict__
193 193
194 func = os.path.basename(root) 194 func = os.path.basename(root)
195 if not hasattr(module, func): 195 if not hasattr(module, func):
196 raise Exception("Expected function %s not found in filter file %s" % (fu nc, filename)) 196 raise Exception("Expected function %s not found in filter file %s" % (fu nc, filename))
197 filters[func] = getattr(module, func) 197 filters[func] = getattr(module, func)
198 filters[func].module_ref = module # Prevent garbage collection 198 filters[func].module_ref = module # Prevent garbage collection
199 199
200 self._env = get_custom_template_environment(filters) 200 self._env = get_custom_template_environment(filters, self._params["source"]. get_template_loader())
201 201
202 def get_html(self, source): 202 def get_html(self, source):
203 template = self._env.from_string(source) 203 template = self._env.from_string(source)
204 return template.render(self._params) 204 return template.render(self._params)
205 205
206 def translate(self, name, page=None, links=[]): 206 def translate(self, name, page=None, links=[]):
207 if page == None: 207 if page == None:
208 localedata = self._params["localedata"] 208 localedata = self._params["localedata"]
209 else: 209 else:
210 localedata = self._params["source"].read_locale(self._params["locale"], pa ge) 210 localedata = self._params["source"].read_locale(self._params["locale"], pa ge)
(...skipping 26 matching lines...) Expand all
237 stack.pop() 237 stack.pop()
238 stack[-1]["subitems"].append(item) 238 stack[-1]["subitems"].append(item)
239 stack.append(item) 239 stack.append(item)
240 return structured 240 return structured
241 241
242 converters = { 242 converters = {
243 "raw": RawConverter, 243 "raw": RawConverter,
244 "md": MarkdownConverter, 244 "md": MarkdownConverter,
245 "tmpl": TemplateConverter, 245 "tmpl": TemplateConverter,
246 } 246 }
OLDNEW
« no previous file with comments | « no previous file | sitescripts/cms/sources.py » ('j') | sitescripts/cms/sources.py » ('J')

Powered by Google App Engine
This is Rietveld