ghtml2pdf 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f6922a9478fbccfc04fb8f995314d4916b8a09d
4
- data.tar.gz: bd10e27b1cf116ec4d90894109870efe4218c2df
3
+ metadata.gz: cdfdbe8ab1a2b00b5cf66b27b99be41beb18303f
4
+ data.tar.gz: 7bd1589a4c06e5fb32955d50ec3d95901438e58d
5
5
  SHA512:
6
- metadata.gz: 235563288c6b44762ce66943749165a5a452e730dee5ff121f7ab437baac070c090c416d106a6117d639547d5d84a6ce9a55da0284806b163c6f049f2dee9b2a
7
- data.tar.gz: 4a2177d0c82a7f6aea373a692375acc719b5bc37a99b526138d184c86fcf25157b55c1360e5e32f1259aac58f96ff403391d3e7be9ee0784b87c0ba6e60b30b1
6
+ metadata.gz: 2844420dbfd5e88d9929c2b5f9abe3ce98add53ec90ba0f551d4a78a0b992f6632c3caad62ddc79b4f7fef9318636f2197ca03d7e59ca3c2660b2e3acc3ae311
7
+ data.tar.gz: 300d570641270b7975b195a5ff7c6e63088a04536f16300f8891d9bc873584b5442d93a7d839ebe88b89377f59435cd533089691849f432b0963fa017c085c08
data/Changelog.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ## 0.2.0 / 2016-02-06
4
+
5
+ * Set wider margins by default
6
+ * Allow setting all margins from the command line
7
+
3
8
  ## 0.1.1 / 2016-02-06
4
9
 
5
10
  * Run headlessly using xvfb
@@ -1,18 +1,14 @@
1
1
  require 'gir_ffi-gtk3'
2
2
  require_relative 'argument_parser'
3
3
 
4
- GirFFI.setup :WebKit2, '4.0'
4
+ GirFFI.setup :WebKit2
5
5
 
6
6
  module GHtml2Pdf
7
7
  # Main GHtml2Pdf application. Orchestrates the Gtk+ objects needed to load
8
8
  # and print a web page to PDF.
9
9
  class Application
10
- attr_reader :input, :output
11
-
12
10
  def initialize(argv)
13
- argument_parser = ArgumentParser.new(argv)
14
- @input = argument_parser.input
15
- @output = argument_parser.output
11
+ @argument_parser = ArgumentParser.new(argv)
16
12
  end
17
13
 
18
14
  def run
@@ -34,6 +30,24 @@ module GHtml2Pdf
34
30
 
35
31
  private
36
32
 
33
+ attr_reader :argument_parser
34
+
35
+ def top_margin
36
+ @top_margin ||= argument_parser.top_margin || Unit.new('2cm')
37
+ end
38
+
39
+ def bottom_margin
40
+ @bottom_margin ||= argument_parser.bottom_margin || Unit.new('3cm')
41
+ end
42
+
43
+ def left_margin
44
+ @left_margin ||= argument_parser.left_margin || Unit.new('2cm')
45
+ end
46
+
47
+ def right_margin
48
+ @right_margin ||= argument_parser.right_margin || Unit.new('2cm')
49
+ end
50
+
37
51
  def print_operation
38
52
  WebKit2::PrintOperation.new(web_view).tap do |operation|
39
53
  operation.page_setup = page_setup
@@ -44,11 +58,15 @@ module GHtml2Pdf
44
58
  def page_setup
45
59
  Gtk::PageSetup.new.tap do |setup|
46
60
  setup.set_paper_size Gtk::PaperSize.new Gtk::PAPER_NAME_A4
61
+ setup.set_top_margin top_margin.convert_to('mm').scalar, :mm
62
+ setup.set_bottom_margin bottom_margin.convert_to('mm').scalar, :mm
63
+ setup.set_left_margin left_margin.convert_to('mm').scalar, :mm
64
+ setup.set_right_margin right_margin.convert_to('mm').scalar, :mm
47
65
  end
48
66
  end
49
67
 
50
68
  def web_context
51
- @web_context || WebKit2::WebContext.new.tap do |context|
69
+ @web_context ||= WebKit2::WebContext.new.tap do |context|
52
70
  context.set_process_model :multiple_secondary_processes
53
71
  end
54
72
  end
@@ -73,11 +91,11 @@ module GHtml2Pdf
73
91
  end
74
92
 
75
93
  def output_uri
76
- "file://#{File.expand_path(output)}"
94
+ "file://#{File.expand_path(argument_parser.output)}"
77
95
  end
78
96
 
79
97
  def input_uri
80
- "file://#{File.expand_path(input)}"
98
+ "file://#{File.expand_path(argument_parser.input)}"
81
99
  end
82
100
  end
83
101
  end
@@ -1,3 +1,6 @@
1
+ require 'optparse'
2
+ require 'ruby-units'
3
+
1
4
  module GHtml2Pdf
2
5
  # Error class raised for missing arguments
3
6
  class MissingArgument < StandardError; end
@@ -5,11 +8,46 @@ module GHtml2Pdf
5
8
  # Parses the command line arguments
6
9
  class ArgumentParser
7
10
  attr_reader :input, :output
11
+ attr_reader :top_margin, :bottom_margin, :left_margin, :right_margin
8
12
 
9
13
  def initialize(argv)
14
+ option_parser.parse! argv
10
15
  @input, @output, = argv
11
16
  raise MissingArgument, 'An input filename is required' unless @input
12
17
  raise MissingArgument, 'An output filename is required' unless @output
13
18
  end
19
+
20
+ def option_parser
21
+ @option_parser ||=
22
+ OptionParser.new.tap do |parser|
23
+ parser.banner = "Usage: #{parser.program_name} [options] INFILE OUTFILE"
24
+ parser.on('--top-margin MARGIN', 'Set top margin') { |val| self.top_margin = val }
25
+ parser.on('--bottom-margin MARGIN', 'Set bottom margin') { |val| self.bottom_margin = val }
26
+ parser.on('--left-margin MARGIN', 'Set left margin') { |val| self.left_margin = val }
27
+ parser.on('--right-margin MARGIN', 'Set right margin') { |val| self.right_margin = val }
28
+ parser.on_tail('-h', '--help', 'Show this message') do
29
+ puts parser
30
+ exit
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def top_margin=(val)
38
+ @top_margin = Unit.new(val)
39
+ end
40
+
41
+ def bottom_margin=(val)
42
+ @bottom_margin = Unit.new(val)
43
+ end
44
+
45
+ def left_margin=(val)
46
+ @left_margin = Unit.new(val)
47
+ end
48
+
49
+ def right_margin=(val)
50
+ @right_margin = Unit.new(val)
51
+ end
14
52
  end
15
53
  end
@@ -1,3 +1,3 @@
1
1
  module GHtml2Pdf
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
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.1
4
+ version: 0.2.0
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: 2016-02-06 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gir_ffi-gtk
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.0
19
+ version: 0.10.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.9.0
26
+ version: 0.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: headless
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-units
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +72,14 @@ dependencies:
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '10.0'
75
+ version: '11.1'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '10.0'
82
+ version: '11.1'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 0.12.0
117
+ version: 0.14.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 0.12.0
124
+ version: 0.14.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: pry
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +142,14 @@ dependencies:
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: 1.3.3
145
+ version: 1.4.0
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: 1.3.3
152
+ version: 1.4.0
139
153
  description: "\n Clean Ruby implemenentation of a HTML to PDF\n converter based
140
154
  on WebKit, WebKit2GTK+ and GirFFI\n "
141
155
  email: