diff --git a/hamlpy/elements.py b/hamlpy/elements.py index 8fbe817..a3c036f 100644 --- a/hamlpy/elements.py +++ b/hamlpy/elements.py @@ -112,25 +112,20 @@ def _escape_attribute_quotes(self, v): return ''.join(escaped) def _parse_attribute_dictionary(self, attribute_dict_string): - class SingleVariableMarker(object): - pass - attributes_dict = {} + if (attribute_dict_string): attribute_dict_string = attribute_dict_string.replace('\n', ' ') try: # converting all allowed attributes to python dictionary style # When encountering single variables (like "required" or - # "visible") use an empty class instance as a trick to have - # both a unique and a non coliding marker because all of this - # will be converted as a python dictionary - attribute_dict_string = re.sub(self.SINGLE_VARIABLE_REGEX, '\gSingleVariableMarker(): "\g"\g', attribute_dict_string) - print attribute_dict_string + # "visible") set its value to None + attribute_dict_string = re.sub(self.SINGLE_VARIABLE_REGEX, '\g"\g": None\g', attribute_dict_string) # do it both because the regex is too greedy and doesn't do it # with single variable in between - attribute_dict_string = re.sub(self.SINGLE_VARIABLE_REGEX, '\gSingleVariableMarker(): "\g"\g', attribute_dict_string) + attribute_dict_string = re.sub(self.SINGLE_VARIABLE_REGEX, '\g"\g": None\g', attribute_dict_string) # Replace Ruby-style HAML with Python style attribute_dict_string = re.sub(self.RUBY_HAML_REGEX, '"\g":', attribute_dict_string) @@ -139,15 +134,13 @@ class SingleVariableMarker(object): attribute_dict_string = re.sub(self.ATTRIBUTE_REGEX, '\g
"\g":\g', attribute_dict_string)
 
                 # Parse string as dictionary
-                attributes_dict = eval(attribute_dict_string, {"SingleVariableMarker": SingleVariableMarker})
+                attributes_dict = eval(attribute_dict_string)
                 for k, v in attributes_dict.items():
                     if k != 'id' and k != 'class':
                         if isinstance(v, NoneType):
                             self.attributes += "%s " % (k,)
                         elif isinstance(v, int) or isinstance(v, float):
                             self.attributes += "%s=%s " % (k, self.attr_wrap(v))
-                        elif isinstance(k, SingleVariableMarker):
-                            self.attributes += "%s " % (v)
                         else:
                             # DEPRECATED: Replace variable in attributes (e.g. "= somevar") with Django version ("{{somevar}}")
                             v = re.sub(self.DJANGO_VARIABLE_REGEX, '{{\g}}', attributes_dict[k])
diff --git a/hamlpy/test/hamlpy_test.py b/hamlpy/test/hamlpy_test.py
index 1d0c402..6c87933 100755
--- a/hamlpy/test/hamlpy_test.py
+++ b/hamlpy/test/hamlpy_test.py
@@ -90,11 +90,11 @@ def test_dictionaries_define_no_value_attribute_several(self):
         self.assertTrue(result.rstrip().endswith("/>"))
 
     def test_dictionaries_define_no_value_attribute_several_a_lot(self):
-        haml = "%%input{a: 'b', %s}" % ", ".join(string.ascii_letters)
+        haml = "%%input{baba: 'b', %s}" % ", ".join(string.ascii_letters)
         hamlParser = hamlpy.Compiler()
         result = hamlParser.process(haml)
         self.assertTrue(""))