-
Notifications
You must be signed in to change notification settings - Fork 14
Conversation
…g on how lines are split
|
||
if not root.parent_of(HamlNode(line, self)).inside_filter_node(): | ||
if line.count('{') - line.count('}') == 1: | ||
start_multiline = line_number # for exception handling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking line numbers would be useful but this line doesn't actually do anything
node_lines = line | ||
|
||
if not root.parent_of(HamlNode(line, self)).inside_filter_node(): | ||
if line.count('{') - line.count('}') == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This where things break if you have {} characters in attribute values
@@ -144,11 +130,17 @@ def read_attribute_dict(stream): | |||
""" | |||
data = OrderedDict() | |||
|
|||
start, terminator = stream.text[0], stream.text[-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this code assumed the stream only contained an attribute dictionary - now it contains the entire haml document
|
||
|
||
def stylus(content, indent, options): | ||
return indent + '<style type=%(attr_wrapper)stext/stylus%(attr_wrapper)s>\n' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some inconsistencies with now indentation is handled by different filters. I've tried to preserve some of those inconsistencies for now so that the template tests work as is
|
||
start.add_node(one) | ||
start.add_node(two) | ||
start.add_node(three) | ||
|
||
self.assertEqual(3, len(start.children)) | ||
|
||
def test_node_parent_function(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parent_of
was being used to figure out of a node belonged to filter node that no longer happens and this is no longer needed
@@ -24,3 +24,4 @@ | |||
3 | |||
4 | |||
5 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of a few cases where we don't match the original output exactly because of an additional new line. IMO this new line is correct (it's coming from the python print
) and shouldn't break anyone's stuff.
…or empty lines in attribute alues which are Haml
@@ -97,6 +93,7 @@ def test_parse(self): | |||
'class': | |||
- if forloop.first | |||
link-first | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This blank line tests #41
…t coverage back to 100%
Currently the node parser works on a line by line basis which leads to following issues:
{
and}
characters. You can break things by putting a brace into an attribute value. People don't often use{
characters not in pairs, but now that we also support(...)
style attribute dictionaries, chances of things breaking are a bit higher.:plain\n %abc
, causes the%abc
line to be parsed as an element even tho it's just a line of plain textThis PR reworks the parsing of nodes so that:
textwrap.dedent
for removing indentation.Performance-wise new code seems to be about ~40% faster.
Fixes #38, #39 and #41