mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Trim falsy value in array attribute
This commit is contained in:
parent
e2b9a20c62
commit
49c0fe2d60
3 changed files with 49 additions and 31 deletions
|
@ -17,7 +17,7 @@ module Hamlit
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_id(*values)
|
def build_id(*values)
|
||||||
values.select { |v| v }.join('_')
|
values.flatten.select { |v| v }.join('_')
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_class(*values)
|
def build_class(*values)
|
||||||
|
|
|
@ -153,26 +153,33 @@ class EngineTest < Haml::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_attr_with_array
|
def test_class_attr_with_array
|
||||||
skip '[INCOMPATIBILITY] Hamlit deletes only boolean attributes'
|
|
||||||
assert_equal("<p class='a b'>foo</p>\n", render("%p{:class => %w[a b]} foo")) # basic
|
assert_equal("<p class='a b'>foo</p>\n", render("%p{:class => %w[a b]} foo")) # basic
|
||||||
assert_equal("<p class='a b css'>foo</p>\n", render("%p.css{:class => %w[a b]} foo")) # merge with css
|
assert_equal("<p class='a b css'>foo</p>\n", render("%p.css{:class => %w[a b]} foo")) # merge with css
|
||||||
assert_equal("<p class='b css'>foo</p>\n", render("%p.css{:class => %w[css b]} foo")) # merge uniquely
|
assert_equal("<p class='b css'>foo</p>\n", render("%p.css{:class => %w[css b]} foo")) # merge uniquely
|
||||||
assert_equal("<p class='a b c d'>foo</p>\n", render("%p{:class => [%w[a b], %w[c d]]} foo")) # flatten
|
assert_equal("<p class='a b c d'>foo</p>\n", render("%p{:class => [%w[a b], %w[c d]]} foo")) # flatten
|
||||||
assert_equal("<p class='a b'>foo</p>\n", render("%p{:class => [:a, :b] } foo")) # stringify
|
assert_equal("<p class='a b'>foo</p>\n", render("%p{:class => [:a, :b] } foo")) # stringify
|
||||||
assert_equal("<p>foo</p>\n", render("%p{:class => [nil, false] } foo")) # strip falsey
|
# [INCOMPATIBILITY] Hamlit deletes only boolean attributes
|
||||||
|
# assert_equal("<p>foo</p>\n", render("%p{:class => [nil, false] } foo")) # strip falsey
|
||||||
|
assert_equal("<p class=''>foo</p>\n", render("%p{:class => [nil, false] } foo")) # strip falsey
|
||||||
assert_equal("<p class='a'>foo</p>\n", render("%p{:class => :a} foo")) # single stringify
|
assert_equal("<p class='a'>foo</p>\n", render("%p{:class => :a} foo")) # single stringify
|
||||||
assert_equal("<p>foo</p>\n", render("%p{:class => false} foo")) # single falsey
|
# [INCOMPATIBILITY] Hamlit deletes only boolean attributes
|
||||||
|
# assert_equal("<p>foo</p>\n", render("%p{:class => false} foo")) # single falsey
|
||||||
|
assert_equal("<p class=''>foo</p>\n", render("%p{:class => false} foo")) # single falsey
|
||||||
assert_equal("<p class='a b html'>foo</p>\n", render("%p(class='html'){:class => %w[a b]} foo")) # html attrs
|
assert_equal("<p class='a b html'>foo</p>\n", render("%p(class='html'){:class => %w[a b]} foo")) # html attrs
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_id_attr_with_array; skip # array attribute
|
def test_id_attr_with_array
|
||||||
assert_equal("<p id='a_b'>foo</p>\n", render("%p{:id => %w[a b]} foo")) # basic
|
assert_equal("<p id='a_b'>foo</p>\n", render("%p{:id => %w[a b]} foo")) # basic
|
||||||
assert_equal("<p id='css_a_b'>foo</p>\n", render("%p#css{:id => %w[a b]} foo")) # merge with css
|
assert_equal("<p id='css_a_b'>foo</p>\n", render("%p#css{:id => %w[a b]} foo")) # merge with css
|
||||||
assert_equal("<p id='a_b_c_d'>foo</p>\n", render("%p{:id => [%w[a b], %w[c d]]} foo")) # flatten
|
assert_equal("<p id='a_b_c_d'>foo</p>\n", render("%p{:id => [%w[a b], %w[c d]]} foo")) # flatten
|
||||||
assert_equal("<p id='a_b'>foo</p>\n", render("%p{:id => [:a, :b] } foo")) # stringify
|
assert_equal("<p id='a_b'>foo</p>\n", render("%p{:id => [:a, :b] } foo")) # stringify
|
||||||
assert_equal("<p>foo</p>\n", render("%p{:id => [nil, false] } foo")) # strip falsey
|
# [INCOMPATIBILITY] Hamlit deletes only boolean attributes
|
||||||
|
# assert_equal("<p>foo</p>\n", render("%p{:id => [nil, false] } foo")) # strip falsey
|
||||||
|
assert_equal("<p id=''>foo</p>\n", render("%p{:id => [nil, false] } foo")) # strip falsey
|
||||||
assert_equal("<p id='a'>foo</p>\n", render("%p{:id => :a} foo")) # single stringify
|
assert_equal("<p id='a'>foo</p>\n", render("%p{:id => :a} foo")) # single stringify
|
||||||
assert_equal("<p>foo</p>\n", render("%p{:id => false} foo")) # single falsey
|
# [INCOMPATIBILITY] Hamlit deletes only boolean attributes
|
||||||
|
# assert_equal("<p>foo</p>\n", render("%p{:id => false} foo")) # single falsey
|
||||||
|
assert_equal("<p id=''>foo</p>\n", render("%p{:id => false} foo")) # single falsey
|
||||||
assert_equal("<p id='html_a_b'>foo</p>\n", render("%p(id='html'){:id => %w[a b]} foo")) # html attrs
|
assert_equal("<p id='html_a_b'>foo</p>\n", render("%p(id='html'){:id => %w[a b]} foo")) # html attrs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ describe Hamlit::Engine do
|
||||||
it { assert_render(%q|%a{ href: "'\"" }|, %Q|<a href=''"'></a>\n|) }
|
it { assert_render(%q|%a{ href: "'\"" }|, %Q|<a href=''"'></a>\n|) }
|
||||||
it { assert_inline(%Q|%a{ href: '/search?foo=bar&hoge=<fuga>' }|) }
|
it { assert_inline(%Q|%a{ href: '/search?foo=bar&hoge=<fuga>' }|) }
|
||||||
|
|
||||||
specify 'id attributes' do
|
describe 'id attributes' do
|
||||||
|
specify 'compatilibity' do
|
||||||
assert_haml(<<-HAML)
|
assert_haml(<<-HAML)
|
||||||
#a
|
#a
|
||||||
#a{ id: [] }
|
|
||||||
#a{ id: nil }
|
#a{ id: nil }
|
||||||
#a{ id: nil }(id=nil)
|
#a{ id: nil }(id=nil)
|
||||||
#a{ id: false }
|
#a{ id: false }
|
||||||
|
@ -25,7 +25,6 @@ describe Hamlit::Engine do
|
||||||
#c{ id: a = 'a' }(id=id)
|
#c{ id: a = 'a' }(id=id)
|
||||||
- id = 'a'
|
- id = 'a'
|
||||||
#d#c{ id: a = 'b' }(id=id)
|
#d#c{ id: a = 'b' }(id=id)
|
||||||
#d#c{ id: [] }(id=id)
|
|
||||||
#d#c{ id: %w[b e] }(id=id)
|
#d#c{ id: %w[b e] }(id=id)
|
||||||
- hash = { id: 'a' }
|
- hash = { id: 'a' }
|
||||||
%div{ hash }
|
%div{ hash }
|
||||||
|
@ -36,6 +35,18 @@ describe Hamlit::Engine do
|
||||||
HAML
|
HAML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
specify 'incompatibility' do
|
||||||
|
assert_render(%q|#a{ id: [] }|, %Q|<div id='a'></div>\n|)
|
||||||
|
assert_render(%q|%a{ id: [nil, false] }|, %Q|<a id=''></a>\n|)
|
||||||
|
assert_render(<<-HAML, <<-HTML)
|
||||||
|
- id = 'a'
|
||||||
|
#d#c{ id: [] }(id=id)
|
||||||
|
HAML
|
||||||
|
<div id='c_a'></div>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
specify 'class attributes' do
|
specify 'class attributes' do
|
||||||
assert_haml(<<-HAML)
|
assert_haml(<<-HAML)
|
||||||
- klass = 'b a'
|
- klass = 'b a'
|
||||||
|
|
Loading…
Reference in a new issue