describe Hamlit::Engine do describe 'old attributes' do it 'renders attributes' do assert_render(<<-HAML, <<-HTML) %span{class: 'foo'} bar HAML bar HTML end it 'renders attributes' do assert_render(<<-HAML, <<-HTML) %span{ data: 2 } bar HAML bar HTML end it 'renders attributes' do assert_render(<<-'HAML', <<-HTML) %span{ :class => 'foo' } bar HAML bar HTML end it 'renders attributes' do assert_render(<<-'HAML', <<-HTML) %span{ :class => 'foo', id: 'bar' } bar HAML bar HTML end it 'renders attributes' do assert_render(<<-'HAML', <<-HTML) %span{ :'data-disable' => true } bar HAML bar HTML end it 'renders false or nil attributes' do assert_render(<<-'HAML', <<-HTML) - hash = { checked: false } %input{ hash } %input{ checked: false } %input{ checked: nil } HAML HTML end it 'accepts even illegal input for haml' do assert_render(<<-'HAML', <<-HTML) %span{ class: '}}}', id: '{}}' } }{ HAML }{ HTML end it 'accepts method call including comma' do assert_render(<<-'HAML', <<-HTML) %body{ class: "#{"ab".gsub(/a/, 'b')}", data: { confirm: 'really?', disable: true }, id: 'c'.gsub(/c/, 'a') } HAML HTML end it 'renders runtime hash attribute' do assert_render(<<-'HAML', <<-HTML) - hash = { foo: 'bar' } %span{ hash } HAML HTML end it 'renders runtime hash attribute escaping only value' do assert_render(<<-'HAML', <<-HTML) - hash = { "''" => '' } %span{ hash } HAML '='<bar>'> HTML end it 'renders multi-byte chars as static attribute value' do assert_render(<<-'HAML', <<-HTML) %img{ alt: 'こんにちは' } HAML こんにちは 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) .item{ class: 'first' } HAML
HTML end it 'does not generate double classes for a variable' do assert_render(<<-HAML, <<-HTML) - val = 'val' .element{ class: val } HAML
HTML end end end end