Changeset 68

Show
Ignore:
Timestamp:
08/10/2006 14:50:25 (2 years ago)
Author:
why
Message:
  • lib/markaby/builder.rb: the img wrapper now returns a CssProxy? for attaching classes.
  • lib/markaby/cssproxy.rb: the merge! method for adding attributes to a proxy object.
Location:
branches/xhtml-careful
Files:
3 modified

Legend:

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

    r67 r68  
    231231 
    232232    # Builds a image tag.  Assumes <tt>:border => '0', :alt => ''</tt>. 
    233     def img(opts = {}) 
    234       tag!(:img, @@default[:image_tag_options].merge(opts)) 
     233    def img(*opts, &blk) 
     234      html_tag(:img, *opts, &blk).merge!(@@default[:image_tag_options]) 
    235235    end 
    236236 
  • branches/xhtml-careful/lib/markaby/cssproxy.rb

    r20 r68  
    1313    end 
    1414   
     15    # Adds attributes to an element, for internal use only.  For example, if you 
     16    # want to write a wrapper which sets a bunch of default attributes for a certain 
     17    # tag.  Like the default `img' method included with Markaby automatically sets an 
     18    # empty alt attribute. 
     19    def merge!(opts) 
     20      @opts.merge! opts 
     21      self 
     22    end 
     23 
    1524    # Adds attributes to an element.  Bang methods set the :id attribute. 
    1625    # Other methods add to the :class attribute.  If a block is supplied, 
     
    3443      end 
    3544    end 
     45 
     46    def to_str 
     47      @blk.call([[@opts]]).to_s 
     48    end 
     49    alias_method :to_s, :to_str 
     50 
    3651  end 
    3752end 
  • branches/xhtml-careful/test/test_markaby.rb

    r67 r68  
    8080    assert_equal %{<th colspan="1"></th>}, mab("th(:colspan => 1)") 
    8181    assert_equal %{<tbody class="okay"></tbody>}, mab("tbody.okay {}") 
     82 
     83    # ticket #19 reported no class attr on img tags 
     84    assert_equal %{<div><img border="0" class="my_class" alt=""/></div>}, mab("div { img.my_class }") 
     85    assert_equal %{<div><img border="0" class="my_class" alt="" src="/test.gif"/></div>}, mab("div { img.my_class :src => '/test.gif' }") 
    8286  end 
    8387