Changeset 67

Show
Ignore:
Timestamp:
08/10/2006 14:15:33 (2 years ago)
Author:
why
Message:
  • lib/markaby/builder.rb: raise an InvalidXhtmlError? for duplicate IDs, from ticket #12, thankyou jerrett!
Location:
branches/xhtml-careful
Files:
2 modified

Legend:

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

    r65 r67  
    5555      @streams = [[]] 
    5656      @assigns = assigns 
     57      @elements = {} 
    5758 
    5859      @@default.each do |k, v| 
     
    141142    # the arguments are the same as the tags implemented via method_missing. 
    142143    def tag!(tag, *args, &block) 
     144      ele_id = nil 
    143145      if @auto_validation and @tagset 
    144146          if !@tagset.tagset.has_key?(tag) 
     
    147149              attrs = args.last.to_hash 
    148150              attrs.each do |k, v| 
    149                   unless k =~ /:/ or @tagset.tagset[tag].include? k.to_s.downcase.intern 
     151                  atname = k.to_s.downcase.intern 
     152                  unless k =~ /:/ or @tagset.tagset[tag].include? atname 
    150153                      raise InvalidXhtmlError, "no attribute `#{k}' on #{tag} elements" 
     154                  end 
     155                  if atname == :id 
     156                      ele_id = v.to_s 
     157                      if @elements.has_key? ele_id 
     158                          raise InvalidXhtmlError, "id `#{ele_id}' already used (id's must be unique)." 
     159                      end 
    151160                  end 
    152161              end 
     
    157166        block = proc { text(str) } 
    158167      end 
    159       fragment { @builder.method_missing(tag, *args, &block) } 
     168 
     169      f = fragment { @builder.method_missing(tag, *args, &block) } 
     170      @elements[ele_id] = f if ele_id 
     171      f 
    160172    end 
    161173 
  • branches/xhtml-careful/test/test_markaby.rb

    r66 r67  
    8686    assert_exception %{div(:styl => 'ok') {}}, Markaby::InvalidXhtmlError, "no attribute `styl' on div elements" 
    8787  end 
     88 
     89  def test_unique_ids  
     90    assert_exception %{html { div.one! {}; div.one! {} }}, Markaby::InvalidXhtmlError, "id `one' already used (id's must be unique)." 
     91    assert_equal "<div id=\"one\"></div>", mab(%{div.one! {}}) 
     92  end  
     93 
    8894end