summaryrefslogtreecommitdiff
path: root/pystache
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-05-04 18:42:46 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-05-04 18:42:46 -0700
commit159849714fe362556e64d1923ff00789f0df47d9 (patch)
treed6ca66965e653cbef18ff741e54f6673c1343ad7 /pystache
parentebdc702f73b1df630a720a5b97d3d882b5a6c8e7 (diff)
downloadpystache-159849714fe362556e64d1923ff00789f0df47d9.tar.gz
Moved more code (partial-related code) from parser to renderengine.
Diffstat (limited to 'pystache')
-rw-r--r--pystache/parser.py8
-rw-r--r--pystache/renderengine.py12
2 files changed, 13 insertions, 7 deletions
diff --git a/pystache/parser.py b/pystache/parser.py
index b2af35c..83b1c7e 100644
--- a/pystache/parser.py
+++ b/pystache/parser.py
@@ -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:
diff --git a/pystache/renderengine.py b/pystache/renderengine.py
index de5527a..836e610 100644
--- a/pystache/renderengine.py
+++ b/pystache/renderengine.py
@@ -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