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/trunk@726 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2008-01-10 08:40:00 +00:00
parent d19156fdf0
commit a76b25d1a5
2 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -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