From 40e34b3d2aea86f7d1411b10dcda928d7115ad08 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 17 Jul 2009 20:19:31 +0000 Subject: [PATCH] Creating stable branch --- app/controllers/application_controller.rb | 10 ++++++ app/controllers/feed_controller.rb | 38 +++++++++++++++++++++++ app/helpers/application_helper.rb | 3 ++ app/helpers/feed_helper.rb | 2 ++ app/models/feed_item.rb | 21 +++++++++++++ app/views/feed/index.html.erb | 14 +++++++++ app/views/feed/index.rss.builder | 17 ++++++++++ app/views/feed/show.html.erb | 17 ++++++++++ app/views/feed/show.rss.builder | 16 ++++++++++ app/views/feed/update.html.erb | 2 ++ app/views/layouts/application.html.erb | 8 +++++ 11 files changed, 148 insertions(+) create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/feed_controller.rb create mode 100644 app/helpers/application_helper.rb create mode 100644 app/helpers/feed_helper.rb create mode 100644 app/models/feed_item.rb create mode 100644 app/views/feed/index.html.erb create mode 100644 app/views/feed/index.rss.builder create mode 100644 app/views/feed/show.html.erb create mode 100644 app/views/feed/show.rss.builder create mode 100644 app/views/feed/update.html.erb create mode 100644 app/views/layouts/application.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..6635a3f --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,10 @@ +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +class ApplicationController < ActionController::Base + helper :all # include all helpers, all the time + protect_from_forgery # See ActionController::RequestForgeryProtection for details + + # Scrub sensitive parameters from your log + # filter_parameter_logging :password +end diff --git a/app/controllers/feed_controller.rb b/app/controllers/feed_controller.rb new file mode 100644 index 0000000..71ab1df --- /dev/null +++ b/app/controllers/feed_controller.rb @@ -0,0 +1,38 @@ +class FeedController < ApplicationController + + skip_before_filter :verify_authenticity_token + + 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_name], params[:title]) + if item + if params[:description] == '' + item.destroy + else + item.update_attribute(:description, params[:description]) + end + else + FeedItem.create(:feed_name => params[:feed_name], + :title => params[:title], + :description => params[:description]) + end + redirect_to feed_url(params[:feed_name]) + end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..22a7940 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,3 @@ +# Methods added to this helper will be available to all templates in the application. +module ApplicationHelper +end diff --git a/app/helpers/feed_helper.rb b/app/helpers/feed_helper.rb new file mode 100644 index 0000000..6709856 --- /dev/null +++ b/app/helpers/feed_helper.rb @@ -0,0 +1,2 @@ +module FeedHelper +end diff --git a/app/models/feed_item.rb b/app/models/feed_item.rb new file mode 100644 index 0000000..cf01358 --- /dev/null +++ b/app/models/feed_item.rb @@ -0,0 +1,21 @@ +class FeedItem < ActiveRecord::Base + + # require 'cgi' # needed for url decoding + + validates_presence_of :feed_name, :title, :description + validate :feed_name_must_be_legal + +protected + + def feed_name_must_be_legal + 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 + feed_name == 'action' + errors.add(:feed_name, 'is an invalid feed name') + end + end + +end diff --git a/app/views/feed/index.html.erb b/app/views/feed/index.html.erb new file mode 100644 index 0000000..b9e082a --- /dev/null +++ b/app/views/feed/index.html.erb @@ -0,0 +1,14 @@ +

Feeds available

+ +<% form_tag :action => 'update' do %> +

Set feed <%= text_field_tag :feed_name, '', :size => 20 %> + to include <%= text_field_tag :title, '', :size => 30 %> + containing <%= text_field_tag :description, '', :size => 50 %> + <%= submit_tag 'Update' %>

+<% end %> + + \ No newline at end of file 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.html.erb b/app/views/feed/show.html.erb new file mode 100644 index 0000000..2a2b9b1 --- /dev/null +++ b/app/views/feed/show.html.erb @@ -0,0 +1,17 @@ +

Contents of feed <%= h params[:feed_name] %>

+

<%= link_to("List of all feeds", index_url) %>

+ +<% form_tag :action => 'update' do %> +

Set feed <%= text_field_tag :feed_name, h(params[:feed_name]), :size => 20 %> + to include <%= text_field_tag :title, '', :size => 30 %> + containing <%= text_field_tag :description, '', :size => 50 %> + <%= submit_tag 'Update' %>

+<% end %> + + +
+ <% for item in @feed_items %> +
<%= h item.title %>
+
<%= h item.description %>
+ <% 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 diff --git a/app/views/feed/update.html.erb b/app/views/feed/update.html.erb new file mode 100644 index 0000000..96fff67 --- /dev/null +++ b/app/views/feed/update.html.erb @@ -0,0 +1,2 @@ +

Feed#update

+

Find me in app/views/feed/update.html.erb

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..ee2975d --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,8 @@ + + + Feedcatcher + + + <%= yield :layout %> + + -- 2.34.1