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.

xml.instruct!

xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do

  xml.title   "Feed Name"
  xml.link    "rel" => "self", "href" => url_for(:only_path => false, :controller => 'feeds', :action => 'atom')
  xml.link    "rel" => "alternate", "href" => url_for(:only_path => false, :controller => 'posts')
  xml.id      url_for(:only_path => false, :controller => 'posts')
  xml.updated @posts.first.updated_at.strftime "%Y-%m-%dT%H:%M:%SZ" if @posts.any?
  xml.author  { xml.name "Author Name" }

  @posts.each do |post|
    xml.entry do
      xml.title   post.title
      xml.link    "rel" => "alternate", "href" => url_for(:only_path => false, :controller => 'posts', :action => 'show', :id => post.id)
      xml.id      url_for(:only_path => false, :controller => 'posts', :action => 'show', :id => post.id)
      xml.updated post.updated_at.strftime "%Y-%m-%dT%H:%M:%SZ"
      xml.author  { xml.name post.author.name }
      xml.summary "Post summary"
      xml.content "type" => "html" do
        xml.text! render(:partial => "posts/post", :post => post)
      end
    end
  end

end

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


Click here to browse all 4861 code snippets

Related Posts