Changeset 103

Show
Ignore:
Timestamp:
02/04/2007 11:22:54 (22 months ago)
Author:
tec
Message:
  • lib/markaby/builder.rb: allow root attributes to be changed (ticket:53)
  • test/test_markaby.rb: test it worked
Location:
trunk
Files:
2 modified

Legend:

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

    r102 r103  
    2727      :output_meta_tag => true, 
    2828      :auto_validation => true, 
    29       :tagset => Markaby::XHTMLTransitional 
     29      :tagset => Markaby::XHTMLTransitional, 
     30      :root_attributes => { 
     31        :xmlns => 'http://www.w3.org/1999/xhtml', :'xml:lang' => 'en', :lang => 'en' 
     32      } 
    3033    } 
    3134 
     
    224227    # are prepended.  Also assumes <tt>:xmlns => "http://www.w3.org/1999/xhtml", 
    225228    # :lang => "en"</tt>. 
    226     def xhtml_transitional(&block) 
     229    def xhtml_transitional(attrs = {}, &block) 
    227230      self.tagset = Markaby::XHTMLTransitional 
    228       xhtml_html(&block) 
     231      xhtml_html(attrs, &block) 
    229232    end 
    230233 
    231234    # Builds an html tag with XHTML 1.0 Strict doctype instead. 
    232     def xhtml_strict(&block) 
     235    def xhtml_strict(attrs = {}, &block) 
    233236      self.tagset = Markaby::XHTMLStrict 
    234       xhtml_html(&block) 
     237      xhtml_html(attrs, &block) 
    235238    end 
    236239 
    237240    private 
    238241 
    239     def xhtml_html(&block) 
     242    def xhtml_html(attrs = {}, &block) 
    240243      instruct! if @output_xml_instruction 
    241244      declare!(:DOCTYPE, :html, :PUBLIC, *tagset.doctype) 
    242       tag!(:html, :xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en", &block) 
     245      tag!(:html, @root_attributes.merge(attrs), &block) 
    243246    end 
    244247 
  • trunk/test/test_markaby.rb

    r102 r103  
    9797 
    9898  def test_full_doc_transitional 
    99     doc = mab { instruct!; xhtml_transitional { head { title 'OKay' } } }     
     99    doc = mab { xhtml_transitional { head { title 'OKay' } } }     
    100100    assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/ 
    101101    assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">}) 
     
    109109    assert doc.include?(%{<title>OKay</title>}) 
    110110  end 
     111   
     112  def test_root_attributes_can_be_changed 
     113    doc = mab { xhtml_strict(:lang => 'fr') { head { title { 'Salut!' } } } } 
     114    assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">}) 
     115    assert doc.include?(%{<title>Salut!</title>}) 
     116    assert doc.include?(%{ lang="fr"}) 
     117  end 
    111118 
    112119end