public
Description: A 'planet' like feed aggregator using feedparser and erubis
Clone URL: git://github.com/technicalpickles/feedbarn.git
Farmer is now more of a controller type thing.
Fri Feb 22 09:21:32 -0800 2008
commit  11a63d4b8b9abf70d0e4d8efbf59c6a8b72a540d
tree    a61b447340b14b0730881a0ec74e7447872987f1
parent  6f4ccc47d5d60856015fc915723670eb79c82699
...
5
6
7
8
9
10
 
 
 
 
 
 
 
11
12
13
...
5
6
7
 
 
 
8
9
10
11
12
13
14
15
16
17
0
@@ -5,9 +5,13 @@ $:.unshift File.dirname(__FILE__) + '/../lib'
0
 require 'feedbarn'
0
 
0
 farmer = FeedBarn::Farmer.new
0
-feeds = farmer.gather
0
-barn = FeedBarn::Barn.new('My barn', feeds)
0
-view = FeedBarn::View.new(barn)
0
+# feeds = farmer.gather
0
+
0
+barn = farmer.build 'my-barn'
0
+
0
+farmer.fill barn
0
+
0
+view = farmer.showcase barn
0
 
0
 Dir.mkdir('output') unless File.exists?('output')
0
 open('output/index.html', 'w') do |file|
...
1
2
3
 
4
5
 
6
7
 
8
9
10
...
15
16
17
 
 
 
 
 
 
 
 
18
19
20
...
1
2
 
3
4
 
5
6
 
7
8
9
10
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -1,10 +1,10 @@
0
 module FeedBarn
0
   class Barn
0
- attr_accessor :name, :feeds
0
+ attr_accessor :name, :config, :feeds
0
     
0
- def initialize(name, feeds)
0
+ def initialize(name, config)
0
       self.name = name
0
- self.feeds = feeds
0
+ self.config = config
0
     end
0
     
0
     def entries
0
@@ -15,6 +15,14 @@ module FeedBarn
0
       @entries
0
     end
0
     
0
+ def title
0
+ config['title']
0
+ end
0
+
0
+ def urls
0
+ config['feeds'].collect {|feed| feed['url']}
0
+ end
0
+
0
     private
0
     
0
     def sort_entries!
...
4
5
6
 
7
8
9
10
 
11
12
13
 
 
14
15
16
...
19
20
21
22
23
 
 
 
 
 
 
 
 
 
24
25
 
26
27
28
 
29
30
31
 
 
 
 
 
 
 
 
 
 
32
33
34
35
...
4
5
6
7
8
9
10
 
11
12
13
 
14
15
16
17
18
...
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
49
50
51
52
53
0
@@ -4,13 +4,15 @@ require 'open-uri'
0
 require 'yaml'
0
 
0
 module FeedBarn
0
+ # The gatherer of feeds, builder of barns
0
   class Farmer
0
     CONFIG = 'config/feeds.yaml'
0
     
0
- attr_accessor :feeds, :config
0
+ attr_accessor :config, :barns
0
     
0
     def initialize()
0
- self.config = YAML.load_file('config/feeds.yaml')
0
+ self.config = YAML.load_file('config/settings.yml')
0
+ self.barns = {}
0
     end
0
     
0
     def feed_urls
0
@@ -19,16 +21,32 @@ module FeedBarn
0
       }
0
     end
0
     
0
- def gather
0
- self.feeds = []
0
+ def build barn_name
0
+ barn_config = load_config_for barn_name
0
+ barns[barn_config['title']] = Barn.new(barn_name, barn_config)
0
+ end
0
+
0
+
0
+
0
+ def fill barn
0
+ barn.feeds = []
0
 
0
- self.config['feeds'].each do |feed_config|
0
+ load_config_for(barn.name)['feeds'].each do |feed_config|
0
         url = feed_config['url']
0
         downloaded_feed = FeedNormalizer::FeedNormalizer.parse(open(url))
0
- feeds << Feed.new(downloaded_feed, feed_config)
0
+ barn.feeds << Feed.new(downloaded_feed, feed_config)
0
       end
0
        
0
- self.feeds
0
+ barn.feeds
0
+ end
0
+
0
+ def showcase barn
0
+ FeedBarn::View.new(barn)
0
+ end
0
+
0
+ private
0
+ def load_config_for barn_name
0
+ YAML.load_file("config/#{barn_name}.yml")
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
1
2
3
 
4
5
6
7
8
 
9
10
11
...
1
2
 
3
4
5
6
7
 
8
9
10
11
0
@@ -1,11 +1,11 @@
0
 <html>
0
   <head>
0
- <title><%= barn.name %></title>
0
+ <title><%= barn.title %></title>
0
   </head>
0
   <body>
0
     <div id="container">
0
       <div id="header">
0
- <h1><%= barn.name %></h1>
0
+ <h1><%= barn.title %></h1>
0
       </div>
0
       <div id="content" class="hfeed">
0
         <% barn.entries.each do |entry| %>

Comments

    No one has commented yet.