Changeset 48

Show
Ignore:
Timestamp:
05/21/2006 13:12:23 (3 years ago)
Author:
tec
Message:
  • lib/markaby/builder.rb: undo [47]. give preference to helper methods
  • test/test_markaby.rb: test case for instance variables
Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/markaby/builder.rb

    r47 r48  
    162162    # * Otherwise, +sym+ and its arguments are passed to tag! 
    163163    def method_missing(sym, *args, &block) 
    164       if TAGS.include?(sym) or (FORM_TAGS.include?(sym) and args.empty?) 
     164      if @helpers.respond_to?(sym) 
     165        r = @helpers.send(sym, *args, &block) 
     166        @builder << r if @output_helpers 
     167        r 
     168      elsif ::Builder::XmlMarkup.instance_methods.include?(sym.to_s) 
     169        @builder.__send__(sym, *args, &block) 
     170      elsif TAGS.include?(sym) or (FORM_TAGS.include?(sym) and args.empty?) 
    165171        if args.empty? and block.nil? 
    166172          return CssProxy.new do |args, block| 
     
    171177          end 
    172178        end 
    173         if args.first.respond_to? :to_hash 
    174           block ||= proc{} 
    175         end 
    176179        tag!(sym, *args, &block) 
    177180      elsif SELF_CLOSING_TAGS.include?(sym) 
    178181        tag!(sym, *args) 
    179       elsif @helpers.respond_to?(sym, true) 
    180         r = @helpers.send(sym, *args, &block) 
    181         @builder << r if @output_helpers 
    182         r 
    183       elsif ::Builder::XmlMarkup.instance_methods.include?(sym.to_s) 
    184         @builder.__send__(sym, *args, &block) 
    185       elsif instance_variable_get("@#{sym}") 
    186         instance_variable_get("@#{sym}") 
     182      elsif value = instance_variable_get("@#{sym}") 
     183        value 
    187184      else 
    188185        tag!(sym, *args, &block) 
  • trunk/test/test_markaby.rb

    r46 r48  
    5555  end 
    5656 
     57  def test_ivars_without_at_symbol 
     58    assert_equal "<h1>Hello World</h1>\n", mab("@message = 'Hello World'; h1 message") 
     59  end 
     60   
    5761  def test_output_helpers 
    5862    assert_equal %{<a href="">edit</a>}, mab("link_to('edit')", {}, MarkabyTestHelpers)