adding rss2.0 feeds

master
Coleman 2008-08-28 22:31:01 -05:00
parent ea98163388
commit 814e089551
7 changed files with 62 additions and 0 deletions

13
app/controllers/feeds.rb Normal file
View File

@ -0,0 +1,13 @@
class Feeds < Application
only_provides :xml
def rss
@items = []
[ Page, Comment ].each do |kls|
@items.concat kls.find(:all, :limit => 25, :order => 'created_at DESC')
end
@items.sort! do |a, b|
b.created_at <=> a.created_at
end
render :format => :xml
end
end

View File

@ -0,0 +1,5 @@
module Merb
module FeedsHelper
end
end # Merb

View File

@ -0,0 +1,26 @@
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title><%= tuxconfig[:site_name] -%></title>
<link><%= absolute_url(:controller => :news, :action => :index) -%></link>
<description><%= tuxconfig[:news_heading] -%></description>
<language>en-us</language>
<% @items.each_with_index do |item, index| -%>
<% break if index >= 25 -%>
<item>
<% if item.is_a? Page -%>
<title><%= item.name -%></title>
<link><%= absolute_url(:page, item.name.gsub(/ /, '_')) -%></link>
<description><%= item.published? ? 'New blog post' : 'New wiki page' -%></description>
<dc:creator><%= item.author.name -%></dc:creator>
<dc:date><%= item.created_at -%></dc:date>
<% elsif item.is_a? Comment -%>
<title>Comment on <%= item.page.name -%></title>
<link><%= absolute_url(:page, item.page.name.gsub(/ /, '_')) -%></link>
<description>new comment by <%= item.name -%>!</description>
<dc:creator><%= item.name -%></dc:creator>
<dc:date><%= item.created_at.to_date -%></dc:date>
<% end -%>
</item>
<% end -%>
</channel>
</rss>

View File

@ -8,6 +8,8 @@
<link rel="stylesheet" href="/stylesheets/application.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="/stylesheets/tuxbliki.css" type="text/css" media="all" charset="utf-8" />
<link rel="alternate" type="application/rss+xml" title="RSS2.0" href="/feeds/rss.xml" />
<script src="/javascripts/prototype.js" type="text/javascript"></script>
<script src="/javascripts/scriptaculous.js" type="text/javascript"></script>
<script src="/javascripts/curvycorners.js" type="text/javascript"></script>

View File

@ -43,4 +43,8 @@ Merb::Router.prepare do |r|
:controller => 'news',
:action => 'index'
)
r.match('/feeds/:action.xml').to(
:controller => 'feeds',
:format => 'xml'
)
end

View File

@ -0,0 +1,7 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
describe Feeds, "index action" do
before(:each) do
dispatch_to(Feeds, :index)
end
end

View File

@ -0,0 +1,5 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
describe Merb::FeedsHelper do
end