mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Haml] Make sure HTML5 custom data attributes don't lead to duplicate attrs.
This commit is contained in:
parent
62f05fcdad
commit
e7be384f4d
2 changed files with 15 additions and 4 deletions
|
@ -542,6 +542,12 @@ END
|
|||
quote_escape = attr_wrapper == '"' ? """ : "'"
|
||||
other_quote_char = attr_wrapper == '"' ? "'" : '"'
|
||||
|
||||
if attributes['data'].is_a?(Hash)
|
||||
attributes = attributes.dup
|
||||
attributes =
|
||||
Haml::Util.map_keys(attributes.delete('data')) {|name| "data-#{name}"}.merge(attributes)
|
||||
end
|
||||
|
||||
result = attributes.collect do |attr, value|
|
||||
next if value.nil?
|
||||
|
||||
|
@ -553,9 +559,6 @@ END
|
|||
next " #{attr}=#{attr_wrapper}#{attr}#{attr_wrapper}"
|
||||
elsif value == false
|
||||
next
|
||||
elsif attr == 'data' && value.is_a?(Hash)
|
||||
next build_attributes(is_html, attr_wrapper,
|
||||
Haml::Util.map_keys(value) {|name| "data-#{name}"})
|
||||
end
|
||||
|
||||
value = Haml::Helpers.preserve(Haml::Helpers.escape_once(value.to_s))
|
||||
|
|
|
@ -1203,7 +1203,15 @@ SASS
|
|||
render("%div{:data => {:one_plus_one => 1+1}}"))
|
||||
|
||||
assert_equal("<div data-foo='Here's a \"quoteful\" string.'></div>\n",
|
||||
render(%{%div{:data => {:foo => %{Here's a "quoteful" string.}}}}))
|
||||
render(%{%div{:data => {:foo => %{Here's a "quoteful" string.}}}})) #'
|
||||
end
|
||||
|
||||
def test_html5_data_attributes_with_multiple_defs
|
||||
# Should always use the more-explicit attribute
|
||||
assert_equal("<div data-foo='second'></div>\n",
|
||||
render("%div{:data => {:foo => 'first'}, 'data-foo' => 'second'}"))
|
||||
assert_equal("<div data-foo='first'></div>\n",
|
||||
render("%div{'data-foo' => 'first', :data => {:foo => 'second'}}"))
|
||||
end
|
||||
|
||||
# New attributes
|
||||
|
|
Loading…
Add table
Reference in a new issue