Commit a9bae002 by Carl Whittaker

Adding logic to preserve whitespace.

parent 4b589295
...@@ -44,7 +44,7 @@ class Template(object): ...@@ -44,7 +44,7 @@ class Template(object):
'ctag': re.escape(self.ctag) 'ctag': re.escape(self.ctag)
} }
section = r"%(otag)s[\#|^]([^\}]*)%(ctag)s\s*(.+?\s*)%(otag)s/\1%(ctag)s" section = r"([\n][\s\t]*?)?%(otag)s[\#|^]([^\}]*)%(ctag)s\s*(.+?\s*)%(otag)s/\2%(ctag)s([\s\t]*?[\n])?"
self.section_re = re.compile(section % tags, re.M|re.S) self.section_re = re.compile(section % tags, re.M|re.S)
tag = r"%(otag)s(#|=|&|!|>|\{)?(.+?)\1?%(ctag)s+" tag = r"%(otag)s(#|=|&|!|>|\{)?(.+?)\1?%(ctag)s+"
...@@ -56,7 +56,7 @@ class Template(object): ...@@ -56,7 +56,7 @@ class Template(object):
if match is None: if match is None:
break break
section, section_name, inner = match.group(0, 1, 2) section, section_name, inner = match.group(0, 2, 3)
section_name = section_name.strip() section_name = section_name.strip()
it = self.view.get(section_name, None) it = self.view.get(section_name, None)
replacer = '' replacer = ''
......
...@@ -46,4 +46,15 @@ class TestSimple(unittest.TestCase): ...@@ -46,4 +46,15 @@ class TestSimple(unittest.TestCase):
------- -------
Again, Welcome! Again, Welcome!
""") """)
\ No newline at end of file
def test_whitespace_is_preserved(self):
template = '''
{{#is_true}}
tidy me up!
{{/is_true}}
'''
context = {
'is_true': True
}
self.assertEquals(pystache.Template(template, context).render(), ' tidy me up')
\ No newline at end of file
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