Rails 3 & HTML 5 Microdata

后端 未结 2 1921
别跟我提以往
别跟我提以往 2021-01-01 03:49

In Rails, is it possible to create a HTML 5 valueless attribute using any of the ActionView Helpers? I\'m trying to create the HTML 5 itemprop microdata for google\'s BreadC

2条回答
  •  余生分开走
    2021-01-01 04:23

    No, you can't. Rails' tag helper defines a ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES array, and any attributes in that array will be outputted as key=key, so if you had, say, tag(:input, :type => :checkbox, :checked => true), the output should be .

    I presume that this parses properly, since an XML parser is simply going to check for the presence of the attribute, so any value should work.

    To that end, you could use:

    content_tag(:div, "somecontent", :itemscope => "itemscope", :item_type ...
    

    This will output itemscope="itemscope" in the tag, but it should result in the same desired effect when parsed.

    Alternately, you could add itemscope to the BOOLEAN_ATTRIBUTES, then specify :itemscope => true.

提交回复
热议问题