Commit 41c92afc by Pieter van de Bruggen

Refactoring the match handling logic.

parent 50bdc535
......@@ -43,6 +43,14 @@ class Template(object):
if match is None:
break
pos = self._handle_match(template, match, buffer)
# Save the rest of the template.
buffer.append(template[pos:])
return buffer
def _handle_match(self, template, match, buffer):
# Normalize the captures dictionary.
captures = match.groupdict()
if captures['change'] is not None:
......@@ -67,21 +75,18 @@ class Template(object):
captures['whitespace'] = ''
# TODO: Process the remaining tag types.
print captures['name']
fetch = lambda view: unicode(view.get(captures['name']))
if captures['tag'] == '!':
pass
elif captures['tag'] in ['{', '&']:
def unescapedTag(view):
return view.get(captures['name'])
buffer.append(unescapedTag)
buffer.append(fetch)
elif captures['tag'] == '':
def escapedTag(view):
return cgi.escape(view.get(captures['name']))
buffer.append(escapedTag)
buffer.append(lambda view: cgi.escape(fetch(view), True))
else:
print 'Error!'
# Save the rest of the template.
buffer.append(template[pos:])
return buffer
return pos
def render(self, encoding=None):
parsed = self._parse(self.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