Skip to content

Commit

Permalink
Mark multiple key separator characters within parenthesis. (Fixes #33)
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Aug 2, 2012
1 parent 4afdf95 commit 4efc7bc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Master

* [Issue #33](https://github.com/netzpirat/haml-coffee/issues/33): Fix tag attributes that contains multiple attribute keys.

# Version 1.2.0, Juli 18, 2012

* [haml_coffee_assets issue #56](https://github.com/netzpirat/haml_coffee_assets/issues/56): Weird behavior when using space before the : of an attribute.
Expand Down
6 changes: 3 additions & 3 deletions lib/nodes/haml.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion spec/suites/templates/text/attributes.haml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@
%span.value{ 'foo' : 'foo', 'bar' : 'bar', baz: 'baz' } Foo
%span.value{ 'foo': 'foo', 'bar' : 'bar', baz: 'baz' } Foo
%span.value{ data: { 'foo' : 'foo', 'bar': 'bar' } } Foo
%span.value{ data: { 'foo' : 'foo', 'bar': 'bar' } } Foo
%tbody.build-row{data-bind: "foreach: { data: xs}"}
3 changes: 2 additions & 1 deletion spec/suites/templates/text/attributes_html5.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<input class='g-field' id='input-transfer-template-repeat-number' type='text' name='transfer_template[repeat_number]' placeholder='например, 14:50'>
<span class='value' foo='foo' bar='bar' baz='baz'>Foo</span>
<span class='value' foo='foo' bar='bar' baz='baz'>Foo</span>
<span class='value' data-foo='foo' data-bar='bar'>Foo</span>
<span class='value' data-foo='foo' data-bar='bar'>Foo</span>
<tbody class='build-row' data-bind='foreach: { data: xs}'></tbody>
3 changes: 2 additions & 1 deletion spec/suites/templates/text/attributes_xhtml.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<input class='g-field' id='input-transfer-template-repeat-number' type='text' name='transfer_template[repeat_number]' placeholder='например, 14:50' />
<span class='value' foo='foo' bar='bar' baz='baz'>Foo</span>
<span class='value' foo='foo' bar='bar' baz='baz'>Foo</span>
<span class='value' data-foo='foo' data-bar='bar'>Foo</span>
<span class='value' data-foo='foo' data-bar='bar'>Foo</span>
<tbody class='build-row' data-bind='foreach: { data: xs}'></tbody>
6 changes: 3 additions & 3 deletions src/nodes/haml.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ module.exports = class Haml extends Node

# Mark key separator characters within quoted values, so they aren't recognized as keys.
exp = exp.replace /(=|:|=>)\s*('([^\\']|\\\\|\\')*'|"([^\\"]|\\\\|\\")*")/g, (match, type, value) ->
type + value?.replace /(:|=|=>)/, '\u0090$1'
type + value?.replace /(:|=|=>)/g, '\u0090$1'

# Mark key separator characters within parenthesis, so they aren't recognized as keys.
level = 0
Expand Down Expand Up @@ -296,7 +296,7 @@ module.exports = class Haml extends Node
level -= 1

for marker in markers.reverse()
exp = exp.substring(0, marker.start) + exp.substring(marker.start, marker.end).replace(/(:|=|=>)/, '\u0090$1') + exp.substring(marker.end)
exp = exp.substring(0, marker.start) + exp.substring(marker.start, marker.end).replace(/(:|=|=>)/g, '\u0090$1') + exp.substring(marker.end)

# Detect the used key type
switch type
Expand Down Expand Up @@ -347,7 +347,7 @@ module.exports = class Haml extends Node
key = quoted[2] if quoted = key.match /^("|')(.*)\1$/

# Trim value, remove succeeding comma and remove markers
value = keyValue[1]?.replace(/^\s+|[\s,]+$/g, '').replace(/\u0090/, '')
value = keyValue[1]?.replace(/^\s+|[\s,]+$/g, '').replace(/\u0090/g, '')

if key is 'data'
inDataAttribute = true
Expand Down

0 comments on commit 4efc7bc

Please sign in to comment.