siuying-rssbook 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rssbook.rb +54 -12
- data/rssbook.gemspec +6 -2
- data/test/feeds/feed1.xml +173 -0
- data/test/feeds/feed2.xml +638 -0
- data/test/rss_test.rb +31 -0
- metadata +15 -2
data/lib/rssbook.rb
CHANGED
@@ -5,12 +5,14 @@ require "rubygems"
|
|
5
5
|
require "prawn"
|
6
6
|
require 'iconv'
|
7
7
|
require 'logger'
|
8
|
-
require '
|
8
|
+
require 'feed-normalizer'
|
9
9
|
require 'open-uri'
|
10
|
+
require 'hpricot'
|
10
11
|
require "prawn/measurement_extensions"
|
12
|
+
require 'prawn/format'
|
11
13
|
|
12
14
|
module RSSBook
|
13
|
-
VERSION = '0.
|
15
|
+
VERSION = '0.2.0'
|
14
16
|
|
15
17
|
class Renderer
|
16
18
|
def initialize(input, output, font = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf",
|
@@ -22,39 +24,79 @@ module RSSBook
|
|
22
24
|
@log = Logger.new($STDOUT)
|
23
25
|
|
24
26
|
puts "input: #{input}, output: #{output}"
|
25
|
-
|
27
|
+
|
28
|
+
@feed = FeedNormalizer::FeedNormalizer.parse open(input)
|
26
29
|
end
|
27
30
|
|
28
31
|
def render
|
29
32
|
puts "start document"
|
30
|
-
@items =
|
33
|
+
@items = @feed.entries
|
31
34
|
Prawn::Document.generate @output, @options do |doc|
|
32
|
-
doc.font @font
|
35
|
+
doc.font @font
|
33
36
|
puts "num of items: #{@items.size}"
|
37
|
+
|
38
|
+
render_toc(doc)
|
39
|
+
|
40
|
+
count = 1
|
34
41
|
@items.each do |item|
|
35
|
-
title =
|
36
|
-
desc =
|
37
|
-
|
42
|
+
title = item.title
|
43
|
+
desc = item.content
|
44
|
+
link_id = "link_#{count}"
|
45
|
+
render_item(doc, title, desc, link_id)
|
46
|
+
count += 1
|
38
47
|
end
|
39
48
|
end
|
40
49
|
puts "end document"
|
41
50
|
end
|
42
51
|
|
43
52
|
private
|
44
|
-
def
|
53
|
+
def render_toc(doc)
|
54
|
+
|
55
|
+
# TITLE
|
56
|
+
doc.bounding_box([doc.bounds.left, doc.bounds.top], :width => doc.bounds.width) do
|
57
|
+
doc.text_options.update(:wrap => :character, :size => 32, :spacing => 4)
|
58
|
+
doc.tags :p => {:font_size => "1em", :color => "black"}
|
59
|
+
doc.styles :toc => {:font_size => "1.5em", :color => "black", :text_decoration => :underline},
|
60
|
+
:title => {:font_size => "3em"}, :details => {:kerning => true}
|
61
|
+
|
62
|
+
doc.pad_bottom(10) do
|
63
|
+
doc.text "<a name='title' class='toc title'></a>"
|
64
|
+
doc.text @feed.title
|
65
|
+
end
|
66
|
+
|
67
|
+
# TOC
|
68
|
+
doc.text_options.update(:wrap => :character, :size => 26, :spacing => 4)
|
69
|
+
count = 1
|
70
|
+
@items.each do |item|
|
71
|
+
title = item.title
|
72
|
+
doc.pad_bottom(5) do
|
73
|
+
doc.text "<p>#{count}</p><a href='#link_#{count}' class='toc'>#{title}</a>"
|
74
|
+
end
|
75
|
+
|
76
|
+
count += 1
|
77
|
+
end
|
78
|
+
doc.start_new_page
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def render_item(doc, title, description, link_id)
|
45
83
|
puts "render: #{title}"
|
46
84
|
doc.bounding_box([doc.bounds.left, doc.bounds.top], :width => doc.bounds.width) do
|
47
|
-
doc.pad_bottom(
|
85
|
+
doc.pad_bottom(30) do
|
48
86
|
doc.text_options.update(:wrap => :character, :size => 26, :spacing => 4)
|
87
|
+
doc.text "<a name='#{link_id}'/>"
|
49
88
|
doc.text title
|
50
89
|
end
|
51
|
-
|
90
|
+
|
52
91
|
doc.text_options.update(:wrap => :character, :size => 20, :spacing => 4)
|
53
92
|
description = Hpricot(description).inner_text
|
54
93
|
description.split(/[\n\r][\n\r]?/).each do |d|
|
55
|
-
doc.
|
94
|
+
doc.pad_bottom(15) do
|
95
|
+
doc.text d
|
96
|
+
end
|
56
97
|
end
|
57
98
|
|
99
|
+
doc.text "<a href='#title' class='toc'><<</a>"
|
58
100
|
doc.start_new_page
|
59
101
|
end
|
60
102
|
end
|
data/rssbook.gemspec
CHANGED
@@ -2,8 +2,8 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
s.name = 'rssbook'
|
5
|
-
s.version = '0.
|
6
|
-
s.date = '2009-06-
|
5
|
+
s.version = '0.2.0'
|
6
|
+
s.date = '2009-06-14'
|
7
7
|
|
8
8
|
s.summary = s.description = "Convert RSS Feed to PDF format."
|
9
9
|
|
@@ -18,11 +18,15 @@ Gem::Specification.new do |s|
|
|
18
18
|
bin/rssbook
|
19
19
|
lib/rssbook.rb
|
20
20
|
rssbook.gemspec
|
21
|
+
test/feeds/feed1.xml
|
22
|
+
test/feeds/feed2.xml
|
23
|
+
test/rss_test.rb
|
21
24
|
]
|
22
25
|
# = MANIFEST =
|
23
26
|
|
24
27
|
s.extra_rdoc_files = %w[README LICENSE]
|
25
28
|
s.add_dependency 'prawn'
|
29
|
+
s.add_dependency 'feed-normalizer'
|
26
30
|
s.add_dependency 'hpricot'
|
27
31
|
s.has_rdoc = false
|
28
32
|
s.executables = ["rssbook"]
|
@@ -0,0 +1,173 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<?xml-stylesheet href="/rss.xsl" type="text/xsl" media="screen"?>
|
3
|
+
<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule">
|
4
|
+
<channel>
|
5
|
+
<title><![CDATA[Yahoo! 新聞 - 港聞]]></title>
|
6
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/rss/hongkong/rss.xml]]></link>
|
7
|
+
<description><![CDATA[Yahoo! 新聞 - 港聞]]></description>
|
8
|
+
<language>zh-HK</language>
|
9
|
+
<copyright>Copyright (c) 2008 Yahoo! Inc. All rights reserved.</copyright>
|
10
|
+
|
11
|
+
<lastBuildDate>Sun, 14 Jun 2009 00:27:20 +0800</lastBuildDate>
|
12
|
+
<ttl>5</ttl>
|
13
|
+
<image>
|
14
|
+
<title><![CDATA[Yahoo! 新聞 - 港聞]]></title>
|
15
|
+
<url><![CDATA[http://hk.yimg.com/i/nws/nws6_rss.gif]]></url>
|
16
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/rss/hongkong/rss.xml]]></link>
|
17
|
+
<width>144</width>
|
18
|
+
<height>31</height>
|
19
|
+
|
20
|
+
</image>
|
21
|
+
<item>
|
22
|
+
<title><![CDATA[柴灣海面發現浮屍無可疑]]></title>
|
23
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/cog6.html]]></link>
|
24
|
+
<description><![CDATA[柴灣貨物起卸區漁船停泊處下午發現一具男屍,未有發現任何證明文件,初步相信無可疑。]]></description>
|
25
|
+
<guid isPermaLink="false">yahoo/hk/news/591558</guid>
|
26
|
+
<pubDate>Sun, 14 Jun 2009 00:15:05 +0800</pubDate>
|
27
|
+
</item>
|
28
|
+
<item>
|
29
|
+
<title><![CDATA[本港新增十一宗新流感個案]]></title>
|
30
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/cog1.html]]></link>
|
31
|
+
<description><![CDATA[衛生署公布,是日新增11宗甲型H1N1流感確診個案,香港至今共錄得84宗病例。]]></description>
|
32
|
+
<guid isPermaLink="false">yahoo/hk/news/591553</guid>
|
33
|
+
<pubDate>Sat, 13 Jun 2009 23:15:05 +0800</pubDate>
|
34
|
+
|
35
|
+
</item>
|
36
|
+
<item>
|
37
|
+
<title><![CDATA[旺角車禍死者家人矢言追究]]></title>
|
38
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/cofo.html]]></link>
|
39
|
+
<description><![CDATA[旺角周五深夜發生的小巴與巴士相撞後剷上行人路車禍,死者家屬誓言追究,而事故現場經常見到小巴與巴士爭路。]]></description>
|
40
|
+
<guid isPermaLink="false">yahoo/hk/news/591540</guid>
|
41
|
+
<pubDate>Sat, 13 Jun 2009 22:20:04 +0800</pubDate>
|
42
|
+
</item>
|
43
|
+
<item>
|
44
|
+
<title><![CDATA[本港再確診五宗新流感]]></title>
|
45
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/coel.html]]></link>
|
46
|
+
<description><![CDATA[本港確診多5宗甲型H1N1流感,令本港的確診個升至78宗,其中4宗屬外地傳入,一宗未分類。]]></description>
|
47
|
+
<guid isPermaLink="false">yahoo/hk/news/591501</guid>
|
48
|
+
<pubDate>Sat, 13 Jun 2009 22:20:04 +0800</pubDate>
|
49
|
+
|
50
|
+
</item>
|
51
|
+
<item>
|
52
|
+
<title><![CDATA[柴灣起卸區撈獲老翁浮屍]]></title>
|
53
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/3/coft.html]]></link>
|
54
|
+
<description><![CDATA[一名年約七十歲老翁,下午被市民發現浮屍柴灣公眾貨物起卸區對開,警方聯同消防員接報到場,將年老浮屍撈上岸邊,警員未能在其身上尋獲任何身分證明文件,警員正追查浮屍者的背景及墮海原因。]]></description>
|
55
|
+
<guid isPermaLink="false">yahoo/hk/news/591545</guid>
|
56
|
+
<pubDate>Sat, 13 Jun 2009 21:33:29 +0800</pubDate>
|
57
|
+
</item>
|
58
|
+
<item>
|
59
|
+
<title><![CDATA[觀塘社區中心翻新後重開]]></title>
|
60
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/3/cofs.html]]></link>
|
61
|
+
<description><![CDATA[觀塘社區中心改善工程己經竣工,內容包括擴建禮堂和舞台、改善音響及燈光器材、更新冷氣系統及增設休憩花園等。經全面翻新後的社區中心今日正式重新啟用,為區內市民提供一個可舉辦各類型表演的理想社區活動場地。]]></description>
|
62
|
+
<guid isPermaLink="false">yahoo/hk/news/591544</guid>
|
63
|
+
<pubDate>Sat, 13 Jun 2009 21:20:29 +0800</pubDate>
|
64
|
+
|
65
|
+
</item>
|
66
|
+
<item>
|
67
|
+
<title><![CDATA[警籲市民提供柴灣致命車禍資料]]></title>
|
68
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/3/cofr.html]]></link>
|
69
|
+
<description><![CDATA[警方港島總區交通部特別調查隊,正調查今午在柴灣發生的一宗交通意外,意外中一名七十四歲老翁死亡。任何人如曾目睹意外經過或有資料提供,請致電31068800或31068833與調查人員聯絡。]]></description>
|
70
|
+
<guid isPermaLink="false">yahoo/hk/news/591543</guid>
|
71
|
+
<pubDate>Sat, 13 Jun 2009 21:09:28 +0800</pubDate>
|
72
|
+
</item>
|
73
|
+
<item>
|
74
|
+
<title><![CDATA[旺角嚴重車禍司機危駕保釋]]></title>
|
75
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/coc9.html]]></link>
|
76
|
+
<description><![CDATA[旺角昨晚深夜一輛小巴與巴士相撞後剷上行人路,造成2死7傷,34歲小巴司機被控危險駕駛,今早獲准保釋。]]></description>
|
77
|
+
<guid isPermaLink="false">yahoo/hk/news/591417</guid>
|
78
|
+
<pubDate>Sat, 13 Jun 2009 21:05:03 +0800</pubDate>
|
79
|
+
|
80
|
+
</item>
|
81
|
+
<item>
|
82
|
+
<title><![CDATA[四千四百多隻活豬今運抵屠房]]></title>
|
83
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/3/cofq.html]]></link>
|
84
|
+
<description><![CDATA[今日運抵屠房的活豬數目為四千四百四十六隻,當中四千一百卅六隻為內地進口活豬,三百一十隻為本地豬。活豬批發價介乎每擔爪百五十至,一千一百一十五元,平均價為九百五十一元。]]></description>
|
85
|
+
<guid isPermaLink="false">yahoo/hk/news/591542</guid>
|
86
|
+
<pubDate>Sat, 13 Jun 2009 21:01:29 +0800</pubDate>
|
87
|
+
</item>
|
88
|
+
<item>
|
89
|
+
<title><![CDATA[警方尖沙咀的士高拘四毒販]]></title>
|
90
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/3/cofp.html]]></link>
|
91
|
+
<description><![CDATA[警方接獲線報,一個販毒集團在尖沙咀麼地道的一間的士高販賣精神科毒品。毒品調查科探員在五月展開一項代號「House Painter」的行動,鎖定該販毒集團的三名成員。]]></description>
|
92
|
+
<guid isPermaLink="false">yahoo/hk/news/591541</guid>
|
93
|
+
<pubDate>Sat, 13 Jun 2009 20:56:28 +0800</pubDate>
|
94
|
+
|
95
|
+
</item>
|
96
|
+
<item>
|
97
|
+
<title><![CDATA[柴灣車禍老伯死亡]]></title>
|
98
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/coez.html]]></link>
|
99
|
+
<description><![CDATA[柴灣嘉業街下午五時許發生車禍,一名74歲老伯被輕型貨車撞倒,送院後證實死亡。]]></description>
|
100
|
+
<guid isPermaLink="false">yahoo/hk/news/591515</guid>
|
101
|
+
<pubDate>Sat, 13 Jun 2009 20:20:03 +0800</pubDate>
|
102
|
+
</item>
|
103
|
+
<item>
|
104
|
+
<title><![CDATA[旺角車禍死者家人促徹查]]></title>
|
105
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/coei.html]]></link>
|
106
|
+
<description><![CDATA[旺角道昨晚深夜造成兩人死亡的嚴重車禍,死者的家人在正午路祭。]]></description>
|
107
|
+
<guid isPermaLink="false">yahoo/hk/news/591498</guid>
|
108
|
+
<pubDate>Sat, 13 Jun 2009 20:20:03 +0800</pubDate>
|
109
|
+
|
110
|
+
</item>
|
111
|
+
<item>
|
112
|
+
<title><![CDATA[警方在尖沙嘴拘捕四毒販]]></title>
|
113
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/cofb.html]]></link>
|
114
|
+
<description><![CDATA[警方於上午執行一項反毒品行動時,在尖沙嘴一間的士高拘捕四名涉嫌販毒男子。]]></description>
|
115
|
+
<guid isPermaLink="false">yahoo/hk/news/591527</guid>
|
116
|
+
<pubDate>Sat, 13 Jun 2009 19:35:03 +0800</pubDate>
|
117
|
+
</item>
|
118
|
+
<item>
|
119
|
+
<title><![CDATA[旺角釀大車禍小巴司機獲准保釋]]></title>
|
120
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/3/cofc.html]]></link>
|
121
|
+
<description><![CDATA[釀成兩死八傷車禍的卅四歲專線小巴司機,因涉嫌危險駕駛引致他人死亡一度被捕,下午已獲准以一萬元保釋,下周須到警署報到。]]></description>
|
122
|
+
<guid isPermaLink="false">yahoo/hk/news/591528</guid>
|
123
|
+
<pubDate>Sat, 13 Jun 2009 19:08:29 +0800</pubDate>
|
124
|
+
|
125
|
+
</item>
|
126
|
+
<item>
|
127
|
+
<title><![CDATA[流感診所首日治二百多人]]></title>
|
128
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/cof0.html]]></link>
|
129
|
+
<description><![CDATA[醫管局轄下八間指定流感診所今日正式服務,首日運作暢順,八間診所合共為236名患有流感徵狀的市民診治。]]></description>
|
130
|
+
<guid isPermaLink="false">yahoo/hk/news/591516</guid>
|
131
|
+
<pubDate>Sat, 13 Jun 2009 18:55:04 +0800</pubDate>
|
132
|
+
</item>
|
133
|
+
<item>
|
134
|
+
<title><![CDATA[港學生多認同中國人身分]]></title>
|
135
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/coey.html]]></link>
|
136
|
+
<description><![CDATA[國民教育中心首次全港學校調查顯示,香港中小學生多認同中國人的身分。]]></description>
|
137
|
+
<guid isPermaLink="false">yahoo/hk/news/591514</guid>
|
138
|
+
<pubDate>Sat, 13 Jun 2009 18:35:04 +0800</pubDate>
|
139
|
+
|
140
|
+
</item>
|
141
|
+
<item>
|
142
|
+
<title><![CDATA[今新確診女子曾到過尖沙嘴]]></title>
|
143
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/coex.html]]></link>
|
144
|
+
<description><![CDATA[曾到過江西及廣州的確診女子,病發前曾到過尖沙嘴星光大道、尖沙嘴中心等地,傳播病毒機會低。]]></description>
|
145
|
+
<guid isPermaLink="false">yahoo/hk/news/591513</guid>
|
146
|
+
<pubDate>Sat, 13 Jun 2009 18:25:05 +0800</pubDate>
|
147
|
+
</item>
|
148
|
+
<item>
|
149
|
+
<title><![CDATA[曾浩輝指流感診所秩序良好]]></title>
|
150
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/coer.html]]></link>
|
151
|
+
<description><![CDATA[衛生防護中心總監曾浩輝表示,首天開放的指定流感診所整體秩序良好。]]></description>
|
152
|
+
<guid isPermaLink="false">yahoo/hk/news/591507</guid>
|
153
|
+
<pubDate>Sat, 13 Jun 2009 18:10:07 +0800</pubDate>
|
154
|
+
|
155
|
+
</item>
|
156
|
+
<item>
|
157
|
+
<title><![CDATA[曾浩輝稱已訂更多抗流感藥]]></title>
|
158
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/4/coep.html]]></link>
|
159
|
+
<description><![CDATA[衛生防護中心總監曾浩輝表示,有鑑於現時本港甲型H1N1流感疫情有變,當局已增購抗流感藥物如特敏福。]]></description>
|
160
|
+
<guid isPermaLink="false">yahoo/hk/news/591505</guid>
|
161
|
+
<pubDate>Sat, 13 Jun 2009 18:00:09 +0800</pubDate>
|
162
|
+
</item>
|
163
|
+
<item>
|
164
|
+
<title><![CDATA[5宗H1N14宗屬外地傳入]]></title>
|
165
|
+
<link><![CDATA[http://hk.rd.yahoo.com/news/rss/*http://hk.news.yahoo.com/article/090613/3/coeo.html]]></link>
|
166
|
+
<description><![CDATA[本港再確診5宗H1N1甲型流感(人類豬流感)個案,累計確診個案增至78宗。]]></description>
|
167
|
+
<guid isPermaLink="false">yahoo/hk/news/591504</guid>
|
168
|
+
<pubDate>Sat, 13 Jun 2009 17:24:29 +0800</pubDate>
|
169
|
+
|
170
|
+
</item>
|
171
|
+
</channel>
|
172
|
+
</rss>
|
173
|
+
<!-- spaceId: 97097717 -->
|