Commit 049a76c1 by Chris Jerdonek

Added RenderEngine.resolve_context().

parent 69c44762
...@@ -215,7 +215,7 @@ class Parser(object): ...@@ -215,7 +215,7 @@ class Parser(object):
elif tag_type == '>': elif tag_type == '>':
template = engine.read_partial(tag_key) template = engine.resolve_partial(tag_key)
# Indent before rendering. # Indent before rendering.
template = re.sub(NON_BLANK_RE, leading_whitespace + ur'\1', template) template = re.sub(NON_BLANK_RE, leading_whitespace + ur'\1', template)
func = engine._make_get_partial(template) func = engine._make_get_partial(template)
......
...@@ -65,8 +65,10 @@ class RenderEngine(object): ...@@ -65,8 +65,10 @@ class RenderEngine(object):
self.literal = literal self.literal = literal
self.load_partial = load_partial self.load_partial = load_partial
# TODO: rename context to stack throughout this module. def resolve_context(self, stack, name):
def read_partial(self, key): return stack.get(name)
def resolve_partial(self, key):
try: try:
return self.load_partial(key) return self.load_partial(key)
except TemplateNotFoundError: except TemplateNotFoundError:
...@@ -77,7 +79,7 @@ class RenderEngine(object): ...@@ -77,7 +79,7 @@ class RenderEngine(object):
Get a value from the given context as a basestring instance. Get a value from the given context as a basestring instance.
""" """
val = context.get(tag_name) val = self.resolve_context(context, tag_name)
if callable(val): if callable(val):
# According to the spec: # According to the spec:
...@@ -145,7 +147,7 @@ class RenderEngine(object): ...@@ -145,7 +147,7 @@ class RenderEngine(object):
""" """
# TODO: is there a bug because we are not using the same # TODO: is there a bug because we are not using the same
# logic as in _get_string_value()? # logic as in _get_string_value()?
data = context.get(name) data = self.resolve_context(context, name)
# Per the spec, lambdas in inverted sections are considered truthy. # Per the spec, lambdas in inverted sections are considered truthy.
if data: if data:
return u'' return u''
...@@ -164,7 +166,7 @@ class RenderEngine(object): ...@@ -164,7 +166,7 @@ class RenderEngine(object):
""" """
template = template_ template = template_
parsed_template = parsed_template_ parsed_template = parsed_template_
data = context.get(name) data = self.resolve_context(context, name)
# From the spec: # From the spec:
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment