diff --git a/lib/hamlit/concerns/attribute_builder.rb b/lib/hamlit/concerns/attribute_builder.rb index 47b287cb..3f1416b7 100644 --- a/lib/hamlit/concerns/attribute_builder.rb +++ b/lib/hamlit/concerns/attribute_builder.rb @@ -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 diff --git a/spec/hamlit/engine/old_attributes_spec.rb b/spec/hamlit/engine/old_attributes_spec.rb index d2196d27..bfc2ad7d 100644 --- a/spec/hamlit/engine/old_attributes_spec.rb +++ b/spec/hamlit/engine/old_attributes_spec.rb @@ -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 - bar - HTML - end - - it 'renders nested hash whose value is variable' do - assert_render(<<-'HAML', <<-HTML) - - hash = { disable: true } - %span{ data: hash } bar - HAML - bar - 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 + bar + HTML + end + + it 'renders nested hash whose value is variable' do + assert_render(<<-'HAML', <<-HTML) + - hash = { disable: true } + %span{ data: hash } bar + HAML + bar + HTML + end + + it 'changes an underscore in a nested key to a hyphen' do + assert_render(<<-'HAML', <<-HTML) + %div{ data: { raw_src: 'foo' } } + HAML +
+ HTML + end + + it 'changes an underscore in a nested dynamic attribute' do + assert_render(<<-'HAML', <<-HTML) + - hash = { raw_src: 'foo' } + %div{ data: hash } + HAML +
+ HTML + end + end + describe 'element class with attributes class' do it 'does not generate double classes' do assert_render(<<-HAML, <<-HTML)