Commit 15984971 by Chris Jerdonek

Moved more code (partial-related code) from parser to renderengine.

parent ebdc702f
......@@ -14,7 +14,6 @@ from pystache.parsed import ParsedTemplate
DEFAULT_DELIMITERS = (u'{{', u'}}')
END_OF_LINE_CHARACTERS = [u'\r', u'\n']
NON_BLANK_RE = re.compile(ur'^(.)', re.M)
def _compile_template_re(delimiters=None):
......@@ -205,6 +204,7 @@ class Parser(object):
elif tag_type == '#':
# TODO: move this code into RenderEngine.
section_start_index = end_index
parsed_section, section_end_index, end_index = self._parse_section(template, end_index, tag_key)
func = engine._make_get_section(tag_key, parsed_section, self._delimiters,
......@@ -212,15 +212,13 @@ class Parser(object):
elif tag_type == '^':
# TODO: move this code into RenderEngine.
parsed_section, section_end_index, end_index = self._parse_section(template, end_index, tag_key)
func = engine._make_get_inverse(tag_key, parsed_section)
elif tag_type == '>':
template = engine.resolve_partial(tag_key)
# Indent before rendering.
template = re.sub(NON_BLANK_RE, leading_whitespace + ur'\1', template)
func = engine._make_get_partial(template)
func = engine._make_get_partial(tag_key, leading_whitespace)
else:
......
......@@ -11,6 +11,9 @@ from pystache.common import is_string
from pystache.parser import Parser
NON_BLANK_RE = re.compile(ur'^(.)', re.M)
def context_get(stack, name):
"""
Find and return a name from a ContextStack instance.
......@@ -127,13 +130,18 @@ class RenderEngine(object):
return get_escaped
def _make_get_partial(self, template):
def _make_get_partial(self, tag_key, leading_whitespace):
template = self.resolve_partial(tag_key)
# Indent before rendering.
template = re.sub(NON_BLANK_RE, leading_whitespace + ur'\1', template)
def get_partial(context):
"""
Returns: a string of type unicode.
"""
# TODO: the parsing should be done before calling this function.
# TODO: can we do the parsing before calling this function?
return self._render(template, context)
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