public
Description: RSS/Atom feeds aggregator, powered by Ramaze. Using Sequel for ORM.
Homepage: http://planet.zhekov.net/
Clone URL: git://github.com/zh/tamanegi.git
Click here to lend your support to: tamanegi and make a donation at www.pledgie.com !
use ratom instead of xml builder for the feed
zh (author)
Mon Apr 21 01:11:12 -0700 2008
commit  2271cf81d71646cce8fc4878e409b35a053ffb2a
tree    4c2f93d339a763be0b8694ae86262caa21df2d85
parent  0ab63fe76c1b793f285993d46c1bb28246de3958
...
2
3
4
 
 
 
5
6
7
...
2
3
4
5
6
7
8
9
10
0
@@ -2,6 +2,9 @@ Configuration.for('app') {
0
   version '0.0.7'
0
   title 'Tamanegi - The state of the Onion'
0
   base_url 'http://localhost:7000'
0
+ author {
0
+ name 'Stoyan Zhekov'
0
+ }
0
   one_page 20
0
   rss_page 20
0
   giveup 10
...
1
 
2
3
4
...
20
21
22
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
25
26
...
 
1
2
3
4
...
20
21
22
 
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
0
@@ -1,4 +1,4 @@
0
-require 'builder'
0
+require 'atom/pub'
0
 
0
 class ItemController < Ramaze::Controller
0
   map '/'
0
@@ -20,7 +20,23 @@ class ItemController < Ramaze::Controller
0
 
0
   # TODO: provide :atom, :json, :xml etc. helper
0
   def atom
0
- @items = Item.order(:created.DESC).limit(Configuration.for('app').rss_page)
0
+ cfg = Configuration.for('app')
0
+ @items = Item.order(:created.DESC).limit(cfg.rss_page)
0
+ @feed = Atom::Feed.new do |feed|
0
+ feed.title = cfg.title
0
+ feed.id = "#{cfg.base_url}/"
0
+ feed.updated = Item.order(:id).last.created.iso8601
0
+ feed.links << Atom::Link.new(:rel=>"self",
0
+ :href=>"#{cfg.base_url}/atom",
0
+ :type=>"application/atom+xml")
0
+ feed.links << Atom::Link.new(:rel => 'alternate',
0
+ :href => "#{cfg.base_url}/")
0
+
0
+ @items.each do |item|
0
+ feed.entries << item.to_atom
0
+ end
0
+ end
0
+ respond @feed.to_xml
0
   end
0
 
0
 private
...
 
 
1
2
3
...
23
24
25
 
 
 
 
 
 
 
 
 
 
 
 
 
26
27
28
...
1
2
3
4
5
...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
0
@@ -1,3 +1,5 @@
0
+require 'atom/pub'
0
+
0
 class Item < Sequel::Model(:items)
0
   set_schema do
0
     primary_key :id
0
@@ -23,6 +25,19 @@ class Item < Sequel::Model(:items)
0
     set(:created => Time.now)
0
   end
0
 
0
+ def to_atom
0
+ cfg = Configuration.for('app')
0
+ Atom::Entry.new do |e|
0
+ e.id = "#{cfg.base_url}/show/#{self.id}"
0
+ e.title = self.title
0
+ e.updated = self.created
0
+ e.published = self.created
0
+ # e.authors << Atom::Person.new(:name => cfg.author.name)
0
+ e.links << Atom::Link.new(:rel => 'alternative', :href => "#{cfg.base_url}/show/#{self.id}")
0
+ e.content = Atom::Content::Html.new(self.description)
0
+ end
0
+ end
0
+
0
 end
0
 
0
 Item.create_table unless Item.table_exists?
...
2
3
4
5
 
...
2
3
4
 
5
0
@@ -2,4 +2,4 @@
0
 
0
 require 'tamanegi'
0
 
0
-Ramaze.start :adapter => :thin, :port => 7000, :load_engines => :Builder
0
+Ramaze.start :adapter => :thin, :port => 7000
...
7
8
9
 
10
11
12
...
7
8
9
10
11
12
13
0
@@ -7,6 +7,7 @@ require 'rubygems'
0
 require 'sequel'
0
 require 'validatable'
0
 require 'ramaze'
0
+require 'actionpack'
0
 
0
 DB_FILE = File.join(File.dirname(__FILE__),"db","tamanegi.db")
0
 DB = Sequel("sqlite:///#{DB_FILE}", :single_threaded => true)

Comments

    No one has commented yet.