1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Hyphenate data attributes

Fixes #5.
This commit is contained in:
Takashi Kokubun 2015-03-31 20:40:55 +09:00
parent f2e350c135
commit 61df7a7fb8
2 changed files with 37 additions and 17 deletions

View file

@ -8,6 +8,7 @@ module Hamlit
case value
when Hash
flatten_attributes(value).each do |k, v|
k = k.to_s.gsub(/_/, '-')
flattened["#{key}-#{k}"] = v if v
end
else

View file

@ -40,23 +40,6 @@ describe Hamlit::Engine do
HTML
end
it 'renders true attributes' do
assert_render(<<-'HAML', <<-HTML)
%span{ data: { disable: true } } bar
HAML
<span data-disable>bar</span>
HTML
end
it 'renders nested hash whose value is variable' do
assert_render(<<-'HAML', <<-HTML)
- hash = { disable: true }
%span{ data: hash } bar
HAML
<span data-disable>bar</span>
HTML
end
it 'renders false or nil attributes' do
assert_render(<<-'HAML', <<-HTML)
- hash = { checked: false }
@ -104,6 +87,42 @@ describe Hamlit::Engine do
HTML
end
describe 'nested attributes' do
it 'renders true attributes' do
assert_render(<<-'HAML', <<-HTML)
%span{ data: { disable: true } } bar
HAML
<span data-disable>bar</span>
HTML
end
it 'renders nested hash whose value is variable' do
assert_render(<<-'HAML', <<-HTML)
- hash = { disable: true }
%span{ data: hash } bar
HAML
<span data-disable>bar</span>
HTML
end
it 'changes an underscore in a nested key to a hyphen' do
assert_render(<<-'HAML', <<-HTML)
%div{ data: { raw_src: 'foo' } }
HAML
<div data-raw-src='foo'></div>
HTML
end
it 'changes an underscore in a nested dynamic attribute' do
assert_render(<<-'HAML', <<-HTML)
- hash = { raw_src: 'foo' }
%div{ data: hash }
HAML
<div data-raw-src='foo'></div>
HTML
end
end
describe 'element class with attributes class' do
it 'does not generate double classes' do
assert_render(<<-HAML, <<-HTML)