Commit f26c5e7a by Chris Jerdonek

Moved some of the partial logic from RenderEngine to Parser.

parent 792ce17d
...@@ -14,6 +14,7 @@ from template import ParsedTemplate ...@@ -14,6 +14,7 @@ from template import ParsedTemplate
DEFAULT_DELIMITERS = ('{{', '}}') DEFAULT_DELIMITERS = ('{{', '}}')
END_OF_LINE_CHARACTERS = ['\r', '\n'] END_OF_LINE_CHARACTERS = ['\r', '\n']
NON_BLANK_RE = re.compile(r'^(.)', re.M)
def _compile_template_re(delimiters): def _compile_template_re(delimiters):
...@@ -148,6 +149,7 @@ class Parser(object): ...@@ -148,6 +149,7 @@ class Parser(object):
def _handle_tag_type(self, template, parse_tree, tag_type, tag_key, leading_whitespace, end_index): def _handle_tag_type(self, template, parse_tree, tag_type, tag_key, leading_whitespace, end_index):
# TODO: switch to using a dictionary instead of a bunch of ifs and elifs.
if tag_type == '!': if tag_type == '!':
return end_index return end_index
...@@ -178,7 +180,12 @@ class Parser(object): ...@@ -178,7 +180,12 @@ class Parser(object):
elif tag_type == '>': elif tag_type == '>':
func = engine._make_get_partial(tag_key, leading_whitespace) template = engine.load_partial(tag_key)
# Indent before rendering.
template = re.sub(NON_BLANK_RE, leading_whitespace + r'\1', template)
func = engine._make_get_partial(template)
else: else:
......
...@@ -10,9 +10,6 @@ import re ...@@ -10,9 +10,6 @@ import re
from parser import Parser from parser import Parser
NON_BLANK_RE = re.compile(r'^(.)', re.M)
class RenderEngine(object): class RenderEngine(object):
""" """
...@@ -129,15 +126,12 @@ class RenderEngine(object): ...@@ -129,15 +126,12 @@ class RenderEngine(object):
return get_escaped return get_escaped
def _make_get_partial(self, name, indentation=''): def _make_get_partial(self, template):
def get_partial(context): def get_partial(context):
""" """
Returns: a string of type unicode. Returns: a string of type unicode.
""" """
template = self.load_partial(name)
# Indent before rendering.
template = re.sub(NON_BLANK_RE, indentation + r'\1', template)
return self._render(template, context) return self._render(template, context)
return get_partial return get_partial
......
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