Commit 7826ec7f by Chris Jerdonek

Merged Template class into RenderEngine.

parent c7007a70
...@@ -100,7 +100,9 @@ class RenderEngine(object): ...@@ -100,7 +100,9 @@ class RenderEngine(object):
unicode subclasses (e.g. markupsafe.Markup). unicode subclasses (e.g. markupsafe.Markup).
""" """
tag_re = None tag_re = None
otag = '{{' otag = '{{'
ctag = '}}' ctag = '}}'
...@@ -155,18 +157,7 @@ class RenderEngine(object): ...@@ -155,18 +157,7 @@ class RenderEngine(object):
# don't use self.literal). # don't use self.literal).
template = unicode(template) template = unicode(template)
_template = Template() return self.render_template(template=template, context=context)
_template.to_unicode = self.literal
_template.escape = self.escape
_template.get_partial = self.load_partial
return _template.render_template(template=template, context=context)
class Template(object):
tag_re = None
otag, ctag = '{{', '}}'
def _compile_regexps(self): def _compile_regexps(self):
...@@ -193,15 +184,6 @@ class Template(object): ...@@ -193,15 +184,6 @@ class Template(object):
self.tag_re = re.compile(tag, re.M | re.X) self.tag_re = re.compile(tag, re.M | re.X)
def to_unicode(self, text):
return unicode(text)
def escape(self, text):
return cgi.escape(text, True)
def get_partial(self, name):
pass
def _get_string_value(self, context, tag_name): def _get_string_value(self, context, tag_name):
""" """
Get a value from the given context as a basestring instance. Get a value from the given context as a basestring instance.
...@@ -231,7 +213,7 @@ class Template(object): ...@@ -231,7 +213,7 @@ class Template(object):
# In case the template is an integer, for example. # In case the template is an integer, for example.
template = str(template) template = str(template)
if type(template) is not unicode: if type(template) is not unicode:
template = self.to_unicode(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):
...@@ -250,7 +232,7 @@ class Template(object): ...@@ -250,7 +232,7 @@ class Template(object):
def literal_tag_function(self, name): def literal_tag_function(self, name):
def func(context): def func(context):
s = self._get_string_value(context, name) s = self._get_string_value(context, name)
s = self.to_unicode(s) s = self.literal(s)
return s return s
return func return func
...@@ -258,7 +240,7 @@ class Template(object): ...@@ -258,7 +240,7 @@ class Template(object):
def partial_tag_function(self, name, indentation=''): def partial_tag_function(self, name, indentation=''):
def func(context): def func(context):
nonblank = re.compile(r'^(.)', re.M) nonblank = re.compile(r'^(.)', re.M)
template = self.get_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)
...@@ -290,18 +272,14 @@ class Template(object): ...@@ -290,18 +272,14 @@ class Template(object):
def parse_string_to_tree(self, template_string, delims=('{{', '}}')): def parse_string_to_tree(self, template_string, delims=('{{', '}}')):
template = Template() engine = RenderEngine(load_partial=self.load_partial, literal=self.literal, escape=self.escape)
template.otag = delims[0]
template.ctag = delims[1]
template.escape = self.escape engine.otag = delims[0]
template.get_partial = self.get_partial engine.ctag = delims[1]
template.to_unicode = self.to_unicode
template._compile_regexps() engine._compile_regexps()
return template.parse_to_tree(template=template_string) return engine.parse_to_tree(template=template_string)
def parse_to_tree(self, template, index=0): def parse_to_tree(self, template, index=0):
""" """
......
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