ghtml2pdf 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2cd71696162ba34bf3dee787d03df42e83fc9d2
4
- data.tar.gz: b3b8de83e5736ecd62535bf3cc5ea617c2921dcd
3
+ metadata.gz: 2f6922a9478fbccfc04fb8f995314d4916b8a09d
4
+ data.tar.gz: bd10e27b1cf116ec4d90894109870efe4218c2df
5
5
  SHA512:
6
- metadata.gz: c63311016143803e16a3635681d8fe5289174d3cd948f110c07338a8cbfbccceebb8032b99cb811d858463f3e789b390875b9769644763c28b9784e1e50159c5
7
- data.tar.gz: 4f5f163a322ffb2af9d8ecf825dcc0b746ef46b0a22fc24d23e483ad09945e71e9f3760ee5b958c4b3bc8ec39d338c09b4a3b6efc76979156f713a5b84c44f63
6
+ metadata.gz: 235563288c6b44762ce66943749165a5a452e730dee5ff121f7ab437baac070c090c416d106a6117d639547d5d84a6ce9a55da0284806b163c6f049f2dee9b2a
7
+ data.tar.gz: 4a2177d0c82a7f6aea373a692375acc719b5bc37a99b526138d184c86fcf25157b55c1360e5e32f1259aac58f96ff403391d3e7be9ee0784b87c0ba6e60b30b1
data/Changelog.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## 0.1.1 / 2016-02-06
4
+
5
+ * Run headlessly using xvfb
6
+ * Set A4 paper size explicitely
7
+ * Update dependency on GirFFI-Gtk
8
+
3
9
  ## 0.1.0 / 2015-11-26
4
10
 
5
11
  * Initial release.
data/bin/ghtml2pdf CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'ghtml2pdf'
4
+ require 'headless'
4
5
 
5
- GHtml2Pdf.run
6
+ Headless.ly do
7
+ GHtml2Pdf.run(ARGV)
8
+ end
data/lib/ghtml2pdf.rb CHANGED
@@ -1,8 +1,16 @@
1
1
  require 'ghtml2pdf/version'
2
2
  require 'ghtml2pdf/application'
3
3
 
4
+ # Main entry point for GHtml2Pdf.
4
5
  module GHtml2Pdf
5
- def self.run
6
- GHtml2Pdf::Application.new.run
6
+ # Run the application.
7
+ #
8
+ # @param [Array] argv The command line arguments
9
+ def self.run(argv)
10
+ Gtk.init
11
+ GHtml2Pdf::Application.new(argv).run
12
+ rescue GHtml2Pdf::MissingArgument => e
13
+ warn e.message
14
+ exit 1
7
15
  end
8
16
  end
@@ -1,47 +1,22 @@
1
1
  require 'gir_ffi-gtk3'
2
+ require_relative 'argument_parser'
3
+
4
+ GirFFI.setup :WebKit2, '4.0'
2
5
 
3
6
  module GHtml2Pdf
7
+ # Main GHtml2Pdf application. Orchestrates the Gtk+ objects needed to load
8
+ # and print a web page to PDF.
4
9
  class Application
5
- def run
6
- input, output, = ARGV
7
- unless input
8
- warn "An input filename is required"
9
- exit 1
10
- end
11
- unless output
12
- warn "An output filename is required"
13
- exit 1
14
- end
15
- input_uri = "file://#{File.expand_path(input)}"
16
- output_uri = "file://#{File.expand_path(output)}"
17
-
18
- GirFFI.setup :WebKit2, '4.0'
19
-
20
- Gtk.init
21
-
22
- win = Gtk::OffscreenWindow.new
23
- web_view = WebKit2::WebView.new
24
- win.add(web_view)
25
-
26
- page_setup = Gtk::PageSetup.new
10
+ attr_reader :input, :output
27
11
 
28
- print_settings = Gtk::PrintSettings.new
29
- print_settings.set_number_up 1
30
- print_settings.set_reverse false
31
- print_settings.set_print_pages :all
32
- print_settings.set 'output-uri', output_uri
33
- print_settings.set 'output-file-format', 'pdf'
34
- print_settings.set_collate false
35
- print_settings.set_n_copies 1
36
- print_settings.set_printer 'Print to File'
37
- print_settings.set_page_set :all
38
- print_settings.set_scale 100.0
39
-
40
- print_operation = WebKit2::PrintOperation.new(web_view)
41
- print_operation.page_setup = page_setup
42
- print_operation.print_settings = print_settings
12
+ def initialize(argv)
13
+ argument_parser = ArgumentParser.new(argv)
14
+ @input = argument_parser.input
15
+ @output = argument_parser.output
16
+ end
43
17
 
44
- web_view.signal_connect "load-changed" do |_, event, _|
18
+ def run
19
+ web_view.signal_connect 'load-changed' do |_, event, _|
45
20
  case event
46
21
  when :finished
47
22
  print_operation.print
@@ -51,9 +26,58 @@ module GHtml2Pdf
51
26
  end
52
27
 
53
28
  web_view.load_uri(input_uri)
54
- win.show_all
55
29
 
56
30
  Gtk.main
31
+
32
+ web_view.destroy
33
+ end
34
+
35
+ private
36
+
37
+ def print_operation
38
+ WebKit2::PrintOperation.new(web_view).tap do |operation|
39
+ operation.page_setup = page_setup
40
+ operation.print_settings = print_settings
41
+ end
42
+ end
43
+
44
+ def page_setup
45
+ Gtk::PageSetup.new.tap do |setup|
46
+ setup.set_paper_size Gtk::PaperSize.new Gtk::PAPER_NAME_A4
47
+ end
48
+ end
49
+
50
+ def web_context
51
+ @web_context || WebKit2::WebContext.new.tap do |context|
52
+ context.set_process_model :multiple_secondary_processes
53
+ end
54
+ end
55
+
56
+ def web_view
57
+ @web_view ||= WebKit2::WebView.new_with_context web_context
58
+ end
59
+
60
+ def print_settings
61
+ Gtk::PrintSettings.new.tap do |settings|
62
+ settings.set_number_up 1
63
+ settings.set_reverse false
64
+ settings.set_print_pages :all
65
+ settings.set 'output-uri', output_uri
66
+ settings.set 'output-file-format', 'pdf'
67
+ settings.set_collate false
68
+ settings.set_n_copies 1
69
+ settings.set_printer 'Print to File'
70
+ settings.set_page_set :all
71
+ settings.set_scale 100.0
72
+ end
73
+ end
74
+
75
+ def output_uri
76
+ "file://#{File.expand_path(output)}"
77
+ end
78
+
79
+ def input_uri
80
+ "file://#{File.expand_path(input)}"
57
81
  end
58
82
  end
59
83
  end
@@ -0,0 +1,15 @@
1
+ module GHtml2Pdf
2
+ # Error class raised for missing arguments
3
+ class MissingArgument < StandardError; end
4
+
5
+ # Parses the command line arguments
6
+ class ArgumentParser
7
+ attr_reader :input, :output
8
+
9
+ def initialize(argv)
10
+ @input, @output, = argv
11
+ raise MissingArgument, 'An input filename is required' unless @input
12
+ raise MissingArgument, 'An output filename is required' unless @output
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module GHtml2Pdf
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghtml2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2016-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gir_ffi-gtk
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.0
19
+ version: 0.9.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.0
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: headless
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '1.10'
47
+ version: '1.7'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '1.10'
54
+ version: '1.7'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,42 @@ dependencies:
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 0.10.0
103
+ version: 0.12.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.12.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pdf-reader
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.3
90
132
  type: :development
91
133
  prerelease: false
92
134
  version_requirements: !ruby/object:Gem::Requirement
93
135
  requirements:
94
136
  - - "~>"
95
137
  - !ruby/object:Gem::Version
96
- version: 0.10.0
138
+ version: 1.3.3
97
139
  description: "\n Clean Ruby implemenentation of a HTML to PDF\n converter based
98
140
  on WebKit, WebKit2GTK+ and GirFFI\n "
99
141
  email:
@@ -109,6 +151,7 @@ files:
109
151
  - bin/ghtml2pdf
110
152
  - lib/ghtml2pdf.rb
111
153
  - lib/ghtml2pdf/application.rb
154
+ - lib/ghtml2pdf/argument_parser.rb
112
155
  - lib/ghtml2pdf/version.rb
113
156
  homepage: https://github.com/mvz/ghtml2pdf
114
157
  licenses:
@@ -130,9 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
173
  version: '0'
131
174
  requirements: []
132
175
  rubyforge_project:
133
- rubygems_version: 2.4.5.1
176
+ rubygems_version: 2.5.1
134
177
  signing_key:
135
178
  specification_version: 4
136
179
  summary: HTML to PDF converter based on WebKit2GTK+
137
180
  test_files: []
138
- has_rdoc: