Created
December 2, 2013 19:41
-
-
Save facerip/7756469 to your computer and use it in GitHub Desktop.
Simple RSS Feed in Sinatra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'data_mapper' | |
require 'builder' | |
class ExitStatusOne < Sinatra::Base | |
get '/rss' do | |
@post = Post.all :order => :id.desc | |
builder :rss | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xml.instruct! :xml, :version => '1.0' | |
xml.rss :version => "2.0" do | |
xml.channel do | |
xml.title "Title of Feed" | |
xml.description "Description of Site" | |
xml.link "web-site-url.com" | |
@post.each do |feed| | |
xml.item do | |
xml.title feed.title | |
xml.link "web-site-url.com/path/to/rss/feed/#{feed.id}" | |
xml.description feed.summary | |
xml.pubDate feed.created_at | |
xml.guid "web-site-url.com/path/to/rss/feed/#{feed.id}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment