Don't treat the 'data' attribute specially.

Fixes #678
This commit is contained in:
Norman Clarke 2013-05-21 10:22:48 -03:00
parent c434e8cfd0
commit bb8ca6b202
3 changed files with 23 additions and 13 deletions

View File

@ -9,6 +9,7 @@
for detailed info. (Matt Wildig)
* Make escape_once respect hexadecimal references. (Matt Wildig)
* General performance and memory usage improvements. (Akira Matsuda)
* Don't treat the 'data' attribute specially when merging attribute hashes. (Matt Wildig and Norman Clarke)
## 4.0.2

View File

@ -246,16 +246,21 @@ RUBY
from['class'] ||= to['class']
end
from_data = from.delete('data')
# forces to_data & from_data into a hash
from_data = { nil => from_data } if from_data && !from_data.is_a?(Hash)
to['data'] = { nil => to['data'] } if to['data'] && !to['data'].is_a?(Hash)
from.keys.each do |key|
next unless from[key].kind_of?(Hash) || to[key].kind_of?(Hash)
if from_data && !to['data']
to['data'] = from_data
elsif from_data && to['data']
to['data'].merge! from_data
from_data = from.delete(key)
# forces to_data & from_data into a hash
from_data = { nil => from_data } if from_data && !from_data.is_a?(Hash)
to[key] = { nil => to[key] } if to[key] && !to[key].is_a?(Hash)
if from_data && !to[key]
to[key] = from_data
elsif from_data && to[key]
to[key].merge! from_data
end
end
to.merge!(from)
end

View File

@ -214,11 +214,6 @@ HAML
render(".no_attributes{:nil => nil}").chomp)
end
def test_attribute_method_with_both_attrib_styles_and_non_static_hashes
assert_equal("<div baz='qux' foo='bar' zig='zag'></div>",
render("%div{{:foo => 'bar'}, :baz => 'qux'}(zig = val)", :locals => {:val => 'zag'}).chomp)
end
def test_strings_should_get_stripped_inside_tags
assert_equal("<div class='stripped'>This should have no spaces in front of it</div>",
render(".stripped This should have no spaces in front of it").chomp)
@ -1458,6 +1453,15 @@ HAML
render("%div{:foo => {:baz => 'bang'}}"))
end
def test_arbitrary_attribute_hash_merging
assert_equal(%Q{<a aria-baz='qux' aria-foo='bar'></a>\n}, render(<<-HAML))
- h1 = {:aria => {:foo => :bar}}
- h2 = {:baz => :qux}
%a{h1, :aria => h2}
HAML
end
def test_html5_data_attributes_with_nested_hash
assert_equal("<div data-a-b='c'></div>\n", render(<<-HAML))
- hash = {:a => {:b => 'c'}}