Commit 24907457 by Chris Jerdonek

Changed the order of a couple methods in RenderEngine.

parent 8ff50e0b
...@@ -159,7 +159,35 @@ class RenderEngine(object): ...@@ -159,7 +159,35 @@ class RenderEngine(object):
# don't use self.literal). # don't use self.literal).
template = unicode(template) template = unicode(template)
return self.render_template(template=template, context=context) return self._render_template(template=template, context=context)
def _render_template(self, template, context):
"""
Arguments:
template: template string
context: a Context instance
"""
if type(template) is not unicode:
raise Exception("Argument 'template' not unicode: %s: %s" % (type(template), repr(template)))
parse_tree = self.parse_string_to_tree(template_string=template)
return render_parse_tree(parse_tree, context, template)
def parse_string_to_tree(self, template_string, delims=None):
engine = RenderEngine(load_partial=self.load_partial,
literal=self.literal,
escape=self.escape)
if delims is not None:
engine.otag = delims[0]
engine.ctag = delims[1]
engine._compile_regexps()
return engine.parse_to_tree(template=template_string)
def _compile_regexps(self): def _compile_regexps(self):
...@@ -216,7 +244,7 @@ class RenderEngine(object): ...@@ -216,7 +244,7 @@ class RenderEngine(object):
template = str(template) template = str(template)
if type(template) is not unicode: if type(template) is not unicode:
template = self.literal(template) template = self.literal(template)
val = self.render_template(template, context) val = self._render_template(template, context)
if not isinstance(val, basestring): if not isinstance(val, basestring):
val = str(val) val = str(val)
...@@ -245,7 +273,7 @@ class RenderEngine(object): ...@@ -245,7 +273,7 @@ class RenderEngine(object):
template = self.load_partial(name) template = self.load_partial(name)
# Indent before rendering. # Indent before rendering.
template = re.sub(nonblank, indentation + r'\1', template) template = re.sub(nonblank, indentation + r'\1', template)
return self.render_template(template, context) return self._render_template(template, context)
return func return func
def section_tag_function(self, name, parse_tree_, template_, delims): def section_tag_function(self, name, parse_tree_, template_, delims):
...@@ -272,18 +300,6 @@ class RenderEngine(object): ...@@ -272,18 +300,6 @@ class RenderEngine(object):
return ''.join(parts) return ''.join(parts)
return func return func
def parse_string_to_tree(self, template_string, delims=None):
engine = RenderEngine(load_partial=self.load_partial, literal=self.literal, escape=self.escape)
if delims is not None:
engine.otag = delims[0]
engine.ctag = delims[1]
engine._compile_regexps()
return engine.parse_to_tree(template=template_string)
def parse_to_tree(self, template, index=0): def parse_to_tree(self, template, index=0):
""" """
Parse a template into a syntax tree. Parse a template into a syntax tree.
...@@ -379,17 +395,3 @@ class RenderEngine(object): ...@@ -379,17 +395,3 @@ class RenderEngine(object):
return end_index return end_index
def render_template(self, template, context):
"""
Arguments:
template: template string
context: a Context instance
"""
if type(template) is not unicode:
raise Exception("Argument 'template' not unicode: %s: %s" % (type(template), repr(template)))
parse_tree = self.parse_string_to_tree(template_string=template)
return render_parse_tree(parse_tree, context, template)
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