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

Side by Side Diff: cms/converters.py

Issue 4923768585584640: Issue 2179 - [cms] Give Jinja2 templates a way to set global parameters (Closed)
Patch Set: Created March 19, 2015, 9:29 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 | no next file » | no next file with comments »
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-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 self._env = jinja2.Environment( 287 self._env = jinja2.Environment(
288 loader=self._SourceLoader(self._params["source"]), 288 loader=self._SourceLoader(self._params["source"]),
289 extensions=["jinja2.ext.do",], 289 extensions=["jinja2.ext.do",],
290 autoescape=True 290 autoescape=True
291 ) 291 )
292 self._env.filters.update(filters) 292 self._env.filters.update(filters)
293 self._env.globals.update(globals) 293 self._env.globals.update(globals)
294 294
295 def get_html(self, source): 295 def get_html(self, source):
296 template = self._env.from_string(source) 296 template = self._env.from_string(source)
297 return template.render(self._params) 297 return template.render(self._params, params=self._params)
Sebastian Noack 2015/03/20 09:44:36 Note that modifying the params dict won't modify t
Wladimir Palant 2015/03/20 15:31:39 The complication here: only variables set at top l
Sebastian Noack 2015/03/20 15:53:18 I think it's the best we can realistically do.
298 298
299 def translate(self, default, name, comment=None): 299 def translate(self, default, name, comment=None):
300 # Note: We currently ignore the comment, it is only relevant when 300 # Note: We currently ignore the comment, it is only relevant when
301 # generating the master translation. 301 # generating the master translation.
302 localedata = self._params["localedata"] 302 localedata = self._params["localedata"]
303 return jinja2.Markup(self.localize_string(name, default, localedata, html_es capes)) 303 return jinja2.Markup(self.localize_string(name, default, localedata, html_es capes))
304 304
305 def get_string(self, name, page): 305 def get_string(self, name, page):
306 localedata = self._params["source"].read_locale(self._params["locale"], page ) 306 localedata = self._params["source"].read_locale(self._params["locale"], page )
307 default = localedata[name] 307 default = localedata[name]
(...skipping 28 matching lines...) Expand all
336 stack.pop() 336 stack.pop()
337 stack[-1]["subitems"].append(item) 337 stack[-1]["subitems"].append(item)
338 stack.append(item) 338 stack.append(item)
339 return structured 339 return structured
340 340
341 converters = { 341 converters = {
342 "html": RawConverter, 342 "html": RawConverter,
343 "md": MarkdownConverter, 343 "md": MarkdownConverter,
344 "tmpl": TemplateConverter, 344 "tmpl": TemplateConverter,
345 } 345 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld