rss_feed.rb
1.89 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class RssFeed < Article
# store setting in body
serialize Hash, :body
def body
self[:body] ||= {}
end
alias :settings :body
def limit
settings[:limit]
end
def limit=(value)
settings[:limit] = value
end
def include
settings[:include]
end
def include=(value)
settings[:include] = value
end
def feed_item_description
settings[:feed_item_description]
end
def feed_item_description=(value)
settings[:feed_item_description] = value
end
# TODO
def to_html
end
# RSS feeds have type =text/xml=.
def mime_type
'text/xml'
end
# FIXME feed real data into the RSS feed
def data
articles =
if (self.include == :parent_and_children) && self.parent
self.parent.map_traversal
else
profile.recent_documents(self.limit || 10)
end
result = ""
xml = Builder::XmlMarkup.new(:target => result)
xml.instruct! :xml, :version=>"1.0"
xml.rss(:version=>"2.0") do
xml.channel do
xml.title(_("%s's RSS feed") % (self.profile.name))
xml.link("http://www.yourDomain.com")
xml.description('Description here')
xml.language("pt_BR")
for article in articles
unless self == article
xml.item do
xml.title(article.name)
if self.feed_item_description == :body
xml.description(article.body)
else
xml.description(article.abstract)
end
# rfc822
xml.pubDate(article.created_on.rfc2822)
xml.link("http://www.yourDomain.com/linkToYourPost")
xml.guid("http://www.yourDomain.com/linkToYourPost")
end
end
end
end
end
result
end
def self.short_description
_('RSS Feed')
end
def self.description
_('Provides a news feed of your more recent articles.')
end
end