mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Fixing a bug where the #.-syntax class or id of a Haml tag would be overwritten by setting the value in the attrs hash to nil. Thanks to Aman Gupta for pointing this out.
git-svn-id: svn://hamptoncatlin.com/haml/tags/stable@726 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
2c11c563f2
commit
36717dec60
2 changed files with 17 additions and 0 deletions
|
@ -123,11 +123,15 @@ module Haml
|
|||
def self.merge_attrs(to, from)
|
||||
if to['id'] && from['id']
|
||||
to['id'] << '_' << from.delete('id')
|
||||
elsif to['id'] || from['id']
|
||||
from['id'] ||= to['id']
|
||||
end
|
||||
|
||||
if to['class'] && from['class']
|
||||
# Make sure we don't duplicate class names
|
||||
from['class'] = (from['class'].split(' ') | to['class'].split(' ')).join(' ')
|
||||
elsif to['class'] || from['class']
|
||||
from['class'] ||= to['class']
|
||||
end
|
||||
|
||||
to.merge!(from)
|
||||
|
|
|
@ -139,6 +139,19 @@ class EngineTest < Test::Unit::TestCase
|
|||
assert_equal("<p>nil</p>\n", render("%p{ :attr => x } nil", :locals => {:x => nil}))
|
||||
end
|
||||
|
||||
def test_nil_id_with_syntactic_id
|
||||
assert_equal("<p id='foo'>nil</p>\n", render("%p#foo{:id => nil} nil"))
|
||||
assert_equal("<p id='foo_bar'>nil</p>\n", render("%p#foo{{:id => 'bar'}, :id => nil} nil"))
|
||||
assert_equal("<p id='foo_bar'>nil</p>\n", render("%p#foo{{:id => nil}, :id => 'bar'} nil"))
|
||||
end
|
||||
|
||||
def test_nil_class_with_syntactic_class
|
||||
assert_equal("<p class='foo'>nil</p>\n", render("%p.foo{:class => nil} nil"))
|
||||
assert_equal("<p class='bar foo'>nil</p>\n", render("%p.bar.foo{:class => nil} nil"))
|
||||
assert_equal("<p class='bar foo'>nil</p>\n", render("%p.foo{{:class => 'bar'}, :class => nil} nil"))
|
||||
assert_equal("<p class='bar foo'>nil</p>\n", render("%p.foo{{:class => nil}, :class => 'bar'} nil"))
|
||||
end
|
||||
|
||||
def test_locals
|
||||
assert_equal("<p>Paragraph!</p>\n", render("%p= text", :locals => { :text => "Paragraph!" }))
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue