Glenn Gillen

Free ATOM feed loving

Chris over at Err the Blog have a great article about how you can very quickly and easily create ATOM syndication of your content with a gem called mofo.

What are microformats?

I'll avoid any misrepresentation by taking the definition straight from the microformats site

Designed for humans first and machines second, microformats are a set of simple, open data formats built upon existing and widely adopted standards Basically what it means in practice is that if you've written well structured and semantically correct (X)HTML code, then with the sprinkling of a few additional class definitions or attributes you can extend what you've already got to support microformats.

What are some example microformats?

There are already formats defined for people, places, and business cards, events and calendaring, voting, reviews, friends and connections, and tags to name but just a select few.

Okay, so how do we turn this into a ATOM feed?

Well here is what the entry for this article in the main page listing would currently look like:

<div class="entry">
  <span class="header">
    <h3><a href="/articles/2008/01/23/free-atom-feed-loving/">Free ATOM feed loving</a></h3>
    <p class="info">Posted by glenn gillen on Jan 23, 2008</p>
    <p class="info tag_line">Posted in <a href="/tag/microformats">microformats</a>, <a href="/tag/atom">atom</a></p>
  </span>
  <a href="/articles/2008/01/23/free-atom-feed-loving/"><img alt="" size="preview" src=""/></a>
  <br/>
  <p>Chris over at Err the Blog have a great article about how you can very quickly and easily
     <a href="http://errtheblog.com/posts/78-feeds-for-free">with a gem called mofo.</a></p>
  <a href="/articles/2008/01/23/free-atom-feed-loving/#extended">More...</a>
</div>

And all it would take to turn it into a microformat hEntry is to make it the following:

<div class="entry hentry">
  <span class="header">
    <h3><a href="/articles/2008/01/23/free-atom-feed-loving/" class="entry-title">Free ATOM feed loving</a></h3>
    <p class="info">Posted by <span class="author vcard fn">glenn gillen</span> on <abbr class="updated" title="2008-01-23T09:00:00Z">Jan 23, 2008</abbr></p>
    <p class="info tag_line">Posted in <a href="/tag/microformats">microformats</a>, <a href="/tag/atom">atom</a></p>
  </span>
  <a href="/articles/2008/01/23/free-atom-feed-loving/"><img alt="" size="preview" src=""/></a>
  <br/>
  <p class="entry-content">Chris over at Err the Blog have a great article about how you can very quickly and easily
     <a href="http://errtheblog.com/posts/78-feeds-for-free">with a gem called mofo.</a></p>
  <a href="/articles/2008/01/23/free-atom-feed-loving/#extended">More...</a>
</div>

Just to highlight it incase you missed it. There is a new hentry class on the container div, a new entry-title on the link to the entry, a span defining a vcard around my name, and the readable date has an abbr tag to translate it back into something the computer prefers. And finally, the p containing the content has had an entry-content class applied.

So that takes care of outputting it in as a microformat, but what use is that unless you've got something to consume it? How about we use mofo to render our view, extract the microformats, and then publish them as a feed for inclusion in your favourite reader? Add something like this to your controller:

def index
  @posts = Post.find(:all)
  respond_to do |format|
    format.html 
    format.rss do
      target = url_for(:action => :index, :format => "html")
      render :xml => hEntry.find(target).to_atom(:title => 'whatever')
    end
  end
end

Great! So tell me how to install it already!

Literally a 1-2-3:

sudo gem install mofo
cd rails_app/vendor/plugins
gem unpack mofo

Glenn Gillen

I'm an advisor to, and investor in, early-stage tech startups. Beyond that I'm an incredibly fortunate husband and father. Working on a developer-facing tool or service? Thinking about starting one? Email me and let me know or come to one of our days to help make it a reality.