Changeset 52

Show
Ignore:
Timestamp:
05/21/2006 17:43:52 (3 years ago)
Author:
why
Message:
  • lib/markaby/builder.rb: removing a bit of the complexity from the retargeting.
  • test/test_markaby.rb: testing the implicit capture.
Location:
branches/xhtml-careful
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/xhtml-careful/lib/markaby/builder.rb

    r51 r52  
    8181 
    8282      @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 
    8487 
    8588      if block 
     
    9194    # Returns a string containing the HTML stream.  Internally, the stream is stored as an Array. 
    9295    def to_s 
    93       @streams.first.join 
     96      @streams.last.join 
    9497    end 
    9598 
     
    112115    # 
    113116    def capture(&block) 
    114       old_stream = @streams.first.dup 
    115       @streams.insert(1, old_stream) 
    116       @streams.first.replace [] 
     117      @streams.push(builder.target = []) 
    117118      str = instance_eval(&block) 
    118       str = @streams.first.join unless @streams.first.compact.empty? 
    119       @streams.delete_at(1) 
    120       @streams.first.replace old_stream 
     119      str = @streams.last.join unless @streams.last.compact.empty? 
     120      @streams.pop 
     121      builder.target = @streams.last 
    121122      str 
    122123    end 
     
    230231 
    231232    def fragment 
    232       stream = @streams.first 
     233      stream = @streams.last 
    233234      f1 = stream.length 
    234235      yield 
  • branches/xhtml-careful/test/test_markaby.rb

    r39 r52  
    5757 
    5858  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..." }}}) 
    6565  end 
    6666end