Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rails 3 haml microdata helpers

branch: master

Green Monkey


This Gem allows you to make html-layout with microdata properties easier. It works with ruby 1.9, rails 3, haml 3.

Green Monkey


Add to Gemfile

gem "green_monkey", '0.1.2'
gem 'chronic_duration', git: 'git://', ref: '8c0d0e101b'


helper time_tag

It almost the same with rails' time_tag but make datetime attribute in iso8601 format, according to Microdata specifications. Also it accepts Numeric values as duration for time intervals

Haml & HTML:

= time_tag post.created_at
= time_tag post.created_at, itemprop: "datePublished"
= time_tag 3.hours + 30.minutes
<time datetime="2011-11-23T00:00:00.0Z">23 Nov 2011</time>
<time datetime="2011-11-23T00:00:00.0Z" itemprop="datePublished">23 Nov 2011</time>
<time datetime="PT3H30M" title="3 hours 30 minutes">about 4 hours</time>

helper time_tag_interval

The same with time_tag but made for time intervals

= time_tag_interval Time.parse("14 March 1879"), Time.parse("18 April 1955"), :format => '%d %h %Y'
= time_tag_interval Time.parse("14 March 1989"), 150.hours, :format => :short
<time datetime="1879-03-14T00:00:00+07:30/1955-04-18T00:00:00+07:30">14 Mar 1879 - 18 Apr 1879</time>
<time datetime="1989-05-06T00:00:00+08:00/P6DT6H">06 May 00:00 in 6d 6h</time>


class User < ActiveRecord::Base
  html_schema_type :Person

User.html_schema_type #=> Mida::SchemaOrg::Person
User.find(1).html_schema_type #=> Mida::SchemaOrg::Person

Haml magic

Attribute itemprop

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

itemscope and iteptype attributes

%article[Mida(:Event)] # =>
<article itemscope itemtype=''></article>

%article[Mida(:Event, :DrinkUp)] # =>
<article itemscope itemtype=''></article>

%article[@user] # =>
<article class='user' id='1' itemid='1' itemscope iteptype=''></article>

Real examples


  = link_to "/posts/#{}", :itemprop => "url" do
    %h3[:name]>= post.title
  .post_body[:articleBody]= post.body.html_safe
  = time_tag(post.created_at, :itemprop => "datePublished")


<article class='post' id='post_1' itemid='1' itemscope itemtype=''>
  <a href="/posts/1" itemprop="url">
    <h3 itemprop='name'>Hello world!</h3>
  <div class='post_body' itemprop='articleBody'>Some text</div>
  <time datetime="2011-11-22T09:16:57.0Z" itemprop="datePublished">November 22, 2011 09:16</time>


    = link_to project.url, itemprop: 'url', target: "_blank" do
      %h3[:name]<>= project.title
    = " "
    - if project.source_code.present?
      = link_to "(source code)", project.source_code, class: "source_link", target: "_blank"
    = simple_format project.description

    - for item_type in project.item_types.split(" ")
      %li[Mida(:WebPageElement, :ItemType), :mentions]
        %span[:name]= item_type


<article class='project' id='project_2' itemid='2' itemscope itemtype=''>
    <a href="" itemprop="url" target="_blank">
      <h3 itemprop='name'>Mida - A Microdata extractor/parser library for Ruby</h3>
    <a href="" class="source_link" target="_blank">(source code)</a>

  <section itemprop='description'>
    <p>A Ruby Microdata parser/extractor</p>

    <li itemprop='mentions' itemscope itemtype=''>
      <span itemprop='name'></span>

I use it in Microdata tools

Something went wrong with that request. Please try again.