wicked_pdf 1.0.3 → 2.6.3
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 +5 -5
- data/.github/issue_template.md +15 -0
- data/.github/workflows/ci.yml +56 -0
- data/.rubocop.yml +60 -0
- data/.rubocop_todo.yml +84 -37
- data/CHANGELOG.md +230 -0
- data/README.md +188 -30
- data/Rakefile +13 -9
- data/gemfiles/5.0.gemfile +8 -0
- data/gemfiles/5.1.gemfile +8 -0
- data/gemfiles/5.2.gemfile +9 -0
- data/gemfiles/6.0.gemfile +10 -0
- data/gemfiles/6.1.gemfile +12 -0
- data/gemfiles/7.0.gemfile +12 -0
- data/generators/wicked_pdf/templates/wicked_pdf.rb +9 -0
- data/lib/generators/wicked_pdf_generator.rb +5 -9
- data/lib/wicked_pdf/binary.rb +65 -0
- data/lib/wicked_pdf/middleware.rb +3 -3
- data/lib/wicked_pdf/option_parser.rb +229 -0
- data/lib/wicked_pdf/pdf_helper.rb +101 -88
- data/lib/wicked_pdf/progress.rb +33 -0
- data/lib/wicked_pdf/railtie.rb +6 -33
- data/lib/wicked_pdf/tempfile.rb +38 -7
- data/lib/wicked_pdf/version.rb +1 -1
- data/lib/wicked_pdf/wicked_pdf_helper/assets.rb +212 -88
- data/lib/wicked_pdf/wicked_pdf_helper.rb +29 -26
- data/lib/wicked_pdf.rb +37 -274
- data/test/fixtures/database.yml +4 -0
- data/test/fixtures/manifest.js +3 -0
- data/test/fixtures/wicked.js +1 -0
- data/test/functional/pdf_helper_test.rb +74 -5
- data/test/functional/wicked_pdf_helper_assets_test.rb +86 -25
- data/test/functional/wicked_pdf_helper_test.rb +15 -13
- data/test/test_helper.rb +22 -7
- data/test/unit/wicked_pdf_binary_test.rb +26 -0
- data/test/unit/wicked_pdf_option_parser_test.rb +128 -0
- data/test/unit/wicked_pdf_test.rb +14 -168
- data/test/unit/wkhtmltopdf_location_test.rb +48 -0
- data/wicked_pdf.gemspec +20 -14
- metadata +69 -38
- data/.travis.yml +0 -57
- data/CHANGLOG.md +0 -48
- data/gemfiles/2.3.gemfile +0 -10
- data/gemfiles/3.0.gemfile +0 -7
- data/gemfiles/3.1.gemfile +0 -8
- data/gemfiles/3.2.gemfile +0 -7
- data/gemfiles/4.0.gemfile +0 -6
- data/gemfiles/4.1.gemfile +0 -6
- data/gemfiles/4.2.gemfile +0 -6
- data/gemfiles/rails_edge.gemfile +0 -6
data/test/test_helper.rb
CHANGED
@@ -5,14 +5,29 @@ require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
|
5
5
|
|
6
6
|
require 'test/unit'
|
7
7
|
require 'mocha'
|
8
|
-
|
9
|
-
|
10
|
-
require 'test_help'
|
11
|
-
else
|
12
|
-
require 'rails/test_help'
|
13
|
-
require 'mocha/test_unit'
|
14
|
-
end
|
8
|
+
require 'rails/test_help'
|
9
|
+
require 'mocha/test_unit'
|
15
10
|
|
16
11
|
require 'wicked_pdf'
|
17
12
|
|
18
13
|
Rails.backtrace_cleaner.remove_silencers!
|
14
|
+
|
15
|
+
if (assets_dir = Rails.root.join('app/assets')) && File.directory?(assets_dir)
|
16
|
+
# Copy CSS file
|
17
|
+
destination = assets_dir.join('stylesheets/wicked.css')
|
18
|
+
source = File.read('test/fixtures/wicked.css')
|
19
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
20
|
+
|
21
|
+
# Copy JS file
|
22
|
+
js_dir = assets_dir.join('javascripts')
|
23
|
+
Dir.mkdir(js_dir) unless File.directory?(js_dir)
|
24
|
+
destination = js_dir.join('wicked.js')
|
25
|
+
source = File.read('test/fixtures/wicked.js')
|
26
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
27
|
+
|
28
|
+
config_dir = assets_dir.join('config')
|
29
|
+
Dir.mkdir(config_dir) unless File.directory?(config_dir)
|
30
|
+
source = File.read('test/fixtures/manifest.js')
|
31
|
+
destination = config_dir.join('manifest.js')
|
32
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class WickedPdfBinaryTest < ActiveSupport::TestCase
|
4
|
+
test 'should extract old wkhtmltopdf version' do
|
5
|
+
version_info_sample = "Name:\n wkhtmltopdf 0.9.9\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
|
6
|
+
assert_equal WickedPdf::DEFAULT_BINARY_VERSION, binary.parse_version_string(version_info_sample)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should extract new wkhtmltopdf version' do
|
10
|
+
version_info_sample = "Name:\n wkhtmltopdf 0.11.0 rc2\n\nLicense:\n Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.\n\n\n\n License LGPLv3+: GNU Lesser General Public License version 3 or later\n <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to\n change and redistribute it. There is NO WARRANTY, to the extent permitted by\n law.\n\nAuthors:\n Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by\n Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and\n Mario Silva."
|
11
|
+
assert_equal Gem::Version.new('0.11.0'), binary.parse_version_string(version_info_sample)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'should extract wkhtmltopdf version with nondigit symbols' do
|
15
|
+
version_info_sample = "Name:\n wkhtmltopdf 0.10.4b\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
|
16
|
+
assert_equal Gem::Version.new('0.10.4b'), binary.parse_version_string(version_info_sample)
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'should fallback to default version on parse error' do
|
20
|
+
assert_equal WickedPdf::DEFAULT_BINARY_VERSION, binary.parse_version_string('')
|
21
|
+
end
|
22
|
+
|
23
|
+
def binary(path = nil)
|
24
|
+
WickedPdf::Binary.new(path)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class WickedPdfOptionParserTest < ActiveSupport::TestCase
|
4
|
+
test 'should parse header and footer options' do
|
5
|
+
%i[header footer].each do |hf|
|
6
|
+
%i[center font_name left right].each do |o|
|
7
|
+
assert_equal "--#{hf}-#{o.to_s.tr('_', '-')} header_footer",
|
8
|
+
parse_options(hf => { o => 'header_footer' }).strip
|
9
|
+
end
|
10
|
+
|
11
|
+
%i[font_size spacing].each do |o|
|
12
|
+
assert_equal "--#{hf}-#{o.to_s.tr('_', '-')} 12",
|
13
|
+
parse_options(hf => { o => '12' }).strip
|
14
|
+
end
|
15
|
+
|
16
|
+
assert_equal "--#{hf}-line",
|
17
|
+
parse_options(hf => { :line => true }).strip
|
18
|
+
assert_equal "--#{hf}-html http://www.abc.com",
|
19
|
+
parse_options(hf => { :html => { :url => 'http://www.abc.com' } }).strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should parse toc options' do
|
24
|
+
toc_option = option_parser.valid_option('toc')
|
25
|
+
|
26
|
+
%i[font_name header_text].each do |o|
|
27
|
+
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} toc",
|
28
|
+
parse_options(:toc => { o => 'toc' }).strip
|
29
|
+
end
|
30
|
+
|
31
|
+
%i[
|
32
|
+
depth header_fs l1_font_size l2_font_size l3_font_size l4_font_size
|
33
|
+
l5_font_size l6_font_size l7_font_size l1_indentation l2_indentation
|
34
|
+
l3_indentation l4_indentation l5_indentation l6_indentation l7_indentation
|
35
|
+
].each do |o|
|
36
|
+
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} 5",
|
37
|
+
parse_options(:toc => { o => 5 }).strip
|
38
|
+
end
|
39
|
+
|
40
|
+
%i[no_dots disable_links disable_back_links].each do |o|
|
41
|
+
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')}",
|
42
|
+
parse_options(:toc => { o => true }).strip
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'should parse outline options' do
|
47
|
+
assert_equal '--outline', parse_options(:outline => { :outline => true }).strip
|
48
|
+
assert_equal '--outline-depth 5', parse_options(:outline => { :outline_depth => 5 }).strip
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'should parse no_images option' do
|
52
|
+
assert_equal '--no-images', parse_options(:no_images => true).strip
|
53
|
+
assert_equal '--images', parse_options(:images => true).strip
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'should parse margins options' do
|
57
|
+
%i[top bottom left right].each do |o|
|
58
|
+
assert_equal "--margin-#{o} 12", parse_options(:margin => { o => '12' }).strip
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'should parse cover' do
|
63
|
+
cover_option = option_parser.valid_option('cover')
|
64
|
+
|
65
|
+
pathname = Rails.root.join('app', 'views', 'pdf', 'file.html')
|
66
|
+
assert_equal "#{cover_option} http://example.org", parse_options(:cover => 'http://example.org').strip, 'URL'
|
67
|
+
assert_equal "#{cover_option} #{pathname}", parse_options(:cover => pathname).strip, 'Pathname'
|
68
|
+
assert_match(/#{cover_option} .+wicked_cover_pdf.+\.html/, parse_options(:cover => '<html><body>HELLO</body></html>').strip, 'HTML')
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'should parse other options' do
|
72
|
+
%i[
|
73
|
+
orientation page_size proxy username password dpi
|
74
|
+
encoding user_style_sheet
|
75
|
+
].each do |o|
|
76
|
+
assert_equal "--#{o.to_s.tr('_', '-')} opts", parse_options(o => 'opts').strip
|
77
|
+
end
|
78
|
+
|
79
|
+
%i[cookie post].each do |o|
|
80
|
+
assert_equal "--#{o.to_s.tr('_', '-')} name value", parse_options(o => 'name value').strip
|
81
|
+
|
82
|
+
nv_formatter = proc { |number| "--#{o.to_s.tr('_', '-')} par#{number} val#{number}" }
|
83
|
+
assert_equal "#{nv_formatter.call(1)} #{nv_formatter.call(2)}", parse_options(o => ['par1 val1', 'par2 val2']).strip
|
84
|
+
end
|
85
|
+
|
86
|
+
%i[redirect_delay zoom page_offset].each do |o|
|
87
|
+
assert_equal "--#{o.to_s.tr('_', '-')} 5", parse_options(o => 5).strip
|
88
|
+
end
|
89
|
+
|
90
|
+
%i[
|
91
|
+
book default_header disable_javascript grayscale lowquality
|
92
|
+
enable_plugins disable_internal_links disable_external_links
|
93
|
+
print_media_type disable_smart_shrinking use_xserver no_background
|
94
|
+
].each do |o|
|
95
|
+
assert_equal "--#{o.to_s.tr('_', '-')}", parse_options(o => true).strip
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'should not use double dash options for version without dashes' do
|
100
|
+
op = option_parser(WickedPdf::OptionParser::BINARY_VERSION_WITHOUT_DASHES)
|
101
|
+
|
102
|
+
%w[toc cover].each do |name|
|
103
|
+
assert_equal op.valid_option(name), name
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
test 'should use double dash options for version with dashes' do
|
108
|
+
op = option_parser(Gem::Version.new('0.11.0'))
|
109
|
+
|
110
|
+
%w[toc cover].each do |name|
|
111
|
+
assert_equal op.valid_option(name), "--#{name}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
test '-- options should not be given after object' do
|
116
|
+
options = { :header => { :center => 3 }, :cover => 'http://example.org', :disable_javascript => true }
|
117
|
+
cover_option = option_parser.valid_option('cover')
|
118
|
+
assert_equal parse_options(options), "--disable-javascript --header-center 3 #{cover_option} http://example.org"
|
119
|
+
end
|
120
|
+
|
121
|
+
def parse_options(options, version = WickedPdf::DEFAULT_BINARY_VERSION)
|
122
|
+
option_parser(version).parse(options).join(' ')
|
123
|
+
end
|
124
|
+
|
125
|
+
def option_parser(version = WickedPdf::DEFAULT_BINARY_VERSION)
|
126
|
+
WickedPdf::OptionParser.new(version)
|
127
|
+
end
|
128
|
+
end
|
@@ -1,24 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
3
2
|
WickedPdf.config = { :exe_path => ENV['WKHTMLTOPDF_BIN'] || '/usr/local/bin/wkhtmltopdf' }
|
4
|
-
HTML_DOCUMENT = '<html><body>Hello World</body></html>'
|
5
|
-
|
6
|
-
# Provide a public accessor to the normally-private parse_options function.
|
7
|
-
# Also, smash the returned array of options into a single string for
|
8
|
-
# convenience in testing below.
|
9
|
-
class WickedPdf
|
10
|
-
def get_parsed_options(opts)
|
11
|
-
parse_options(opts).join(' ')
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_valid_option(name)
|
15
|
-
valid_option(name)
|
16
|
-
end
|
17
|
-
|
18
|
-
def set_binary_version_to(version)
|
19
|
-
@binary_version = version
|
20
|
-
end
|
21
|
-
end
|
3
|
+
HTML_DOCUMENT = '<html><body>Hello World</body></html>'.freeze
|
22
4
|
|
23
5
|
class WickedPdfTest < ActiveSupport::TestCase
|
24
6
|
def setup
|
@@ -26,26 +8,23 @@ class WickedPdfTest < ActiveSupport::TestCase
|
|
26
8
|
end
|
27
9
|
|
28
10
|
test 'should generate PDF from html document' do
|
29
|
-
|
30
|
-
pdf = wp.pdf_from_string HTML_DOCUMENT
|
11
|
+
pdf = @wp.pdf_from_string HTML_DOCUMENT
|
31
12
|
assert pdf.start_with?('%PDF-1.4')
|
32
13
|
assert pdf.rstrip.end_with?('%%EOF')
|
33
14
|
assert pdf.length > 100
|
34
15
|
end
|
35
16
|
|
36
17
|
test 'should generate PDF from html document with long lines' do
|
37
|
-
wp = WickedPdf.new
|
38
18
|
document_with_long_line_file = File.new('test/fixtures/document_with_long_line.html', 'r')
|
39
|
-
pdf = wp.pdf_from_string(document_with_long_line_file.read)
|
19
|
+
pdf = @wp.pdf_from_string(document_with_long_line_file.read)
|
40
20
|
assert pdf.start_with?('%PDF-1.4')
|
41
21
|
assert pdf.rstrip.end_with?('%%EOF')
|
42
22
|
assert pdf.length > 100
|
43
23
|
end
|
44
24
|
|
45
25
|
test 'should generate PDF from html existing HTML file without converting it to string' do
|
46
|
-
wp = WickedPdf.new
|
47
26
|
filepath = File.join(Dir.pwd, 'test/fixtures/document_with_long_line.html')
|
48
|
-
pdf = wp.pdf_from_html_file(filepath)
|
27
|
+
pdf = @wp.pdf_from_html_file(filepath)
|
49
28
|
assert pdf.start_with?('%PDF-1.4')
|
50
29
|
assert pdf.rstrip.end_with?('%%EOF')
|
51
30
|
assert pdf.length > 100
|
@@ -67,7 +46,7 @@ class WickedPdfTest < ActiveSupport::TestCase
|
|
67
46
|
begin
|
68
47
|
tmp = Tempfile.new('wkhtmltopdf')
|
69
48
|
fp = tmp.path
|
70
|
-
File.chmod
|
49
|
+
File.chmod 0o000, fp
|
71
50
|
assert_raise RuntimeError do
|
72
51
|
WickedPdf.new fp
|
73
52
|
end
|
@@ -80,7 +59,7 @@ class WickedPdfTest < ActiveSupport::TestCase
|
|
80
59
|
begin
|
81
60
|
tmp = Tempfile.new('wkhtmltopdf')
|
82
61
|
fp = tmp.path
|
83
|
-
File.chmod
|
62
|
+
File.chmod 0o777, fp
|
84
63
|
wp = WickedPdf.new fp
|
85
64
|
assert_raise RuntimeError do
|
86
65
|
wp.pdf_from_string HTML_DOCUMENT
|
@@ -90,148 +69,15 @@ class WickedPdfTest < ActiveSupport::TestCase
|
|
90
69
|
end
|
91
70
|
end
|
92
71
|
|
93
|
-
test 'should
|
94
|
-
wp = WickedPdf.new
|
95
|
-
|
96
|
-
[:header, :footer].each do |hf|
|
97
|
-
[:center, :font_name, :left, :right].each do |o|
|
98
|
-
assert_equal "--#{hf}-#{o.to_s.tr('_', '-')} header_footer",
|
99
|
-
wp.get_parsed_options(hf => { o => 'header_footer' }).strip
|
100
|
-
end
|
101
|
-
|
102
|
-
[:font_size, :spacing].each do |o|
|
103
|
-
assert_equal "--#{hf}-#{o.to_s.tr('_', '-')} 12",
|
104
|
-
wp.get_parsed_options(hf => { o => '12' }).strip
|
105
|
-
end
|
106
|
-
|
107
|
-
assert_equal "--#{hf}-line",
|
108
|
-
wp.get_parsed_options(hf => { :line => true }).strip
|
109
|
-
assert_equal "--#{hf}-html http://www.abc.com",
|
110
|
-
wp.get_parsed_options(hf => { :html => { :url => 'http://www.abc.com' } }).strip
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
test 'should parse toc options' do
|
115
|
-
wp = WickedPdf.new
|
116
|
-
toc_option = wp.get_valid_option('toc')
|
117
|
-
|
118
|
-
[:font_name, :header_text].each do |o|
|
119
|
-
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} toc",
|
120
|
-
wp.get_parsed_options(:toc => { o => 'toc' }).strip
|
121
|
-
end
|
122
|
-
|
123
|
-
[
|
124
|
-
:depth, :header_fs, :l1_font_size, :l2_font_size, :l3_font_size, :l4_font_size,
|
125
|
-
:l5_font_size, :l6_font_size, :l7_font_size, :l1_indentation, :l2_indentation,
|
126
|
-
:l3_indentation, :l4_indentation, :l5_indentation, :l6_indentation, :l7_indentation
|
127
|
-
].each do |o|
|
128
|
-
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} 5",
|
129
|
-
wp.get_parsed_options(:toc => { o => 5 }).strip
|
130
|
-
end
|
131
|
-
|
132
|
-
[:no_dots, :disable_links, :disable_back_links].each do |o|
|
133
|
-
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')}",
|
134
|
-
wp.get_parsed_options(:toc => { o => true }).strip
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
test 'should parse outline options' do
|
139
|
-
wp = WickedPdf.new
|
140
|
-
|
141
|
-
assert_equal '--outline', wp.get_parsed_options(:outline => { :outline => true }).strip
|
142
|
-
assert_equal '--outline-depth 5', wp.get_parsed_options(:outline => { :outline_depth => 5 }).strip
|
143
|
-
end
|
144
|
-
|
145
|
-
test 'should parse margins options' do
|
146
|
-
wp = WickedPdf.new
|
147
|
-
|
148
|
-
[:top, :bottom, :left, :right].each do |o|
|
149
|
-
assert_equal "--margin-#{o} 12", wp.get_parsed_options(:margin => { o => '12' }).strip
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
test 'should parse cover' do
|
72
|
+
test 'should output progress when creating pdfs on compatible hosts' do
|
154
73
|
wp = WickedPdf.new
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
test 'should parse other options' do
|
164
|
-
wp = WickedPdf.new
|
165
|
-
|
166
|
-
[
|
167
|
-
:orientation, :page_size, :proxy, :username, :password, :dpi,
|
168
|
-
:encoding, :user_style_sheet
|
169
|
-
].each do |o|
|
170
|
-
assert_equal "--#{o.to_s.tr('_', '-')} opts", wp.get_parsed_options(o => 'opts').strip
|
171
|
-
end
|
172
|
-
|
173
|
-
[:cookie, :post].each do |o|
|
174
|
-
assert_equal "--#{o.to_s.tr('_', '-')} name value", wp.get_parsed_options(o => 'name value').strip
|
175
|
-
|
176
|
-
nv_formatter = proc { |number| "--#{o.to_s.tr('_', '-')} par#{number} val#{number}" }
|
177
|
-
assert_equal "#{nv_formatter.call(1)} #{nv_formatter.call(2)}", wp.get_parsed_options(o => ['par1 val1', 'par2 val2']).strip
|
74
|
+
output = []
|
75
|
+
options = { :progress => proc { |o| output << o } }
|
76
|
+
wp.pdf_from_string HTML_DOCUMENT, options
|
77
|
+
if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
78
|
+
assert_empty output
|
79
|
+
else
|
80
|
+
assert(output.collect { |l| !l.match(/Loading/).nil? }.include?(true)) # should output something like "Loading pages (1/5)"
|
178
81
|
end
|
179
|
-
|
180
|
-
[:redirect_delay, :zoom, :page_offset].each do |o|
|
181
|
-
assert_equal "--#{o.to_s.tr('_', '-')} 5", wp.get_parsed_options(o => 5).strip
|
182
|
-
end
|
183
|
-
|
184
|
-
[
|
185
|
-
:book, :default_header, :disable_javascript, :grayscale, :lowquality,
|
186
|
-
:enable_plugins, :disable_internal_links, :disable_external_links,
|
187
|
-
:print_media_type, :disable_smart_shrinking, :use_xserver, :no_background
|
188
|
-
].each do |o|
|
189
|
-
assert_equal "--#{o.to_s.tr('_', '-')}", wp.get_parsed_options(o => true).strip
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
test 'should extract old wkhtmltopdf version' do
|
194
|
-
version_info_sample = "Name:\n wkhtmltopdf 0.9.9\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
|
195
|
-
assert_equal WickedPdf::DEFAULT_BINARY_VERSION, @wp.send(:parse_version, version_info_sample)
|
196
|
-
end
|
197
|
-
|
198
|
-
test 'should extract new wkhtmltopdf version' do
|
199
|
-
version_info_sample = "Name:\n wkhtmltopdf 0.11.0 rc2\n\nLicense:\n Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.\n\n\n\n License LGPLv3+: GNU Lesser General Public License version 3 or later\n <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to\n change and redistribute it. There is NO WARRANTY, to the extent permitted by\n law.\n\nAuthors:\n Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by\n Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and\n Mario Silva."
|
200
|
-
assert_equal Gem::Version.new('0.11.0'), @wp.send(:parse_version, version_info_sample)
|
201
|
-
end
|
202
|
-
|
203
|
-
test 'should extract wkhtmltopdf version with nondigit symbols' do
|
204
|
-
version_info_sample = "Name:\n wkhtmltopdf 0.10.4b\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
|
205
|
-
assert_equal Gem::Version.new('0.10.4b'), @wp.send(:parse_version, version_info_sample)
|
206
|
-
end
|
207
|
-
|
208
|
-
test 'should fallback to default version on parse error' do
|
209
|
-
assert_equal WickedPdf::DEFAULT_BINARY_VERSION, @wp.send(:parse_version, '')
|
210
|
-
end
|
211
|
-
|
212
|
-
test 'should set version on initialize' do
|
213
|
-
assert_not_equal @wp.send(:get_binary_version), ''
|
214
|
-
end
|
215
|
-
|
216
|
-
test 'should not use double dash options for version without dashes' do
|
217
|
-
@wp.set_binary_version_to(WickedPdf::BINARY_VERSION_WITHOUT_DASHES)
|
218
|
-
|
219
|
-
%w(toc cover).each do |name|
|
220
|
-
assert_equal @wp.get_valid_option(name), name
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
test 'should use double dash options for version with dashes' do
|
225
|
-
@wp.set_binary_version_to(Gem::Version.new('0.11.0'))
|
226
|
-
|
227
|
-
%w(toc cover).each do |name|
|
228
|
-
assert_equal @wp.get_valid_option(name), "--#{name}"
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
test '-- options should not be given after object' do
|
233
|
-
options = { :header => { :center => 3 }, :cover => 'http://example.org', :disable_javascript => true }
|
234
|
-
cover_option = @wp.get_valid_option('cover')
|
235
|
-
assert_equal @wp.get_parsed_options(options), "--disable-javascript --header-center 3 #{cover_option} http://example.org"
|
236
82
|
end
|
237
83
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class WkhtmltopdfLocationTest < ActiveSupport::TestCase
|
2
|
+
setup do
|
3
|
+
@saved_config = WickedPdf.config
|
4
|
+
WickedPdf.config = {}
|
5
|
+
end
|
6
|
+
|
7
|
+
teardown do
|
8
|
+
WickedPdf.config = @saved_config
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'should correctly locate wkhtmltopdf without bundler' do
|
12
|
+
bundler_module = Bundler
|
13
|
+
Object.send(:remove_const, :Bundler)
|
14
|
+
|
15
|
+
assert_nothing_raised do
|
16
|
+
WickedPdf.new
|
17
|
+
end
|
18
|
+
|
19
|
+
Object.const_set(:Bundler, bundler_module)
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'should correctly locate wkhtmltopdf with bundler' do
|
23
|
+
assert_nothing_raised do
|
24
|
+
WickedPdf.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class LocationNonWritableTest < ActiveSupport::TestCase
|
29
|
+
setup do
|
30
|
+
@saved_config = WickedPdf.config
|
31
|
+
WickedPdf.config = {}
|
32
|
+
|
33
|
+
@old_home = ENV['HOME']
|
34
|
+
ENV['HOME'] = '/not/a/writable/directory'
|
35
|
+
end
|
36
|
+
|
37
|
+
teardown do
|
38
|
+
WickedPdf.config = @saved_config
|
39
|
+
ENV['HOME'] = @old_home
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'should correctly locate wkhtmltopdf with bundler while HOME is set to a non-writable directory' do
|
43
|
+
assert_nothing_raised do
|
44
|
+
WickedPdf.new
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/wicked_pdf.gemspec
CHANGED
@@ -1,34 +1,40 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'wicked_pdf/version'
|
4
|
+
require 'English'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'wicked_pdf'
|
8
8
|
spec.version = WickedPdf::VERSION
|
9
|
-
spec.authors = ['Miles Z. Sterrett']
|
10
|
-
spec.email = 'miles.sterrett@gmail.com'
|
9
|
+
spec.authors = ['Miles Z. Sterrett', 'David Jones']
|
10
|
+
spec.email = ['miles.sterrett@gmail.com', 'unixmonkey1@gmail.com']
|
11
11
|
spec.summary = 'PDF generator (from HTML) gem for Ruby on Rails'
|
12
12
|
spec.homepage = 'https://github.com/mileszs/wicked_pdf'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
spec.date = Time.now.strftime('%Y-%m-%d')
|
15
|
+
spec.description = <<DESC.gsub(/^\s+/, '')
|
16
|
+
Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML.
|
17
|
+
In other words, rather than dealing with a PDF generation DSL of some sort,
|
18
|
+
you simply write an HTML view as you would normally, and let Wicked take care of the hard stuff.
|
19
|
+
DESC
|
20
|
+
spec.metadata = {
|
21
|
+
'changelog_uri' => 'https://github.com/mileszs/wicked_pdf/blob/master/CHANGELOG.md'
|
22
|
+
}
|
15
23
|
|
24
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.2')
|
16
25
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
26
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
27
|
spec.require_paths = ['lib']
|
20
28
|
|
29
|
+
spec.requirements << 'wkhtmltopdf'
|
30
|
+
|
31
|
+
spec.add_dependency 'activesupport'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler'
|
34
|
+
spec.add_development_dependency 'mocha', '= 1.3'
|
21
35
|
spec.add_development_dependency 'rails'
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
36
|
spec.add_development_dependency 'rake'
|
24
|
-
spec.add_development_dependency 'rubocop'
|
25
|
-
spec.add_development_dependency 'sqlite3'
|
26
|
-
spec.add_development_dependency 'mocha'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 1.24'
|
38
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
27
39
|
spec.add_development_dependency 'test-unit'
|
28
|
-
|
29
|
-
spec.description = <<desc
|
30
|
-
Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML.
|
31
|
-
In other words, rather than dealing with a PDF generation DSL of some sort,
|
32
|
-
you simply write an HTML view as you would normally, and let Wicked take care of the hard stuff.
|
33
|
-
desc
|
34
40
|
end
|