Changeset 66

Show
Ignore:
Timestamp:
08/10/2006 13:50:07 (2 years ago)
Author:
why
Message:
  • lib/markaby/tags.rb: at last, adding the missing attributes from tickets #14 and #21. thankyou, everyone.
Location:
branches/xhtml-careful
Files:
2 modified

Legend:

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

    r63 r66  
    66 
    77  # Common sets of attributes. 
    8   AttrCustom = [:id, :class, :style] 
     8  AttrCore = [:id, :class, :style, :title] 
     9  AttrI18n = [:lang, :'xml:lang', :dir] 
    910  AttrEvents = [:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover, :onmousemove,  
    1011      :onmouseout, :onkeypress, :onkeydown, :onkeyup] 
    11   AttrAnno = [:title, :lang, :dir] 
    12   Attrs = AttrCustom + AttrEvents + AttrAnno 
     12  AttrFocus = [:accesskey, :tabindex, :onfocus, :onblur] 
     13  AttrHAlign = [:align, :char, :charoff] 
     14  AttrVAlign = [:valign] 
     15  Attrs = AttrCore + AttrI18n + AttrEvents 
    1316 
    14   # Very basic rules from the XHTML 1.0 Strict DTD. 
     17  # All the tags and attributes from XHTML 1.0 Strict 
    1518  class XHTMLStrict 
    1619    class << self 
     
    1922    @doctype = ["-//W3C//DTD XHTML 1.0 Strict//EN", "DTD/xhtml1-strict.dtd"] 
    2023    @tagset = { 
    21       :pre => AttrCustom + AttrAnno + [:space],  
     24      :html => AttrI18n + [:id, :xmlns], 
     25      :head => AttrI18n + [:id, :profile], 
     26      :title => AttrI18n + [:id], 
     27      :base => [:href, :id], 
     28      :meta => AttrI18n + [:id, :http, :name, :content, :scheme, :'http-equiv'], 
     29      :link => Attrs + [:charset, :href, :hreflang, :type, :rel, :rev, :media], 
     30      :style => AttrI18n + [:id, :type, :media, :title, :'xml:space'], 
     31      :script => [:id, :charset, :type, :src, :defer, :'xml:space'], 
     32      :noscript => Attrs, 
     33      :body => Attrs + [:onload, :onunload], 
     34      :div => Attrs, 
     35      :p => Attrs, 
     36      :ul => Attrs, 
     37      :ol => Attrs, 
     38      :li => Attrs, 
     39      :dl => Attrs, 
     40      :dt => Attrs, 
     41      :dd => Attrs, 
     42      :address => Attrs, 
     43      :hr => Attrs, 
     44      :pre => Attrs + [:'xml:space'], 
     45      :blockquote => Attrs + [:cite], 
     46      :ins => Attrs + [:cite, :datetime], 
     47      :del => Attrs + [:cite, :datetime], 
     48      :a => Attrs + AttrFocus + [:charset, :type, :name, :href, :hreflang, :rel, :rev, :shape, :coords], 
     49      :span => Attrs, 
     50      :bdo => AttrCore + AttrEvents + [:lang, :'xml:lang', :dir], 
     51      :br => AttrCore, 
    2252      :em => Attrs, 
     53      :strong => Attrs, 
     54      :dfn => Attrs, 
    2355      :code => Attrs, 
     56      :samp => Attrs, 
     57      :kbd => Attrs, 
     58      :var => Attrs, 
     59      :cite => Attrs, 
     60      :abbr => Attrs, 
     61      :acronym => Attrs, 
     62      :q => Attrs + [:cite], 
     63      :sub => Attrs, 
     64      :sup => Attrs, 
     65      :tt => Attrs, 
     66      :i => Attrs, 
     67      :b => Attrs, 
     68      :big => Attrs, 
     69      :small => Attrs, 
     70      :object => Attrs + [:declare, :classid, :codebase, :data, :type, :codetype, :archive, :standby, :height, :width, :usemap, :name, :tabindex], 
     71      :param => [:id, :name, :value, :valuetype, :type], 
     72      :img => Attrs + [:src, :alt, :longdesc, :height, :width, :usemap, :ismap], 
     73      :map => AttrI18n + AttrEvents + [:id, :class, :style, :title, :name], 
     74      :area => Attrs + AttrFocus + [:shape, :coords, :href, :nohref, :alt], 
     75      :form => Attrs + [:action, :method, :enctype, :onsubmit, :onreset, :accept, :accept], 
     76      :label => Attrs + [:for, :accesskey, :onfocus, :onblur], 
     77      :input => Attrs + AttrFocus + [:type, :name, :value, :checked, :disabled, :readonly, :size, :maxlength, :src, :alt, :usemap, :onselect, :onchange, :accept], 
     78      :select => Attrs + [:name, :size, :multiple, :disabled, :tabindex, :onfocus, :onblur, :onchange], 
     79      :optgroup => Attrs + [:disabled, :label], 
     80      :option => Attrs + [:selected, :disabled, :label, :value], 
     81      :textarea => Attrs + AttrFocus + [:name, :rows, :cols, :disabled, :readonly, :onselect, :onchange], 
     82      :fieldset => Attrs, 
     83      :legend => Attrs + [:accesskey], 
     84      :button => Attrs + AttrFocus + [:name, :value, :type, :disabled], 
     85      :table => Attrs + [:summary, :width, :border, :frame, :rules, :cellspacing, :cellpadding], 
     86      :caption => Attrs, 
     87      :colgroup => Attrs + AttrHAlign + AttrVAlign + [:span, :width], 
     88      :col => Attrs + AttrHAlign + AttrVAlign + [:span, :width], 
     89      :thead => Attrs + AttrHAlign + AttrVAlign, 
     90      :tfoot => Attrs + AttrHAlign + AttrVAlign, 
     91      :tbody => Attrs + AttrHAlign + AttrVAlign, 
     92      :tr => Attrs + AttrHAlign + AttrVAlign, 
     93      :th => Attrs + AttrHAlign + AttrVAlign + [:abbr, :axis, :headers, :scope, :rowspan, :colspan], 
     94      :td => Attrs + AttrHAlign + AttrVAlign + [:abbr, :axis, :headers, :scope, :rowspan, :colspan], 
     95      :h1 => Attrs, 
    2496      :h2 => Attrs, 
    2597      :h3 => Attrs, 
    26       :h1 => Attrs, 
    27       :h6 => Attrs, 
    28       :dl => Attrs, 
    2998      :h4 => Attrs, 
    3099      :h5 => Attrs, 
    31       :area => Attrs + [:accesskey, :tabindex, :onfocus, :onblur, :shape, :coords, :href, :nohref, :alt],  
    32       :meta => [:lang, :dir, :id, :name, :content, :scheme, "http-equiv".intern],  
    33       :table => [],  
    34       :dfn => Attrs, 
    35       :label => Attrs + [:for, :accesskey, :onfocus, :onblur],  
    36       :select => Attrs + [:name, :size, :multiple, :disabled, :tabindex, :onfocus, :onblur, :onchange],  
    37       :noscript => Attrs, 
    38       :style => [:lang, :dir, :id, :type, :media, :title, :space],  
    39       :strong => Attrs, 
    40       :span => Attrs, 
    41       :sub => Attrs, 
    42       :img => Attrs + [:src, :alt, :longdesc, :height, :width, :usemap, :ismap],  
    43       :title => [:lang, :dir, :id],  
    44       :bdo => AttrCustom + [:title] + AttrEvents + [:lang, :dir],  
    45       :tr => [],  
    46       :tbody => [],  
    47       :param => [:id, :name, :value, :valuetype, :type],  
    48       :li => Attrs, 
    49       :acronym => Attrs, 
    50       :html => [:lang, :dir, :id, :xmlns],  
    51       :caption => [],  
    52       :tfoot => [],  
    53       :th => [],  
    54       :sup => Attrs, 
    55       :var => Attrs, 
    56       :input => Attrs + [:accesskey, :tabindex, :onfocus, :onblur, :type, :name, :value, :checked, :disabled, :readonly, :size, :maxlength, :src, :alt, :usemap, :onselect, :onchange, :accept],  
    57       :td => Attrs + [:summary, :width, :border, :frame, :rules, :cellspacing, :cellpadding, :span, :align, :char, :charoff, :valign, :abbr, :axis, :headers, :scope, :rowspan, :colspan],  
    58       :samp => Attrs, 
    59       :cite => Attrs, 
    60       :thead => [],  
    61       :body => Attrs + [:onload, :onunload],  
    62       :map => AttrCustom + [:lang, :dir, ] + AttrEvents + [:title, :name],  
    63       :head => [:lang, :dir, :id, :profile],  
    64       :blockquote => Attrs + [:cite],  
    65       :fieldset => Attrs, 
    66       :option => Attrs + [:selected, :disabled, :label, :value],  
    67       :form => Attrs + [:action, :method, :enctype, :onsubmit, :onreset, :accept, 'accept-charset'],  
    68       :hr => Attrs, 
    69       :big => Attrs, 
    70       :dd => Attrs, 
    71       :object => Attrs + [:declare, :classid, :codebase, :data, :type, :codetype, :archive, :standby, :height, :width, :usemap, :name, :tabindex],  
    72       :base => [:href, :id],  
    73       :link => Attrs + [:charset, :href, :hreflang, :type, :rel, :rev, :media],  
    74       :kbd => Attrs, 
    75       :br => AttrCustom + [:title],  
    76       :address => Attrs, 
    77       :optgroup => Attrs + [:disabled, :label],  
    78       :dt => Attrs, 
    79       :ins => Attrs + [:cite, :datetime],  
    80       :b => Attrs, 
    81       :legend => Attrs + [:accesskey],  
    82       :abbr => Attrs, 
    83       :a => Attrs + [:accesskey, :tabindex, :onfocus, :onblur, :charset, :type, :name, :href, :hreflang, :rel, :rev, :shape, :coords],  
    84       :ol => Attrs, 
    85       :textarea => Attrs + [:accesskey, :tabindex, :onfocus, :onblur, :name, :rows, :cols, :disabled, :readonly, :onselect, :onchange],  
    86       :colgroup => [],  
    87       :i => Attrs, 
    88       :button => Attrs + [:accesskey, :tabindex, :onfocus, :onblur, :name, :value, :type, :disabled],  
    89       :script => [:id, :charset, :type, :src, :defer, :space],  
    90       :col => [],  
    91       :q => Attrs + [:cite],  
    92       :p => Attrs, 
    93       :del => Attrs + [:cite, :datetime],  
    94       :small => Attrs, 
    95       :div => Attrs, 
    96       :tt => Attrs, 
    97       :ul => Attrs   
     100      :h6 => Attrs 
    98101    } 
    99102 
     
    117120      :u => Attrs, 
    118121      :menu => Attrs + [:compact],  
    119       :iframe => AttrCustom + [:title, :longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :scrolling, :align, :height, :width],  
    120       :font => AttrCustom + AttrAnno + [:size, :color, :face],  
     122      :iframe => AttrCore + [:longdesc, :name, :src, :frameborder, :marginwidth, :marginheight, :scrolling, :align, :height, :width], 
     123      :font => AttrCore + AttrI18n + [:size, :color, :face], 
    121124      :s => Attrs, 
    122       :applet => AttrCustom + [:title, :codebase, :archive, :code, :object, :alt, :name, :width, :height, :align, :hspace, :vspace],  
    123       :isindex => AttrCustom + AttrAnno + [:prompt] 
     125      :applet => AttrCore + [:codebase, :archive, :code, :object, :alt, :name, :width, :height, :align, :hspace, :vspace], 
     126      :isindex => AttrCore + AttrI18n + [:prompt] 
    124127 
    125128    # Additional attributes found in XHTML 1.0 Transitional 
    126129    { :script => [:language], 
    127130      :a => [:target], 
    128       :td => [:bgcolor, :nowrap, :height], 
     131      :td => [:bgcolor, :nowrap, :width, :height], 
    129132      :p => [:align], 
    130133      :h5 => [:align], 
     
    132135      :li => [:type, :value], 
    133136      :div => [:align], 
    134       :pre => AttrEvents + [:width], 
     137      :pre => [:width], 
    135138      :body => [:background, :bgcolor, :text, :link, :vlink, :alink], 
    136139      :ol => [:type, :compact, :start], 
  • branches/xhtml-careful/test/test_markaby.rb

    r63 r66  
    7676  end 
    7777 
     78  def test_valid_xhtml 
     79    # tickets #14 and #21 identified missing attributes, let's test a few. 
     80    assert_equal %{<th colspan="1"></th>}, mab("th(:colspan => 1)") 
     81    assert_equal %{<tbody class="okay"></tbody>}, mab("tbody.okay {}") 
     82  end 
     83 
    7884  def test_invalid_xhtml 
    7985    assert_exception %{dav {}}, NoMethodError, "no such method `dav'" 
    8086    assert_exception %{div(:styl => 'ok') {}}, Markaby::InvalidXhtmlError, "no attribute `styl' on div elements" 
    81     assert_exception %{tbody.okay {}}, Markaby::InvalidXhtmlError, "no attribute `class' on tbody elements" 
    8287  end 
    8388end