From 814e0895517a78406b5782a4cf9be02799374e79 Mon Sep 17 00:00:00 2001 From: Coleman Date: Thu, 28 Aug 2008 22:31:01 -0500 Subject: [PATCH] adding rss2.0 feeds --- app/controllers/feeds.rb | 13 +++++++++++++ app/helpers/feeds_helper.rb | 5 +++++ app/views/feeds/rss.xml.erb | 26 ++++++++++++++++++++++++++ app/views/layout/application.html.erb | 2 ++ config/router.rb | 4 ++++ spec/controllers/feeds_spec.rb | 7 +++++++ spec/helpers/feeds_helper_spec.rb | 5 +++++ 7 files changed, 62 insertions(+) create mode 100644 app/controllers/feeds.rb create mode 100644 app/helpers/feeds_helper.rb create mode 100644 app/views/feeds/rss.xml.erb create mode 100644 spec/controllers/feeds_spec.rb create mode 100644 spec/helpers/feeds_helper_spec.rb diff --git a/app/controllers/feeds.rb b/app/controllers/feeds.rb new file mode 100644 index 0000000..94eb908 --- /dev/null +++ b/app/controllers/feeds.rb @@ -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 diff --git a/app/helpers/feeds_helper.rb b/app/helpers/feeds_helper.rb new file mode 100644 index 0000000..5a25ad6 --- /dev/null +++ b/app/helpers/feeds_helper.rb @@ -0,0 +1,5 @@ +module Merb + module FeedsHelper + + end +end # Merb \ No newline at end of file diff --git a/app/views/feeds/rss.xml.erb b/app/views/feeds/rss.xml.erb new file mode 100644 index 0000000..34b5689 --- /dev/null +++ b/app/views/feeds/rss.xml.erb @@ -0,0 +1,26 @@ + + + <%= tuxconfig[:site_name] -%> + <%= absolute_url(:controller => :news, :action => :index) -%> + <%= tuxconfig[:news_heading] -%> + en-us +<% @items.each_with_index do |item, index| -%> +<% break if index >= 25 -%> + +<% if item.is_a? Page -%> + <%= item.name -%> + <%= absolute_url(:page, item.name.gsub(/ /, '_')) -%> + <%= item.published? ? 'New blog post' : 'New wiki page' -%> + <%= item.author.name -%> + <%= item.created_at -%> +<% elsif item.is_a? Comment -%> + Comment on <%= item.page.name -%> + <%= absolute_url(:page, item.page.name.gsub(/ /, '_')) -%> + new comment by <%= item.name -%>! + <%= item.name -%> + <%= item.created_at.to_date -%> +<% end -%> + +<% end -%> + + diff --git a/app/views/layout/application.html.erb b/app/views/layout/application.html.erb index 41212b3..7835ee0 100644 --- a/app/views/layout/application.html.erb +++ b/app/views/layout/application.html.erb @@ -8,6 +8,8 @@ + + diff --git a/config/router.rb b/config/router.rb index 3ccd353..f1a63e1 100644 --- a/config/router.rb +++ b/config/router.rb @@ -43,4 +43,8 @@ Merb::Router.prepare do |r| :controller => 'news', :action => 'index' ) + r.match('/feeds/:action.xml').to( + :controller => 'feeds', + :format => 'xml' + ) end diff --git a/spec/controllers/feeds_spec.rb b/spec/controllers/feeds_spec.rb new file mode 100644 index 0000000..fceb9a2 --- /dev/null +++ b/spec/controllers/feeds_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/helpers/feeds_helper_spec.rb b/spec/helpers/feeds_helper_spec.rb new file mode 100644 index 0000000..364f07b --- /dev/null +++ b/spec/helpers/feeds_helper_spec.rb @@ -0,0 +1,5 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb') + +describe Merb::FeedsHelper do + +end \ No newline at end of file