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 BreadCrumbs. Here's the output I'd like to generate:
<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"></div>
But you can see that the itemscope attribute value has no value. Ideally, I'd like to do something like this in Rails...
content_tag(:div, "somecontent", :itemscope => nil, :item_type => "http://data-vocabulary.org/Breadcrumb")
... but I can't seem to get generate an attribute without a value.
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 <input type='checkbox' checked='checked' />
.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With