From de8aed5300026cf4865509ac08298cf0fc5ca471 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sun, 1 Apr 2012 16:31:00 -0700 Subject: Removed View from NestedContext example and added experimental Renderer.context property. Also corrected some test variable names (expected -> actual). :) --- pystache/renderer.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'pystache/renderer.py') 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) -- cgit v1.2.1