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

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Atom rxml template

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

RSS2 rxml template

Some of the rxml RSS 2 templates posted here will work, but have small validation problems. As far as I can tell, this one passes validation every time, given an instance variable @posts, with the appropriate methods. From the source of blinksale.com:

xml.instruct!

xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
  xml.channel do

    xml.title       "Feed Name"
    xml.link        url_for :only_path => false, :controller => 'posts'
    xml.pubDate     CGI.rfc1123_date @posts.first.updated_at if @posts.any?
    xml.description "Feed Description"

    @posts.each do |posts|
      xml.item do
        xml.title       post.name
        xml.link        url_for :only_path => false, :controller => 'posts', :action => 'show', :id => post.id
        xml.description post.body
        xml.pubDate     CGI.rfc1123_date post.updated_at
        xml.guid        url_for :only_path => false, :controller => 'posts', :action => 'show', :id => post.id
        xml.author      "#{post.author.email} (#{post.author.name})"
      end
    end

  end
end
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS