public
Description: Small application that lets you generate an rss feed for any page
Clone URL: git://github.com/jduff/rssanything.git
John Duff (author)
Tue May 06 19:17:17 -0700 2008
commit  843f956261fcafbe7b31e2d410b508edc5c7a6ca
tree    60c7e6d3bee6ef5e2d1eb9c1a9da7209e7e845f1
parent  010b57b781574aae07806c199b7fd28b4be37d46
rssanything / app / controllers / feeds_controller.rb
100644 48 lines (29 sloc) 1.179 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class FeedsController < ApplicationController
  
  def index
    @feeds = Feed.find(:all)
  end
  
  def new
    pp params
    
    feed = Feed.new(:title => params[:url].gsub('[', '[@'), :link => params[:url].gsub('[', '[@'),
            :link_regexp => params[:link].gsub('[', '[@'), :title_regexp => params[:title].gsub('[', '[@'),
            :content_regexp => params[:content].gsub('[', '[@'))
            
    feed.save!
    
    redirect_to :action => :show, :id => feed.id
  end
  
  def show
    @feed = Feed.find_by_id(params[:id])
    
    parsed_items = @feed.execute
 
    existing_items = Item.find(:all,
      :conditions => ["feed_id =? and guid in (?)", @feed.id, parsed_items.collect(&:guid)])
 
 
    existing_items.collect!(&:guid) unless existing_items.empty?
 
    new_items = parsed_items.reject {|item| existing_items.include?(item.guid)}
 
    @feed.items << new_items unless new_items.empty?
 
    @feed.last_published = Time.now
 
    @feed.save unless new_items.empty?
    
    @items = Item.find(:all, :conditions => ["feed_id = ?", @feed.id],
      :order => "created_at DESC")
    
    respond_to do |format|
      format.xml
    end
  end
  
  
end