Search code examples
ruby-on-railsrubyhamlerb

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?


Solution

  • 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).