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

Delta Between Two Patch Sets: cms/converters.py

Issue 6439782653624320: Issue 2434 - Fixed: Custom filters and global functions can not be instance methods (Closed)
Left Patch Set: Created April 29, 2015, 12:06 p.m.
Right Patch Set: Record module unconditonally Created April 30, 2015, 12:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 name = os.path.basename(root) 323 name = os.path.basename(root)
324 if not hasattr(module, name): 324 if not hasattr(module, name):
325 raise Exception("Expected symbol %s not found in %s file %s" % (name, dirname, filename)) 325 raise Exception("Expected symbol %s not found in %s file %s" % (name, dirname, filename))
326 dictionary[name] = getattr(module, name) 326 dictionary[name] = getattr(module, name)
327 327
328 # HACK: The module we created here can be garbage collected because it 328 # HACK: The module we created here can be garbage collected because it
329 # isn't added to sys.modules. If a function is called and its module is 329 # isn't added to sys.modules. If a function is called and its module is
330 # gone it might cause weird errors (imports and module variables 330 # gone it might cause weird errors (imports and module variables
331 # unavailable). We avoid this situation by keeping a reference. 331 # unavailable). We avoid this situation by keeping a reference.
332 if callable(dictionary[name]) 332 self._module_refs.append(module)
333 self._module_refs.append(module)
334 333
335 self._env = jinja2.Environment(loader=self._SourceLoader(self._params["sourc e"]), autoescape=True) 334 self._env = jinja2.Environment(loader=self._SourceLoader(self._params["sourc e"]), autoescape=True)
336 self._env.filters.update(filters) 335 self._env.filters.update(filters)
337 self._env.globals.update(globals) 336 self._env.globals.update(globals)
338 337
339 def get_html(self, source): 338 def get_html(self, source):
340 template = self._env.from_string(source) 339 template = self._env.from_string(source)
341 module = template.make_module(self._params) 340 module = template.make_module(self._params)
342 for key, value in module.__dict__.iteritems(): 341 for key, value in module.__dict__.iteritems():
343 if not key.startswith("_"): 342 if not key.startswith("_"):
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 stack.pop() 393 stack.pop()
395 stack[-1]["subitems"].append(item) 394 stack[-1]["subitems"].append(item)
396 stack.append(item) 395 stack.append(item)
397 return structured 396 return structured
398 397
399 converters = { 398 converters = {
400 "html": RawConverter, 399 "html": RawConverter,
401 "md": MarkdownConverter, 400 "md": MarkdownConverter,
402 "tmpl": TemplateConverter, 401 "tmpl": TemplateConverter,
403 } 402 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld