diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-05-04 14:54:19 -0700 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-05-04 14:54:19 -0700 |
commit | ef3ef4bf927dce83341b05ef61a251c3d450920c (patch) | |
tree | 1718c750c2617a308c9838595ba58e3efebffe02 /pystache | |
parent | 1a9ca1f74acd12f72993cbb7e19ab07b36d7cc18 (diff) | |
download | pystache-ef3ef4bf927dce83341b05ef61a251c3d450920c.tar.gz |
Refactored some of the parsing logic: delayed template slicing.
Diffstat (limited to 'pystache')
-rw-r--r-- | pystache/parser.py | 12 | ||||
-rw-r--r-- | pystache/renderengine.py | 7 |
2 files changed, 10 insertions, 9 deletions
diff --git a/pystache/parser.py b/pystache/parser.py index 4851303..b2af35c 100644 --- a/pystache/parser.py +++ b/pystache/parser.py @@ -177,10 +177,10 @@ class Parser(object): including any trailing newlines). """ - parsed_section, content_end_index, end_index = \ + parsed_section, section_end_index, end_index = \ self.parse(template=template, start_index=start_index, section_key=section_key) - return parsed_section, template[start_index:content_end_index], end_index + return parsed_section, section_end_index, end_index def _handle_tag_type(self, template, parse_tree, tag_type, tag_key, leading_whitespace, end_index): @@ -205,12 +205,14 @@ class Parser(object): elif tag_type == '#': - parsed_section, section_contents, end_index = self._parse_section(template, end_index, tag_key) - func = engine._make_get_section(tag_key, parsed_section, section_contents, self._delimiters) + 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, + template, section_start_index, section_end_index) elif tag_type == '^': - parsed_section, section_contents, end_index = self._parse_section(template, end_index, tag_key) + 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 == '>': diff --git a/pystache/renderengine.py b/pystache/renderengine.py index 7a9df9d..8d95fb1 100644 --- a/pystache/renderengine.py +++ b/pystache/renderengine.py @@ -162,14 +162,13 @@ class RenderEngine(object): # TODO: the template_ and parsed_template_ arguments don't both seem # to be necessary. Can we remove one of them? For example, if # callable(data) is True, then the initial parsed_template isn't used. - def _make_get_section(self, name, parsed_template_, template_, delims): + def _make_get_section(self, name, parsed_template, delims, + template, section_start_index, section_end_index): def get_section(context): """ Returns: a string of type unicode. """ - template = template_ - parsed_template = parsed_template_ data = self.resolve_context(context, name) # From the spec: @@ -220,7 +219,7 @@ class RenderEngine(object): # https://github.com/defunkt/pystache/issues/113 # # TODO: should we check the arity? - new_template = element(template) + new_template = element(template[section_start_index:section_end_index]) new_parsed_template = self._parse(new_template, delimiters=delims) parts.append(new_parsed_template.render(context)) continue |