Commits

Andriy Kornatskyy committed aba0be9

Preserve spaces in widgets preprocessing.

Comments (0)

Files changed (8)

src/wheezy/html/ext/jinja2.py

     def __init__(self,
                  variable_start_string=None,
                  variable_end_string=None):
-        pattern = r'\s*\{\{((?P<expr>.+?)\.'\
+        pattern = r'\{\{((?P<expr>.+?)\.'\
             r'(?P<widget>%(widgets)s){1}\((?P<params>.*?)\)\s*'\
-            r'(?P<expr_filter>(\|\s*[\w,\s]+?|\s*)))\}\}\s*'
+            r'(?P<expr_filter>(\|\s*[\w,\s]+?|\s*)))\}\}'
         if variable_start_string:
             pattern = pattern.replace('\{\{',
                                       re.escape(variable_start_string))
     MULTIPLE_HIDDEN = """\
 {%% for item in %(value)s: %%}\
 <input type="hidden" name="%(name)s" value="{{ item%(expr_filter)s }}" />\
-{%% endfor %%}
-"""
+{%% endfor %%}"""
 
     INPUT = """\
 <input id="%(id)s" name="%(name)s" type="%(type)s"%(attrs)s%(class)s\

src/wheezy/html/ext/mako.py

 
     def __init__(self, skip_imports=False):
         super(MakoPreprocessor, self).__init__(
-            r'(?<!##)\s*\$\{((?P<expr>.+?)\.'
-            r'(?P<widget>%(widgets)s){1}\((?P<params>.*?)\)\s*'
-            r'(?P<expr_filter>(\|\s*[\w,\s]+?|\s*)))\}\s*')
+            r'\$\{((?P<expr>.+?)\.'
+            r'(?P<widget>%(widgets)s){1}\((?P<params>.*?)\)\s*?'
+            r'(?P<expr_filter>(\|\s*[\w,\s]+?|)))\}')
 
     PREPEND = """\
 <%!

src/wheezy/html/ext/template.py

     def __init__(self):
         super(WheezyPreprocessor, self).__init__(
             r'@((?P<expr>.+?)\.'
-            r'(?P<widget>%(widgets)s){1}\((?P<params>.*?)\)\s*'
-            r'(?P<expr_filter>((?<!!)!\w+(!\w+)*|\s*)))(\s|$)')
+            r'(?P<widget>%(widgets)s){1}\((?P<params>.*?)\)\s*?'
+            r'(?P<expr_filter>((?<!!)!\w+(!\w+)*|)))(?=\s|$)')
 
     EXPRESSION = '@%(expr)s%(expr_filter)s'
 

src/wheezy/html/ext/tenjin.py

 
     def __init__(self):
         super(TenjinPreprocessor, self).__init__(
-            r'\s*(?P<expr_filter>[#\$])\{((?P<expr>.+?)\.'
+            r'(?P<expr_filter>[#\$])\{((?P<expr>.+?)\.'
             r'(?P<widget>%(widgets)s){1}'
-            r'\((?P<params>.*?)\)\s*)\}\s*')
+            r'\((?P<params>.*?)\)\s*)\}')
 
     EXPRESSION = '%(expr_filter)s{%(expr)s}'
 

src/wheezy/html/ext/tests/test_jinja2.py

     """ Test the ``Jinja2Preprocessor``.
     """
 
+    WHITE_SPACE_PATTERNS = ['%(w)s', ' %(w)s', '%(w)s ', ' %(w)s ']
+
     def assert_render_equal(self, template, expected, **kwargs):
         assert_jinja2_equal({
             'variable_start_string': '{{',
     """ Test the ``Jinja2Preprocessor``.
     """
 
+    WHITE_SPACE_PATTERNS = ['%(w)s', ' %(w)s', '%(w)s ', ' %(w)s ']
+
     def assert_render_equal(self, template, expected, **kwargs):
         assert_jinja2_equal({
             'variable_start_string': '${',

src/wheezy/html/ext/tests/test_lexer.py

 import unittest
 
 
+def generate_white_space_patterns():
+    for t in ['x', ' x', 'x ', ' x ', '[ x', 'x ]', '[ x ]', 'xx', 'x x']:
+        for s in [' ', '\t', '\n', ' \t', ' \n', '\n ']:
+            for n in [1, 3]:
+                yield t.replace(' ', s * n).replace('x', '%(w)s')
+
+
 class PreprocessorInitTestCase(unittest.TestCase):
     """ Test the ``Preprocessor.__init__``.
     """
     """
     from operator import itemgetter
 
+    WHITE_SPACE_PATTERNS = ['%(w)s']
+
     class Dummy(object):
         pass
 
     def render(self, widget, html):
         """ hidden widget.
         """
-        self.assert_render_equal(
-            widget, html, model=self.m, errors=self.e, scm=self.scm,
-            message=(hasattr(self.m, 'message') and self.m.message or ''))
+        for wsp in self.WHITE_SPACE_PATTERNS:
+            self.assert_render_equal(
+                wsp % {'w': widget},
+                wsp % {'w': html},
+                model=self.m, errors=self.e, scm=self.scm,
+                message=(hasattr(self.m, 'message') and self.m.message or ''))
 
     def test_hidden(self):
         """ hidden widget.

src/wheezy/html/ext/tests/test_mako.py

     """ Test the ``MakoPreprocessor``.
     """
 
+    WHITE_SPACE_PATTERNS = ['%(w)s', ' %(w)s', '%(w)s ', ' %(w)s ']
+
     def assert_render_equal(self, template, expected, **kwargs):
         assert_mako_equal(template, expected, **kwargs)
 

src/wheezy/html/ext/tests/test_tenjin.py

     """ Test the ``TenjinPreprocessor``.
     """
 
+    WHITE_SPACE_PATTERNS = ['%(w)s', '[ %(w)s', '%(w)s ', '[ %(w)s ']
+
     def assert_render_equal(self, template, expected, **kwargs):
         assert_tenjin_equal(template, expected, **kwargs)