summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-09-10 16:01:41 +0200
committerhukl <contact@smyck.org>2009-09-10 16:01:41 +0200
commitd7ec763c7ce069824aad24a6bd0d845ee74ed10d (patch)
tree5def39dc36d468d190a072db2a089b7e8f12bd6a
parent304ba222fb85178763746ded4c1d252124c9ddfd (diff)
added public rss controller plus template to render the latest 20 updates into a neat little atom feed
-rw-r--r--app/controllers/rss_controller.rb16
-rw-r--r--app/helpers/rss_helper.rb2
-rw-r--r--app/views/rss/updates.xml.builder23
-rw-r--r--config/initializers/xmlparser.rb8
-rw-r--r--config/routes.rb3
-rw-r--r--test/functional/rss_controller_test.rb8
-rw-r--r--test/unit/helpers/rss_helper_test.rb4
-rw-r--r--vendor/plugins/acts_as_taggable_redux/lib/acts_as_taggable.rb5
8 files changed, 67 insertions, 2 deletions
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 @@
1class RssController < ApplicationController
2
3 def updates
4
5 @items = Page.heads.find_tagged_with(
6 "update",
7 :order => "published_at DESC",
8 :limit => 20
9 )
10
11 respond_to do |format|
12 format.xml {}
13 end
14 end
15
16end
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 @@
1module RssHelper
2end
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 @@
1xml.instruct!
2xml.feed(:xmlns => "http://www.w3.org/2005/Atom") do
3 xml.title("Chaos Computer Club Updates")
4 xml.link(:href => "http://www.ccc.de/")
5 xml.updated(@items.first.published_at)
6 xml.author("Chaos Computer Club e.V.")
7 xml.id("http://www.ccc.de/")
8
9 @items.each do |item|
10 xml.entry do
11 xml.title(item.title)
12 port = (request.port != 80) ? port = ":#{request.port}" : ""
13 xml.link(request.protocol + request.host + port + item.public_link)
14 xml.id(request.protocol + request.host + port + item.public_link)
15 xml.updated(item.updated_at)
16 xml.content(:type => "xhtml") do
17 xml.div(item.body, :xmlns => "http://www.w3.org/1999/xhtml")
18 end
19 end
20
21 end
22
23end \ 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
3 self.next = other 3 self.next = other
4 remove! 4 remove!
5 end 5 end
6end
7
8module Builder
9 class XmlBase
10 def _escape(text)
11 text
12 end
13 end
6end \ No newline at end of file 14end \ 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|
23 map.resources :menu_items, :member => {:sort => :post} 23 map.resources :menu_items, :member => {:sort => :post}
24 map.resource :session 24 map.resource :session
25 25
26 map.rss 'rss/:action', :controller => 'rss'
27 map.rss 'rss/:action.:format', :controller => 'rss'
28
26 map.connect ':controller/:action/:id' 29 map.connect ':controller/:action/:id'
27 map.connect ':controller/:action/:id.:format' 30 map.connect ':controller/:action/:id.:format'
28 31
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 @@
1require 'test_helper'
2
3class RssControllerTest < ActionController::TestCase
4 # Replace this with your real tests.
5 test "the truth" do
6 assert true
7 end
8end
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 @@
1require 'test_helper'
2
3class RssHelperTest < ActionView::TestCase
4end
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
30 end 30 end
31 31
32 def tagged_with_scope(tags, options={}) 32 def tagged_with_scope(tags, options={})
33 options.assert_valid_keys([:match, :order, :user]) 33 options.assert_valid_keys([:match, :order, :user, :limit])
34 34
35 tags = Tag.parse(tags) 35 tags = Tag.parse(tags)
36 return [] if tags.empty? 36 return [] if tags.empty?
@@ -44,7 +44,8 @@ module ActiveRecord
44 "LEFT OUTER JOIN #{Tag.table_name} #{table_name}_tags ON #{table_name}_tags.id = #{table_name}_taggings.tag_id", 44 "LEFT OUTER JOIN #{Tag.table_name} #{table_name}_tags ON #{table_name}_tags.id = #{table_name}_taggings.tag_id",
45 :conditions => conditions, 45 :conditions => conditions,
46 :group => group, 46 :group => group,
47 :order => options[:order] 47 :order => options[:order],
48 :limit => options[:limit]
48 } 49 }
49 50
50 with_scope(:find => find_parameters) { yield } 51 with_scope(:find => find_parameters) { yield }