README

Build Status

Item

Item is a Ruby on Rails plugin for implementing semantic markup (microdata) without messing up the view code.

See Schema.org for valid microdata.

Installation

Add this line to your application's Gemfile:

gem 'item'

Then run:

$ bundle

Usage

Scopes

To define an itemscope:

<% scope :product do %>
  ...
<% end %>

This will generate the following HTML:

<div itemscope itemtype="http://schema.org/Product">
  ...
</div>

Properties

To define an itemprop span:

<%= prop :name, "My Product Name" %>

This will generate the following HTML:

<span itemprop="name">My Product Name</span>

Hidden meta properties

To define hidden itemprops via <meta> tags, pass a hash to the prop helper:

<%= prop date_published: Date.today %>

This will generate the following HTML:

<meta itemprop="datePublished" content="2014-07-26" />

To define a link to an enumeration member, e.g. ItemAvailability

Example

The following is the Product example on Schema.org rewritten with Item. In your view:

<% scope :product do %>
  <%= itemprop :name, "Kenmore White 17\" Microwave" %>
  <%= image_tag "kenmore-microwave-17in.jpg" %>

  <% prop :aggregate_rating do %>
    Rated <%= prop :rating_value, 3.5 %>/5
    based on <%= prop :review_count, 11 %> custom reviews
  <% end %>

  <% prop :offers, type: :offer do %>
    <%= prop :price, "$55.00" %>
    <%= prop :availability, :in_stock %>
    In Stock
  <% end %>

  Product description:
  <%= prop :description, "0.7 cubic feet countertop microwave.
    Has six preset cooking categories and convenience features like
    Add-A-Minute and Child Lock." %>

  Customer reviews:
  <% prop :review do %>
    <%= prop :name, "Not a happy camper" %> -
    by <%= prop :author, "Ellie" %>,
    <%= prop date_published: "2011-04-01" %>
    April 1, 2011
    <% prop :review_rating, type: :rating do %>
      <%= prop worst_rating: 1 %>
      <%= prop :rating_value, 1 %> /
      <%= prop :best_rating, 5 %> stars
      <%= prop :description, "The lamp burned out and now I have to replace it." %>
    <% end %>
  <% end %>
<% end %>

Contributing

Changes and improvements are to Item are very welcome and greatly appreciated.

  1. Fork the project
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Add your changes, including tests so we don't break it unintentionally.
  4. Run rake to make sure the tests pass
  5. Commit your changes (git commit -am 'Add feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new pull request