Commit 43280bd1 by Chris Jerdonek

Merge pull request #45 (4) "Preventing section content being processed as a template. Fixes #46"

From: https://github.com/jakearchibald/pystache/commit/a936076fd5c06f49c8a7307060861807d8245ffe
Into: issue_46

The failed unit test now passes.

Conflicts:
	pystache/template.py
parents 12d0039d a936076f
...@@ -130,7 +130,9 @@ class Template(object): ...@@ -130,7 +130,9 @@ class Template(object):
tag = r"%(otag)s(#|=|&|!|>|\{)?(.+?)\1?%(ctag)s+" tag = r"%(otag)s(#|=|&|!|>|\{)?(.+?)\1?%(ctag)s+"
self.tag_re = re.compile(tag % tags) self.tag_re = re.compile(tag % tags)
def _render_sections(self, template): def _render(self, template):
output = ''
while True: while True:
match = self.section_re.search(template) match = self.section_re.search(template)
if match is None: if match is None:
...@@ -164,9 +166,15 @@ class Template(object): ...@@ -164,9 +166,15 @@ class Template(object):
elif (not it and section[2] == '^') or (it and section[2] != '^'): elif (not it and section[2] == '^') or (it and section[2] != '^'):
replacer = self._render_dictionary(inner, it) replacer = self._render_dictionary(inner, it)
template = literal(template.replace(section, replacer)) # Render template prior to section too
output = output + self._render_tags(template[0:match.start()]) + replacer
template = template[match.end():]
return template # Render remainder
output = output + self._render_tags(template)
return output
def _render_tags(self, template): def _render_tags(self, template):
output = [] output = []
...@@ -275,8 +283,7 @@ class Template(object): ...@@ -275,8 +283,7 @@ class Template(object):
""" """
self._initialize_context(context, **kwargs) self._initialize_context(context, **kwargs)
template = self._render_sections(self.template) result = self._render(self.template)
result = self._render_tags(template)
if self.output_encoding is not None: if self.output_encoding is not None:
result = result.encode(self.output_encoding) result = result.encode(self.output_encoding)
......
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