From d7ec763c7ce069824aad24a6bd0d845ee74ed10d Mon Sep 17 00:00:00 2001 From: hukl Date: Thu, 10 Sep 2009 16:01:41 +0200 Subject: added public rss controller plus template to render the latest 20 updates into a neat little atom feed --- app/controllers/rss_controller.rb | 16 +++++++++++++++ app/helpers/rss_helper.rb | 2 ++ app/views/rss/updates.xml.builder | 23 ++++++++++++++++++++++ config/initializers/xmlparser.rb | 8 ++++++++ config/routes.rb | 3 +++ test/functional/rss_controller_test.rb | 8 ++++++++ test/unit/helpers/rss_helper_test.rb | 4 ++++ .../acts_as_taggable_redux/lib/acts_as_taggable.rb | 5 +++-- 8 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 app/controllers/rss_controller.rb create mode 100644 app/helpers/rss_helper.rb create mode 100644 app/views/rss/updates.xml.builder create mode 100644 test/functional/rss_controller_test.rb create mode 100644 test/unit/helpers/rss_helper_test.rb diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb new file mode 100644 index 0000000..d2540d0 --- /dev/null +++ b/app/controllers/rss_controller.rb @@ -0,0 +1,16 @@ +class RssController < ApplicationController + + def updates + + @items = Page.heads.find_tagged_with( + "update", + :order => "published_at DESC", + :limit => 20 + ) + + respond_to do |format| + format.xml {} + end + end + +end diff --git a/app/helpers/rss_helper.rb b/app/helpers/rss_helper.rb new file mode 100644 index 0000000..9031e55 --- /dev/null +++ b/app/helpers/rss_helper.rb @@ -0,0 +1,2 @@ +module RssHelper +end diff --git a/app/views/rss/updates.xml.builder b/app/views/rss/updates.xml.builder new file mode 100644 index 0000000..541ad4e --- /dev/null +++ b/app/views/rss/updates.xml.builder @@ -0,0 +1,23 @@ +xml.instruct! +xml.feed(:xmlns => "http://www.w3.org/2005/Atom") do + xml.title("Chaos Computer Club Updates") + xml.link(:href => "http://www.ccc.de/") + xml.updated(@items.first.published_at) + xml.author("Chaos Computer Club e.V.") + xml.id("http://www.ccc.de/") + + @items.each do |item| + xml.entry do + xml.title(item.title) + port = (request.port != 80) ? port = ":#{request.port}" : "" + xml.link(request.protocol + request.host + port + item.public_link) + xml.id(request.protocol + request.host + port + item.public_link) + xml.updated(item.updated_at) + xml.content(:type => "xhtml") do + xml.div(item.body, :xmlns => "http://www.w3.org/1999/xhtml") + end + end + + end + +end \ No newline at end of file diff --git a/config/initializers/xmlparser.rb b/config/initializers/xmlparser.rb index ba8660a..9c3f1c8 100644 --- a/config/initializers/xmlparser.rb +++ b/config/initializers/xmlparser.rb @@ -3,4 +3,12 @@ class XML::Node self.next = other remove! end +end + +module Builder + class XmlBase + def _escape(text) + text + end + end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1706dad..d591619 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,6 +23,9 @@ ActionController::Routing::Routes.draw do |map| map.resources :menu_items, :member => {:sort => :post} map.resource :session + map.rss 'rss/:action', :controller => 'rss' + map.rss 'rss/:action.:format', :controller => 'rss' + map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' diff --git a/test/functional/rss_controller_test.rb b/test/functional/rss_controller_test.rb new file mode 100644 index 0000000..161dbd7 --- /dev/null +++ b/test/functional/rss_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class RssControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/helpers/rss_helper_test.rb b/test/unit/helpers/rss_helper_test.rb new file mode 100644 index 0000000..b040b3e --- /dev/null +++ b/test/unit/helpers/rss_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class RssHelperTest < ActionView::TestCase +end diff --git a/vendor/plugins/acts_as_taggable_redux/lib/acts_as_taggable.rb b/vendor/plugins/acts_as_taggable_redux/lib/acts_as_taggable.rb index 6b5e8b9..e070d2b 100644 --- a/vendor/plugins/acts_as_taggable_redux/lib/acts_as_taggable.rb +++ b/vendor/plugins/acts_as_taggable_redux/lib/acts_as_taggable.rb @@ -30,7 +30,7 @@ module ActiveRecord end def tagged_with_scope(tags, options={}) - options.assert_valid_keys([:match, :order, :user]) + options.assert_valid_keys([:match, :order, :user, :limit]) tags = Tag.parse(tags) return [] if tags.empty? @@ -44,7 +44,8 @@ module ActiveRecord "LEFT OUTER JOIN #{Tag.table_name} #{table_name}_tags ON #{table_name}_tags.id = #{table_name}_taggings.tag_id", :conditions => conditions, :group => group, - :order => options[:order] + :order => options[:order], + :limit => options[:limit] } with_scope(:find => find_parameters) { yield } -- cgit v1.3