Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Atom rxml template (See related posts)

This rxml template (modified from the one in blinksale.com) generates valid Atom 1.0 feeds. If you have a partial to create HTML for each item, they can be included in the feed's "content" elements.

   1  
   2  xml.instruct!
   3  
   4  xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
   5  
   6    xml.title   "Feed Name"
   7    xml.link    "rel" => "self", "href" => url_for(:only_path => false, :controller => 'feeds', :action => 'atom')
   8    xml.link    "rel" => "alternate", "href" => url_for(:only_path => false, :controller => 'posts')
   9    xml.id      url_for(:only_path => false, :controller => 'posts')
  10    xml.updated @posts.first.updated_at.strftime "%Y-%m-%dT%H:%M:%SZ" if @posts.any?
  11    xml.author  { xml.name "Author Name" }
  12  
  13    @posts.each do |post|
  14      xml.entry do
  15        xml.title   post.title
  16        xml.link    "rel" => "alternate", "href" => url_for(:only_path => false, :controller => 'posts', :action => 'show', :id => post.id)
  17        xml.id      url_for(:only_path => false, :controller => 'posts', :action => 'show', :id => post.id)
  18        xml.updated post.updated_at.strftime "%Y-%m-%dT%H:%M:%SZ"
  19        xml.author  { xml.name post.author.name }
  20        xml.summary "Post summary"
  21        xml.content "type" => "html" do
  22          xml.text! render(:partial => "posts/post", :post => post)
  23        end
  24      end
  25    end
  26  
  27  end

You need to create an account or log in to post comments to this site.


Click here to browse all 5829 code snippets

Related Posts