diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-01 16:31:00 -0700 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-04-01 16:31:00 -0700 |
commit | de8aed5300026cf4865509ac08298cf0fc5ca471 (patch) | |
tree | ad82a2c45e7129a3f8e6455bf59e26b4792180dc /pystache | |
parent | 1996af1c0c53da1111bb002fd3951f2f427f5c48 (diff) | |
download | pystache-de8aed5300026cf4865509ac08298cf0fc5ca471.tar.gz |
Removed View from NestedContext example and added experimental Renderer.context property.
Also corrected some test variable names (expected -> actual). :)
Diffstat (limited to 'pystache')
-rw-r--r-- | pystache/renderer.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/pystache/renderer.py b/pystache/renderer.py index ca69dc5..a02693c 100644 --- a/pystache/renderer.py +++ b/pystache/renderer.py @@ -111,6 +111,7 @@ class Renderer(object): if isinstance(search_dirs, basestring): search_dirs = [search_dirs] + self._context = None self.decode_errors = decode_errors self.escape = escape self.file_encoding = file_encoding @@ -119,6 +120,19 @@ class Renderer(object): self.search_dirs = search_dirs self.string_encoding = string_encoding + # This is an experimental way of giving views access to the current context. + # TODO: consider another approach of not giving access via a property, + # but instead letting the caller pass the initial context to the + # main render() method by reference. This approach would probably + # be less likely to be misused. + @property + def context(self): + """ + Return the current rendering context [experimental]. + + """ + return self._context + def _to_unicode_soft(self, s): """ Convert a basestring to unicode, preserving any unicode subclass. @@ -240,6 +254,7 @@ class Renderer(object): template = self._to_unicode_hard(template) context = Context.create(*context, **kwargs) + self._context = context engine = self._make_render_engine() rendered = engine.render(template, context) |