public
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/nex3/haml.git
Search Repo:
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
nex3 (author)
Thu Jan 10 00:40:00 -0800 2008
commit  36717dec6044c48faa9ccc9306b480f27d1f2a7a
tree    bb52196a943528b8b64ea269bdf809351095b70a
parent  2c11c563f2d546110e885c38f1fb0b4a4b0acec8
...
123
124
125
 
 
126
127
128
129
130
 
 
131
132
133
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
0
@@ -123,11 +123,15 @@ module Haml
0
     def self.merge_attrs(to, from)
0
       if to['id'] && from['id']
0
         to['id'] << '_' << from.delete('id')
0
+ elsif to['id'] || from['id']
0
+ from['id'] ||= to['id']
0
       end
0
 
0
       if to['class'] && from['class']
0
         # Make sure we don't duplicate class names
0
         from['class'] = (from['class'].split(' ') | to['class'].split(' ')).join(' ')
0
+ elsif to['class'] || from['class']
0
+ from['class'] ||= to['class']
0
       end
0
 
0
       to.merge!(from)
...
139
140
141
 
 
 
 
 
 
 
 
 
 
 
 
 
142
143
144
...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
0
@@ -139,6 +139,19 @@ class EngineTest < Test::Unit::TestCase
0
     assert_equal("<p>nil</p>\n", render("%p{ :attr => x } nil", :locals => {:x => nil}))
0
   end
0
 
0
+ def test_nil_id_with_syntactic_id
0
+ assert_equal("<p id='foo'>nil</p>\n", render("%p#foo{:id => nil} nil"))
0
+ assert_equal("<p id='foo_bar'>nil</p>\n", render("%p#foo{{:id => 'bar'}, :id => nil} nil"))
0
+ assert_equal("<p id='foo_bar'>nil</p>\n", render("%p#foo{{:id => nil}, :id => 'bar'} nil"))
0
+ end
0
+
0
+ def test_nil_class_with_syntactic_class
0
+ assert_equal("<p class='foo'>nil</p>\n", render("%p.foo{:class => nil} nil"))
0
+ assert_equal("<p class='bar foo'>nil</p>\n", render("%p.bar.foo{:class => nil} nil"))
0
+ assert_equal("<p class='bar foo'>nil</p>\n", render("%p.foo{{:class => 'bar'}, :class => nil} nil"))
0
+ assert_equal("<p class='bar foo'>nil</p>\n", render("%p.foo{{:class => nil}, :class => 'bar'} nil"))
0
+ end
0
+
0
   def test_locals
0
     assert_equal("<p>Paragraph!</p>\n", render("%p= text", :locals => { :text => "Paragraph!" }))
0
   end

Comments

    No one has commented yet.