Changeset 52
- Timestamp:
- 05/21/2006 17:43:52 (3 years ago)
- Location:
- branches/xhtml-careful
- Files:
-
- 2 modified
-
lib/markaby/builder.rb (modified) (4 diffs)
-
test/test_markaby.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/xhtml-careful/lib/markaby/builder.rb
r51 r52 81 81 82 82 @margin += 1 83 @builder = ::Builder::XmlMarkup.new(:indent => @indent, :margin => @margin, :target => @streams.first) 83 @builder = ::Builder::XmlMarkup.new(:indent => @indent, :margin => @margin, :target => @streams.last) 84 def @builder.target=(io) 85 @target = io 86 end 84 87 85 88 if block … … 91 94 # Returns a string containing the HTML stream. Internally, the stream is stored as an Array. 92 95 def to_s 93 @streams. first.join96 @streams.last.join 94 97 end 95 98 … … 112 115 # 113 116 def capture(&block) 114 old_stream = @streams.first.dup 115 @streams.insert(1, old_stream) 116 @streams.first.replace [] 117 @streams.push(builder.target = []) 117 118 str = instance_eval(&block) 118 str = @streams. first.join unless @streams.first.compact.empty?119 @streams. delete_at(1)120 @streams.first.replace old_stream119 str = @streams.last.join unless @streams.last.compact.empty? 120 @streams.pop 121 builder.target = @streams.last 121 122 str 122 123 end … … 230 231 231 232 def fragment 232 stream = @streams. first233 stream = @streams.last 233 234 f1 = stream.length 234 235 yield -
branches/xhtml-careful/test/test_markaby.rb
r39 r52 57 57 58 58 def test_fragments 59 assert_equal %{ },60 mab(%q{div { @a = small 'Miniature'; @b = strong 'Large'; h1 "Monkeys"; h2 "Giraffes #{@a} and #{@b}"; h3 "Donkeys"; h4 "Parakeet #{@b} as well..."}})61 assert_equal %{ },62 mab(%q{div { h1 "Monkeys"; h2 "Giraffes #{small 'Miniature' } and #{strong 'Large'}"; h3 "Donkeys"; h4 "Parakeet #{b { i 'Innocent IV' }} in Classic Chartreuse"}})63 assert_equal %{<div>\n<h1>Monkeys</h1>\n<h2> Giraffes <strong>Miniature</strong>\n</h2>\n<h3>Donkeys</h3>\n</div>\n},64 mab(%q{div { h1 "Monkeys"; h2 "Giraffes #{strong 'Miniature' }"; h3 "Donkeys"}})59 assert_equal %{<div>\n<h1>Monkeys</h1>\n<h2>\nGiraffes <small>Miniature</small>\n and <strong>Large</strong>\n</h2>\n<h3>Donkeys</h3>\n<h4>\nParakeet <b>\n<i>Innocent IV</i>\n</b>\n in Classic Chartreuse</h4>\n</div>\n}, 60 mab(%q{div { h1 "Monkeys"; h2 { "Giraffes #{small 'Miniature' } and #{strong 'Large'}" }; h3 "Donkeys"; h4 { "Parakeet #{b { i 'Innocent IV' }} in Classic Chartreuse" } }}) 61 assert_equal %{<div>\n<h1>Monkeys</h1>\n<h2>\nGiraffes <strong>Miniature</strong>\n</h2>\n<h3>Donkeys</h3>\n</div>\n}, 62 mab(%q{div { h1 "Monkeys"; h2 { "Giraffes #{strong 'Miniature' }" }; h3 "Donkeys" }}) 63 assert_equal %{<div>\n<h1>Monkeys</h1>\n<h2>\nGiraffes <small>Miniature</small>\n and <strong>Large</strong>\n</h2>\n<h3>Donkeys</h3>\n<h4>\nParakeet <strong>Large</strong>\n as well...</h4>\n</div>\n}, 64 mab(%q{div { @a = small 'Miniature'; @b = strong 'Large'; h1 "Monkeys"; h2 { "Giraffes #{@a} and #{@b}" }; h3 "Donkeys"; h4 { "Parakeet #{@b} as well..." }}}) 65 65 end 66 66 end