-
Notifications
You must be signed in to change notification settings - Fork 1
/
rss.rb
44 lines (43 loc) · 1.26 KB
/
rss.rb
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
require 'erb'
class RSS
def self.make(hash)
[:title, :description, :link, :items].each do |x|
raise unless hash[x]
end
template = <<EOF # {{{
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<channel>
<title><%= hash[:title] %></title>
<link><%= hash[:link] %></link>
<description><%= hash[:description] %></description>
<% hash[:items].each do |item| %>
<item>
<title><%= item[:title] %></title>
<link><%= item[:link] %></link>
<description><%= item[:description] %></description>
<pubDate><%= item[:date] %></pubDate>
<dc:date><%= item[:date] %></dc:date>
</item>
<% end %>
</channel>
</rss>
EOF
# }}}
ERB.new(template).result(binding)
end
end
if $0 == __FILE__
hashes = []
rss = RSS.make(
:title => "Recent Commits to livecoding6:master with Diff",
:description => "Recent Commits to livecoding6:master with Diff",
:link => "http://ujihisa.github.com/livecoding6/",
:items => hashes)
puts rss
end
# vim: foldmethod=marker