public
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/nex3/haml.git
Bring #haml_tag more in line with actual tag behavior.
nex3 (author)
Thu Jun 05 18:16:27 -0700 2008
commit  377464e79e6b3633e63ea87bb2863b0fb786eaaa
tree    9676f4a243ddca66e0ad712029b9d5526b8dc56c
parent  27daf070ba7ec09d3c5181a504201409fa2b9568
...
321
322
323
324
325
326
327
328
329
330
331
332
333
 
 
 
 
 
 
 
 
 
334
 
 
 
 
 
335
336
337
...
321
322
323
 
 
 
 
 
 
 
 
 
 
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
0
@@ -321,17 +321,21 @@ module Haml
0
         return nil
0
       end
0
 
0
- puts "<#{name}#{attributes}>"
0
- unless text && text.empty?
0
- tab_up
0
- # Print out either the text (using push_text) or call the block and add an endline
0
- if text
0
- puts(text)
0
- elsif block
0
- block.call
0
- end
0
- tab_down
0
+ tag = "<#{name}#{attributes}>"
0
+ if block.nil?
0
+ tag << text.to_s << "</#{name}>"
0
+ puts tag
0
+ return
0
+ end
0
+
0
+ if text
0
+ raise Error.new("Illegal nesting: content can't be both given to haml_tag :#{name} and nested within it.")
0
       end
0
+
0
+ puts tag
0
+ tab_up
0
+ block.call
0
+ tab_down
0
       puts "</#{name}>"
0
       nil
0
     end
...
105
106
107
108
 
 
 
 
 
 
 
 
 
109
110
111
...
105
106
107
 
108
109
110
111
112
113
114
115
116
117
118
119
0
@@ -105,7 +105,15 @@ class HelperTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_haml_tag_non_autoclosed_tags_arent_closed
0
- assert_equal("<p>\n</p>\n", render("- haml_tag :p"))
0
+ assert_equal("<p></p>\n", render("- haml_tag :p"))
0
+ end
0
+
0
+ def test_haml_tag_renders_text_on_a_single_line
0
+ assert_equal("<p>#{'a' * 100}</p>\n", render("- haml_tag :p, 'a' * 100"))
0
+ end
0
+
0
+ def test_haml_tag_raises_error_for_multiple_content
0
+ assert_raise(Haml::Error) { render("- haml_tag :p, 'foo' do\n bar") }
0
   end
0
 
0
   def test_is_haml
...
79
80
81
82
83
84
 
85
86
87
...
90
91
92
93
94
 
...
79
80
81
 
 
 
82
83
84
85
...
88
89
90
 
 
91
0
@@ -79,9 +79,7 @@ foo
0
 <table>
0
   <tr>
0
     <td class='cell'>
0
- <strong>
0
- strong!
0
- </strong>
0
+ <strong>strong!</strong>
0
       data
0
     </td>
0
     <td>
0
@@ -90,5 +88,4 @@ foo
0
   </tr>
0
 </table>
0
 <hr />
0
-<div>
0
-</div>
0
+<div></div>

Comments

    No one has commented yet.