siuying-rssbook 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/LICENSE +22 -0
  2. data/README +18 -0
  3. data/Rakefile +60 -0
  4. data/bin/rssbook +13 -0
  5. data/lib/rssbook.rb +62 -0
  6. data/rssbook.gemspec +32 -0
  7. metadata +78 -0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 siu [dot] ying [at] gmail [dot] com
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,18 @@
1
+ RSSBook
2
+ =======
3
+
4
+ Convert RSS Feed to PDF format.
5
+
6
+ Usage:
7
+
8
+ Convert a RSS Feed File to PDF
9
+
10
+ rssbook engadgetchinese.rss engadget.pdf
11
+
12
+ Download and convert a RSS Feed to PDF
13
+
14
+ rssbook "http://feeds2.feedburner.com/engadgetchinese?format=xml" engadget.pdf
15
+
16
+ Download and convert a RSS Feed to PDF, using custom fonts:
17
+
18
+ rssbook "http://feeds2.feedburner.com/engadgetchinese?format=xml" engadget.pdf "Arial Unicode.ttf"
@@ -0,0 +1,60 @@
1
+ require 'rake/clean'
2
+ require 'rake/testtask'
3
+ require 'fileutils'
4
+ require "rake/gempackagetask"
5
+
6
+ SPEC_FILE = "rssbook.gemspec"
7
+
8
+ task :default => :package
9
+
10
+ # PACKAGING ============================================================
11
+
12
+ # Load the gemspec using the same limitations as github
13
+ def spec
14
+ @spec ||=
15
+ begin
16
+ require 'rubygems/specification'
17
+ data = File.read(SPEC_FILE)
18
+ spec = nil
19
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
20
+ spec
21
+ end
22
+ end
23
+
24
+ Rake::GemPackageTask.new(spec) do |pkg|
25
+ pkg.gem_spec = spec
26
+ end
27
+
28
+ desc "Install the RSSBook as a gem"
29
+ task :install => [:repackage] do
30
+ sh %{gem install pkg/#{spec.name}-#{spec.version}}
31
+ end
32
+
33
+ # Gemspec Helpers ====================================================
34
+
35
+ def source_version
36
+ line = File.read('lib/rssbook.rb')[/^\s*VERSION = .*/]
37
+ line.match(/.*VERSION = '(.*)'/)[1]
38
+ end
39
+
40
+ task SPEC_FILE => FileList['lib/**','bin/**','Rakefile','LICENSE','README'] do |f|
41
+ # read spec file and split out manifest section
42
+ spec = File.read(f.name)
43
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
44
+ # replace version and date
45
+ head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
46
+ head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
47
+ # determine file list from git ls-files
48
+ files = `git ls-files`.
49
+ split("\n").
50
+ sort.
51
+ reject{ |file| file =~ /^\./ }.
52
+ reject { |file| file =~ /^doc/ }.
53
+ map{ |file| " #{file}" }.
54
+ join("\n")
55
+ # piece file back together and write...
56
+ manifest = " s.files = %w[\n#{files}\n ]\n"
57
+ spec = [head,manifest,tail].join(" # = MANIFEST =\n")
58
+ File.open(f.name, 'w') { |io| io.write(spec) }
59
+ puts "updated #{f.name}"
60
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require "rssbook"
4
+
5
+ if ARGV.size != 2 && ARGV.size != 3
6
+ puts "rssbook - Convert RSS to PDF"
7
+ puts " pdbook <rss-file-or-URL> <output-pdf-file> [font-file]"
8
+
9
+ else
10
+ conv = RSSBook::Renderer.new(ARGV[0], ARGV[1], ARGV[2])
11
+ conv.render
12
+
13
+ end
@@ -0,0 +1,62 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require "rubygems"
5
+ require "prawn"
6
+ require 'iconv'
7
+ require 'logger'
8
+ require 'hpricot'
9
+ require 'open-uri'
10
+ require "prawn/measurement_extensions"
11
+
12
+ module RSSBook
13
+ VERSION = '0.1.3'
14
+
15
+ class Renderer
16
+ def initialize(input, output, font = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf",
17
+ options = {:page_size => "A4", :margin => 0.6.in, :compress => true})
18
+ @input = input
19
+ @output = output
20
+ @font = font
21
+ @options = options
22
+ @log = Logger.new($STDOUT)
23
+
24
+ puts "input: #{input}, output: #{output}"
25
+ @feed = Hpricot.XML(open(input))
26
+ end
27
+
28
+ def render
29
+ puts "start document"
30
+ @items = (@feed/"//item")
31
+ Prawn::Document.generate @output, @options do |doc|
32
+ doc.font @font
33
+ puts "num of items: #{@items.size}"
34
+ @items.each do |item|
35
+ title = (item/"/title").inner_text
36
+ desc = (item/"/description").inner_text
37
+ render_feed(doc, title, desc)
38
+ end
39
+ end
40
+ puts "end document"
41
+ end
42
+
43
+ private
44
+ def render_feed(doc, title, description)
45
+ puts "render: #{title}"
46
+ doc.bounding_box([doc.bounds.left, doc.bounds.top], :width => doc.bounds.width) do
47
+ doc.pad_bottom(20) do
48
+ doc.text_options.update(:wrap => :character, :size => 26, :spacing => 4)
49
+ doc.text title
50
+ end
51
+
52
+ doc.text_options.update(:wrap => :character, :size => 20, :spacing => 4)
53
+ description = Hpricot(description).inner_text
54
+ description.split(/[\n\r][\n\r]?/).each do |d|
55
+ doc.text d
56
+ end
57
+
58
+ doc.start_new_page
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.name = 'rssbook'
5
+ s.version = '0.1.3'
6
+ s.date = '2009-06-09'
7
+
8
+ s.summary = s.description = "Convert RSS Feed to PDF format."
9
+
10
+ s.author = "siuying"
11
+ s.email = "siu.ying@gmail.com"
12
+
13
+ # = MANIFEST =
14
+ s.files = %w[
15
+ LICENSE
16
+ README
17
+ Rakefile
18
+ bin/rssbook
19
+ lib/rssbook.rb
20
+ rssbook.gemspec
21
+ ]
22
+ # = MANIFEST =
23
+
24
+ s.extra_rdoc_files = %w[README LICENSE]
25
+ s.add_dependency 'prawn'
26
+ s.add_dependency 'hpricot'
27
+ s.has_rdoc = false
28
+ s.executables = ["rssbook"]
29
+ s.require_paths = %w[lib]
30
+ s.rubygems_version = '1.1.1'
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: siuying-rssbook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - siuying
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-09 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: prawn
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hpricot
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Convert RSS Feed to PDF format.
36
+ email: siu.ying@gmail.com
37
+ executables:
38
+ - rssbook
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ - LICENSE
44
+ files:
45
+ - LICENSE
46
+ - README
47
+ - Rakefile
48
+ - bin/rssbook
49
+ - lib/rssbook.rb
50
+ - rssbook.gemspec
51
+ has_rdoc: false
52
+ homepage:
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.2.0
74
+ signing_key:
75
+ specification_version: 2
76
+ summary: Convert RSS Feed to PDF format.
77
+ test_files: []
78
+