简体   繁体   中英

Gem Green Monkey - Rails

Has anyone used " Green Monkey " to create an HTML-layout with microdata properties?

I'm struggling to understand how to go from Haml to Html.erb, according to the documentation. For example, I haven't figured out the Haml %span[:name]= item.name .

I get most of it except [:name] .

How do I translate this in html.erb?

Green Monkey adds an extension to Haml. The documents display what the input and output look like.

Haml input (assuming item.name is set to 'Item name' ):

%span[:name]= item.name

HTML output:

<span itemprop='name'>Item name</span>

It is taking the value in [] , transforming it into HTML attributes. Symbols become itemprop attributes, and Mida objects become itemscope and itemtype attributes.

There is a also a helper the documention mentions above that example, which would work like this:

<span<%=mida_scope(:item)%>><%=item.name%></span>

mida_scope transforms the Mida-aware objects to HTML attributes and outputs those using the Rails tag_builder.tag_options(html_attributes) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM