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 +++++++++++++++++++++++ 3 files changed, 41 insertions(+) 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 (limited to 'app') 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 -- cgit v1.3