From: Neil Smith Date: Fri, 17 Jul 2009 15:42:41 +0000 (+0000) Subject: Updates and RSS generation done X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=73ebfcfd8bdc389269ab4522a8cfc2486c32978e;p=feedcatcher.git Updates and RSS generation done --- diff --git a/app/controllers/feed_controller.rb b/app/controllers/feed_controller.rb index 7fa4e28..2eddc8c 100644 --- a/app/controllers/feed_controller.rb +++ b/app/controllers/feed_controller.rb @@ -1,13 +1,33 @@ class FeedController < ApplicationController def index @feeds = FeedItem.find(:all, :select => 'DISTINCT feed_name') + respond_to do |format| + format.html + format.rss { render :layout => false } + end end def show @feed_items = FeedItem.find_all_by_feed_name(params[:feed_name]) + redirect_to index_url if @feed_items == [] + respond_to do |format| + format.html + format.rss { render :layout => false } + end end def update + item = FeedItem.find_by_feed_name_and_title(params[:feed_item][:feed_name], params[:feed_item][:title]) + if item + if params[:feed_item][:description] == '' + item.destroy + else + item.update_attribute(:description, params[:feed_item][:description]) + end + else + FeedItem.create(params[:feed_item]) + end + redirect_to feed_url(params[:feed_item][:feed_name]) end end diff --git a/app/models/feed_item.rb b/app/models/feed_item.rb index ce5b8c6..cf01358 100644 --- a/app/models/feed_item.rb +++ b/app/models/feed_item.rb @@ -1,6 +1,6 @@ class FeedItem < ActiveRecord::Base - require 'cgi' # needed for url decoding + # require 'cgi' # needed for url decoding validates_presence_of :feed_name, :title, :description validate :feed_name_must_be_legal @@ -8,8 +8,8 @@ class FeedItem < ActiveRecord::Base protected def feed_name_must_be_legal - if url_encode(feed_name) != feed_name or - CGI::unescape(feed_name) != feed_name or + if Rack::Utils::escape(feed_name) != feed_name or + Rack::Utils::unescape(feed_name) != feed_name or feed_name == 'index' or feed_name == 'show' or feed_name == 'update' or diff --git a/app/views/feed/index.rss.builder b/app/views/feed/index.rss.builder new file mode 100644 index 0000000..93ce050 --- /dev/null +++ b/app/views/feed/index.rss.builder @@ -0,0 +1,17 @@ +# index.rss.builder +xml.instruct! :xml, :version => "1.0" +xml.rss :version => "2.0" do + xml.channel do + xml.title "Feedcatcher" + xml.description "Feeds available" + xml.link index_url(:rss) + + for feed in @feeds + xml.item do + xml.title feed.feed_name + xml.link feed_url(feed.feed_name, :rss) + xml.guid feed_url(feed.feed_name, :rss) + end + end + end +end diff --git a/app/views/feed/show.rss.builder b/app/views/feed/show.rss.builder new file mode 100644 index 0000000..522b662 --- /dev/null +++ b/app/views/feed/show.rss.builder @@ -0,0 +1,16 @@ +# index.rss.builder +xml.instruct! :xml, :version => "1.0" +xml.rss :version => "2.0" do + xml.channel do + xml.title @feed_items[0].feed_name + xml.link feed_url(@feed_items[0].feed_name, :rss) + + for item in @feed_items + xml.item do + xml.title item.title + xml.description item.description + xml.guid item.id, :isPermaLink => 'false' + end + end + end +end