OLD | NEW |
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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 raise Exception("Expected function %s not found in filter file %s" % (fu
nc, filename)) | 283 raise Exception("Expected function %s not found in filter file %s" % (fu
nc, filename)) |
284 filters[func] = getattr(module, func) | 284 filters[func] = getattr(module, func) |
285 filters[func].module_ref = module # Prevent garbage collection | 285 filters[func].module_ref = module # Prevent garbage collection |
286 | 286 |
287 self._env = jinja2.Environment(loader=self._SourceLoader(self._params["sourc
e"]), autoescape=True) | 287 self._env = jinja2.Environment(loader=self._SourceLoader(self._params["sourc
e"]), autoescape=True) |
288 self._env.filters.update(filters) | 288 self._env.filters.update(filters) |
289 self._env.globals.update(globals) | 289 self._env.globals.update(globals) |
290 | 290 |
291 def get_html(self, source): | 291 def get_html(self, source): |
292 template = self._env.from_string(source) | 292 template = self._env.from_string(source) |
293 return template.render(self._params) | 293 module = template.make_module(self._params) |
| 294 for key, value in module.__dict__.iteritems(): |
| 295 if not key.startswith("_"): |
| 296 self._params[key] = value |
| 297 return unicode(module) |
294 | 298 |
295 def translate(self, default, name, comment=None): | 299 def translate(self, default, name, comment=None): |
296 # Note: We currently ignore the comment, it is only relevant when | 300 # Note: We currently ignore the comment, it is only relevant when |
297 # generating the master translation. | 301 # generating the master translation. |
298 localedata = self._params["localedata"] | 302 localedata = self._params["localedata"] |
299 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)) |
300 | 304 |
301 def get_string(self, name, page): | 305 def get_string(self, name, page): |
302 localedata = self._params["source"].read_locale(self._params["locale"], page
) | 306 localedata = self._params["source"].read_locale(self._params["locale"], page
) |
303 default = localedata[name] | 307 default = localedata[name] |
(...skipping 28 matching lines...) Expand all Loading... |
332 stack.pop() | 336 stack.pop() |
333 stack[-1]["subitems"].append(item) | 337 stack[-1]["subitems"].append(item) |
334 stack.append(item) | 338 stack.append(item) |
335 return structured | 339 return structured |
336 | 340 |
337 converters = { | 341 converters = { |
338 "html": RawConverter, | 342 "html": RawConverter, |
339 "md": MarkdownConverter, | 343 "md": MarkdownConverter, |
340 "tmpl": TemplateConverter, | 344 "tmpl": TemplateConverter, |
341 } | 345 } |
OLD | NEW |