Permalink
Browse files

Add RSS feed.

  • Loading branch information...
1 parent 4b42afd commit a457e432c4ecf5516f5c0021818a43a7a5d6b514 @spraints committed Mar 1, 2011
@@ -9,4 +9,8 @@ def current
now = Time.now
redirect_to edition_path(now.year, now.month)
end
+
+ def feed
+ @stories = Story.for_feed
+ end
end
View
@@ -6,6 +6,7 @@ class Story < ActiveRecord::Base
serialize :paragraphs, Array
scope :for_edition, lambda { |date| where(:edition => date.strftime('%Y-%m')) }
+ scope :for_feed, order('created_at desc').limit(10)
def content_for_edit
(self.paragraphs || []).join("\n\n")
@@ -14,4 +15,12 @@ def content_for_edit
def content_for_edit=(content)
self.paragraphs = content && content.split(/\n\s*\n/)
end
+
+ def year
+ self.edition.split(/-/)[0]
+ end
+
+ def month
+ self.edition.split(/-/)[1]
+ end
end
@@ -0,0 +1,20 @@
+!!! XML
+%rss{:version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom'}
+ %channel
+ %title Latest news from Pickard Ayune
+ %description Latest news from Pickard Ayune
+ %link= root_url
+ %atom:link{:rel => 'self', :href => news_url(:rss)}
+ -@stories.each do |story|
+ %item
+ %title
+ = story.title
+ %description
+ - story.paragraphs.each do |p|
+ =h "<p>#{p.html_safe}</p>"
+ %guid
+ == http://pickardayune.com/stories/#{story.id}
+ %pubDate
+ = story.created_at.to_s(:rfc822)
+ %link
+ = edition_url(story.year, story.month)
@@ -6,6 +6,8 @@
= @date
=stylesheet_link_tag :all
=javascript_include_tag :defaults
+ -[:rss, :atom].each do |format|
+ =auto_discovery_link_tag format, news_url(format)
- if Rails.env.production?
%script{:src => 'http://search.twitter.com/search.json?q=%23pickard&callback=showtweets'}
- else
View
@@ -1,5 +1,6 @@
Pickardayune::Application.routes.draw do
match ":year/:month", :to => 'edition#index', :as => :edition, :constraints => {:year => /\d{4}/, :month => /\d{1,2}/}
+ match "news.:format", :to => 'edition#feed', :as => :news
get "edition/index"
root :to => "edition#current"
end

0 comments on commit a457e43

Please sign in to comment.