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

About this user

Scott Raymond http://redgreenblu.com/

« 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.

   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

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:

   1  
   2  xml.instruct!
   3  
   4  xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
   5    xml.channel do
   6  
   7      xml.title       "Feed Name"
   8      xml.link        url_for :only_path => false, :controller => 'posts'
   9      xml.pubDate     CGI.rfc1123_date @posts.first.updated_at if @posts.any?
  10      xml.description "Feed Description"
  11  
  12      @posts.each do |posts|
  13        xml.item do
  14          xml.title       post.name
  15          xml.link        url_for :only_path => false, :controller => 'posts', :action => 'show', :id => post.id
  16          xml.description post.body
  17          xml.pubDate     CGI.rfc1123_date post.updated_at
  18          xml.guid        url_for :only_path => false, :controller => 'posts', :action => 'show', :id => post.id
  19          xml.author      "#{post.author.email} (#{post.author.name})"
  20        end
  21      end
  22  
  23    end
  24  end
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS