Commit c7007a70 by Chris Jerdonek

The Template class no longer has a template attribute.

parent 47f24b4e
...@@ -155,7 +155,7 @@ class RenderEngine(object): ...@@ -155,7 +155,7 @@ class RenderEngine(object):
# don't use self.literal). # don't use self.literal).
template = unicode(template) template = unicode(template)
_template = Template(template=template) _template = Template()
_template.to_unicode = self.literal _template.to_unicode = self.literal
_template.escape = self.escape _template.escape = self.escape
...@@ -168,9 +168,6 @@ class Template(object): ...@@ -168,9 +168,6 @@ class Template(object):
tag_re = None tag_re = None
otag, ctag = '{{', '}}' otag, ctag = '{{', '}}'
def __init__(self, template=None):
self.template = template
def _compile_regexps(self): def _compile_regexps(self):
# The possible tag type characters following the opening tag, # The possible tag type characters following the opening tag,
...@@ -277,7 +274,7 @@ class Template(object): ...@@ -277,7 +274,7 @@ class Template(object):
elif callable(data): elif callable(data):
# TODO: should we check the arity? # TODO: should we check the arity?
template = data(template) template = data(template)
parse_tree = self.parse_string_to_tree(template, delims) parse_tree = self.parse_string_to_tree(template_string=template, delims=delims)
data = [ data ] data = [ data ]
elif type(data) not in [list, tuple]: elif type(data) not in [list, tuple]:
data = [ data ] data = [ data ]
...@@ -291,9 +288,9 @@ class Template(object): ...@@ -291,9 +288,9 @@ class Template(object):
return ''.join(parts) return ''.join(parts)
return func return func
def parse_string_to_tree(self, template, delims=('{{', '}}')): def parse_string_to_tree(self, template_string, delims=('{{', '}}')):
template = Template(template) template = Template()
template.otag = delims[0] template.otag = delims[0]
template.ctag = delims[1] template.ctag = delims[1]
...@@ -304,15 +301,14 @@ class Template(object): ...@@ -304,15 +301,14 @@ class Template(object):
template._compile_regexps() template._compile_regexps()
return template.parse_to_tree() return template.parse_to_tree(template=template_string)
def parse_to_tree(self, index=0): def parse_to_tree(self, template, index=0):
""" """
Parse a template into a syntax tree. Parse a template into a syntax tree.
""" """
parse_tree = [] parse_tree = []
template = self.template
start_index = index start_index = index
while True: while True:
...@@ -325,15 +321,14 @@ class Template(object): ...@@ -325,15 +321,14 @@ class Template(object):
match_index = match.end('content') match_index = match.end('content')
end_index = match.end() end_index = match.end()
index = self._handle_match(parse_tree, captures, start_index, match_index, end_index) index = self._handle_match(template, parse_tree, captures, start_index, match_index, end_index)
# Save the rest of the template. # Save the rest of the template.
parse_tree.append(template[index:]) parse_tree.append(template[index:])
return parse_tree return parse_tree
def _handle_match(self, parse_tree, captures, start_index, match_index, end_index): def _handle_match(self, template, parse_tree, captures, start_index, match_index, end_index):
template = self.template
# Normalize the captures dictionary. # Normalize the captures dictionary.
if captures['change'] is not None: if captures['change'] is not None:
...@@ -374,7 +369,7 @@ class Template(object): ...@@ -374,7 +369,7 @@ class Template(object):
elif captures['tag'] in ['#', '^']: elif captures['tag'] in ['#', '^']:
try: try:
self.parse_to_tree(index=end_index) self.parse_to_tree(template=template, index=end_index)
except EndOfSection as e: except EndOfSection as e:
bufr = e.parse_tree bufr = e.parse_tree
tmpl = e.template tmpl = e.template
...@@ -414,6 +409,6 @@ class Template(object): ...@@ -414,6 +409,6 @@ class Template(object):
if type(template) is not unicode: if type(template) is not unicode:
raise Exception("Argument 'template' not unicode: %s: %s" % (type(template), repr(template))) raise Exception("Argument 'template' not unicode: %s: %s" % (type(template), repr(template)))
parse_tree = self.parse_string_to_tree(template=template, delims=delims) parse_tree = self.parse_string_to_tree(template_string=template, delims=delims)
return render_parse_tree(parse_tree, context, 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