nano-pro-lib 0.0.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 +7 -0
- data/nano-pro-lib.gemspec +11 -0
- data/wicked_pdf-2.8.2/CHANGELOG.md +254 -0
- data/wicked_pdf-2.8.2/Gemfile +3 -0
- data/wicked_pdf-2.8.2/LICENSE.txt +22 -0
- data/wicked_pdf-2.8.2/README.md +504 -0
- data/wicked_pdf-2.8.2/Rakefile +58 -0
- data/wicked_pdf-2.8.2/gemfiles/5.0.gemfile +8 -0
- data/wicked_pdf-2.8.2/gemfiles/5.1.gemfile +8 -0
- data/wicked_pdf-2.8.2/gemfiles/5.2.gemfile +9 -0
- data/wicked_pdf-2.8.2/gemfiles/6.0.gemfile +10 -0
- data/wicked_pdf-2.8.2/gemfiles/6.1.gemfile +11 -0
- data/wicked_pdf-2.8.2/gemfiles/7.0.gemfile +11 -0
- data/wicked_pdf-2.8.2/generators/wicked_pdf/templates/wicked_pdf.rb +30 -0
- data/wicked_pdf-2.8.2/generators/wicked_pdf/wicked_pdf_generator.rb +7 -0
- data/wicked_pdf-2.8.2/init.rb +2 -0
- data/wicked_pdf-2.8.2/lib/generators/wicked_pdf_generator.rb +7 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/binary.rb +65 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/middleware.rb +92 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/option_parser.rb +230 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/pdf_helper.rb +128 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/progress.rb +33 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/railtie.rb +17 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/tempfile.rb +43 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/version.rb +3 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/wicked_pdf_helper/assets.rb +332 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/wicked_pdf_helper.rb +36 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf.rb +132 -0
- data/wicked_pdf-2.8.2/test/fixtures/database.yml +4 -0
- data/wicked_pdf-2.8.2/test/fixtures/document_with_long_line.html +16 -0
- data/wicked_pdf-2.8.2/test/fixtures/manifest.js +3 -0
- data/wicked_pdf-2.8.2/test/fixtures/subdirectory/nested.js +1 -0
- data/wicked_pdf-2.8.2/test/fixtures/wicked.css +1 -0
- data/wicked_pdf-2.8.2/test/fixtures/wicked.js +1 -0
- data/wicked_pdf-2.8.2/test/functional/pdf_helper_test.rb +96 -0
- data/wicked_pdf-2.8.2/test/functional/wicked_pdf_helper_assets_test.rb +252 -0
- data/wicked_pdf-2.8.2/test/functional/wicked_pdf_helper_test.rb +28 -0
- data/wicked_pdf-2.8.2/test/test_helper.rb +40 -0
- data/wicked_pdf-2.8.2/test/unit/wicked_pdf_binary_test.rb +26 -0
- data/wicked_pdf-2.8.2/test/unit/wicked_pdf_option_parser_test.rb +133 -0
- data/wicked_pdf-2.8.2/test/unit/wicked_pdf_test.rb +100 -0
- data/wicked_pdf-2.8.2/test/unit/wkhtmltopdf_location_test.rb +48 -0
- data/wicked_pdf-2.8.2/wicked_pdf.gemspec +42 -0
- metadata +82 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'action_view/test_case'
|
|
3
|
+
|
|
4
|
+
class WickedPdfHelperAssetsTest < ActionView::TestCase
|
|
5
|
+
include WickedPdf::WickedPdfHelper::Assets
|
|
6
|
+
|
|
7
|
+
setup do
|
|
8
|
+
@saved_config = WickedPdf.config
|
|
9
|
+
WickedPdf.config = {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
teardown do
|
|
13
|
+
WickedPdf.config = @saved_config
|
|
14
|
+
|
|
15
|
+
# @see freerange/mocha#331
|
|
16
|
+
Rails.application.unstub(:assets)
|
|
17
|
+
Rails.application.unstub(:assets_manifest)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if Rails::VERSION::MAJOR > 3 || (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0)
|
|
21
|
+
test 'wicked_pdf_asset_base64 returns a base64 encoded asset' do
|
|
22
|
+
assert_match %r{data:text\/css;base64,.+}, wicked_pdf_asset_base64('wicked.css')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'wicked_pdf_asset_base64 works without file extension when using sprockets' do
|
|
26
|
+
assert_match %r{data:application\/javascript;base64,.+}, wicked_pdf_asset_base64('wicked')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'wicked_pdf_asset_base64 works with nested files and without file extension when using sprockets' do
|
|
30
|
+
assert_match %r{data:application\/javascript;base64,.+}, wicked_pdf_asset_base64('subdirectory/nested')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test 'wicked_pdf_asset_base64 works without file extension when using asset manifest' do
|
|
34
|
+
stub_manifest = OpenStruct.new(
|
|
35
|
+
:dir => Rails.root.join('app/assets'),
|
|
36
|
+
:assets => { 'wicked.css' => 'stylesheets/wicked.css', 'wicked.js' => 'javascripts/wicked.js' }
|
|
37
|
+
)
|
|
38
|
+
Rails.application.stubs(:assets).returns(nil)
|
|
39
|
+
Rails.application.stubs(:assets_manifest).returns(stub_manifest)
|
|
40
|
+
|
|
41
|
+
assert_match %r{data:text\/css;base64,.+}, wicked_pdf_asset_base64('wicked')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
test 'wicked_pdf_asset_base64 works with nested files and without file extension when using asset manifest' do
|
|
45
|
+
stub_manifest = OpenStruct.new(
|
|
46
|
+
:dir => Rails.root.join('app/assets'),
|
|
47
|
+
:assets => { 'subdirectory/nested.js' => 'javascripts/subdirectory/nested.js' }
|
|
48
|
+
)
|
|
49
|
+
Rails.application.stubs(:assets).returns(nil)
|
|
50
|
+
Rails.application.stubs(:assets_manifest).returns(stub_manifest)
|
|
51
|
+
|
|
52
|
+
assert_match %r{data:text\/javascript;base64,.+}, wicked_pdf_asset_base64('subdirectory/nested')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in' do
|
|
56
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
57
|
+
assert_equal "<style type='text/css'>/* Wicked styles */\n\n</style>",
|
|
58
|
+
wicked_pdf_stylesheet_link_tag('wicked')
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
test 'wicked_pdf_stylesheet_link_tag should work without file extension when using sprockets' do
|
|
62
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
63
|
+
assert_equal "<style type='text/css'>/* Wicked styles */\n\n</style>",
|
|
64
|
+
wicked_pdf_stylesheet_link_tag('wicked')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
test 'wicked_pdf_stylesheet_link_tag should work without file extension when using asset manifest' do
|
|
68
|
+
stub_manifest = OpenStruct.new(
|
|
69
|
+
:dir => Rails.root.join('app/assets'),
|
|
70
|
+
:assets => { 'wicked.css' => 'stylesheets/wicked.css', 'wicked.js' => 'javascripts/wicked.js' }
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
Rails.application.stubs(:assets).returns(nil)
|
|
74
|
+
Rails.application.stubs(:assets_manifest).returns(stub_manifest)
|
|
75
|
+
|
|
76
|
+
assert_equal "<style type='text/css'>/* Wicked styles */\n</style>",
|
|
77
|
+
wicked_pdf_stylesheet_link_tag('wicked')
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
test 'wicked_pdf_stylesheet_link_tag should raise if the stylesheet is not available and config is set' do
|
|
81
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
82
|
+
WickedPdf.config[:raise_on_missing_assets] = true
|
|
83
|
+
assert_raise WickedPdf::WickedPdfHelper::Assets::MissingLocalAsset do
|
|
84
|
+
wicked_pdf_stylesheet_link_tag('non_existent')
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
test 'wicked_pdf_stylesheet_link_tag should return empty if the stylesheet is not available' do
|
|
89
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
90
|
+
assert_equal "<style type='text/css'></style>",
|
|
91
|
+
wicked_pdf_stylesheet_link_tag('non_existent')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
test 'wicked_pdf_stylesheet_link_tag should raise if the absolute path stylesheet is not available and config is set' do
|
|
95
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
96
|
+
WickedPdf.config[:raise_on_missing_assets] = true
|
|
97
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
98
|
+
assert_raise WickedPdf::WickedPdfHelper::Assets::MissingLocalAsset do
|
|
99
|
+
wicked_pdf_stylesheet_link_tag('/non_existent')
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
test 'wicked_pdf_stylesheet_link_tag should return empty if the absolute path stylesheet is not available' do
|
|
104
|
+
Rails.configuration.assets.expects(:compile => true).twice
|
|
105
|
+
assert_equal "<style type='text/css'></style>",
|
|
106
|
+
wicked_pdf_stylesheet_link_tag('/non_existent')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in when assets are remote' do
|
|
110
|
+
stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 200, :body => '/* Wicked styles */')
|
|
111
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
112
|
+
assert_equal "<style type='text/css'>/* Wicked styles */</style>",
|
|
113
|
+
wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in when assets are remote and using asset manifest' do
|
|
117
|
+
stub_manifest = OpenStruct.new(
|
|
118
|
+
:dir => Rails.root.join('app/assets'),
|
|
119
|
+
:assets => { 'wicked.css' => 'stylesheets/wicked.css', 'wicked.js' => 'javascripts/wicked.js' }
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
Rails.application.stubs(:assets).returns(nil)
|
|
123
|
+
Rails.application.stubs(:assets_manifest).returns(stub_manifest)
|
|
124
|
+
|
|
125
|
+
stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 200, :body => '/* Wicked styles */')
|
|
126
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
127
|
+
assert_equal "<style type='text/css'>/* Wicked styles */</style>",
|
|
128
|
+
wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
test 'wicked_pdf_stylesheet_link_tag should raise if remote assets are not available and config is set' do
|
|
132
|
+
WickedPdf.config[:raise_on_missing_assets] = true
|
|
133
|
+
stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 404, :body => 'File not found')
|
|
134
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
135
|
+
assert_raise WickedPdf::WickedPdfHelper::Assets::MissingRemoteAsset do
|
|
136
|
+
wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
test 'wicked_pdf_stylesheet_link_tag should return empty if remote assets are not available' do
|
|
141
|
+
stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 404, :body => 'File not found')
|
|
142
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
143
|
+
assert_equal "<style type='text/css'></style>",
|
|
144
|
+
wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
test 'wicked_pdf_image_tag should return the same as image_tag when passed a full path' do
|
|
148
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
149
|
+
assert_equal image_tag("file:///#{Rails.root.join('public', 'pdf')}"),
|
|
150
|
+
wicked_pdf_image_tag('pdf')
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
test 'wicked_pdf_javascript_include_tag should inline the javascripts passed in' do
|
|
154
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
155
|
+
assert_equal "<script type='text/javascript'>// Wicked js\n;\n</script>",
|
|
156
|
+
wicked_pdf_javascript_include_tag('wicked')
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
test 'wicked_pdf_asset_path should return a url when assets are served by an asset server' do
|
|
160
|
+
expects(:asset_pathname => 'http://assets.domain.com/dummy.png')
|
|
161
|
+
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
test 'wicked_pdf_asset_path should return a url when assets are served by an asset server using HTTPS' do
|
|
165
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
166
|
+
expects(:asset_path => 'https://assets.domain.com/dummy.png')
|
|
167
|
+
assert_equal 'https://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
test 'wicked_pdf_asset_path should return a url with a protocol when assets are served by an asset server with relative urls' do
|
|
171
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
172
|
+
expects(:asset_path => '//assets.domain.com/dummy.png')
|
|
173
|
+
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
test 'wicked_pdf_asset_path should return a url with a protocol when assets are served by an asset server with no protocol set' do
|
|
177
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
178
|
+
expects(:asset_path => 'assets.domain.com/dummy.png')
|
|
179
|
+
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
test 'wicked_pdf_asset_path should return a path' do
|
|
183
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
184
|
+
path = wicked_pdf_asset_path('application.css')
|
|
185
|
+
|
|
186
|
+
assert path.include?('/app/assets/stylesheets/application.css')
|
|
187
|
+
assert path.include?('file:///')
|
|
188
|
+
|
|
189
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
190
|
+
expects(:asset_path => '/assets/application-6fba03f13d6ff1553477dba03475c4b9b02542e9fb8913bd63c258f4de5b48d9.css')
|
|
191
|
+
path = wicked_pdf_asset_path('application.css')
|
|
192
|
+
|
|
193
|
+
assert path.include?('/public/assets/application-6fba03f13d6ff1553477dba03475c4b9b02542e9fb8913bd63c258f4de5b48d9.css')
|
|
194
|
+
assert path.include?('file:///')
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# This assets does not exists so probably it doesn't matter what is
|
|
198
|
+
# returned, but lets ensure that returned value is the same when assets
|
|
199
|
+
# are precompiled and when they are not
|
|
200
|
+
test 'wicked_pdf_asset_path should return a path when asset does not exist' do
|
|
201
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
202
|
+
path = wicked_pdf_asset_path('missing.png')
|
|
203
|
+
|
|
204
|
+
assert path.include?('/public/missing.png')
|
|
205
|
+
assert path.include?('file:///')
|
|
206
|
+
|
|
207
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
208
|
+
expects(:asset_path => '/missing.png')
|
|
209
|
+
path = wicked_pdf_asset_path('missing.png')
|
|
210
|
+
|
|
211
|
+
assert path.include?('/public/missing.png')
|
|
212
|
+
assert path.include?('file:///')
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
test 'wicked_pdf_asset_path should return a url when asset is url' do
|
|
216
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
217
|
+
expects(:asset_path => 'http://example.com/rails.png')
|
|
218
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('http://example.com/rails.png')
|
|
219
|
+
|
|
220
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
221
|
+
expects(:asset_path => 'http://example.com/rails.png')
|
|
222
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('http://example.com/rails.png')
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
test 'wicked_pdf_asset_path should return a url when asset is url without protocol' do
|
|
226
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
227
|
+
expects(:asset_path => '//example.com/rails.png')
|
|
228
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('//example.com/rails.png')
|
|
229
|
+
|
|
230
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
231
|
+
expects(:asset_path => '//example.com/rails.png')
|
|
232
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('//example.com/rails.png')
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
test 'WickedPdfHelper::Assets::ASSET_URL_REGEX should match various URL data type formats' do
|
|
236
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(\'/asset/stylesheets/application.css\');'
|
|
237
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url("/asset/stylesheets/application.css");'
|
|
238
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(/asset/stylesheets/application.css);'
|
|
239
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(\'http://assets.domain.com/dummy.png\');'
|
|
240
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url("http://assets.domain.com/dummy.png");'
|
|
241
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(http://assets.domain.com/dummy.png);'
|
|
242
|
+
assert_no_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, '.url { \'http://assets.domain.com/dummy.png\' }'
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
test 'prepend_protocol should properly set the protocol when the asset is precompiled' do
|
|
246
|
+
assert_equal 'http://assets.domain.com/dummy.png', prepend_protocol('//assets.domain.com/dummy.png')
|
|
247
|
+
assert_equal '/assets.domain.com/dummy.png', prepend_protocol('/assets.domain.com/dummy.png')
|
|
248
|
+
assert_equal 'http://assets.domain.com/dummy.png', prepend_protocol('http://assets.domain.com/dummy.png')
|
|
249
|
+
assert_equal 'https://assets.domain.com/dummy.png', prepend_protocol('https://assets.domain.com/dummy.png')
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'action_view/test_case'
|
|
3
|
+
|
|
4
|
+
class WickedPdfHelperTest < ActionView::TestCase
|
|
5
|
+
include WickedPdf::WickedPdfHelper
|
|
6
|
+
|
|
7
|
+
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in' do
|
|
8
|
+
assert_equal "<style type='text/css'>/* Wicked styles */\n</style>",
|
|
9
|
+
wicked_pdf_stylesheet_link_tag('../../../fixtures/wicked')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test 'wicked_pdf_image_tag should return the same as image_tag when passed a full path' do
|
|
13
|
+
assert_equal image_tag("file:///#{Rails.root.join('public', 'images', 'pdf')}"),
|
|
14
|
+
wicked_pdf_image_tag('pdf')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
if Rails::VERSION::MAJOR == 2
|
|
18
|
+
test 'wicked_pdf_javascript_src_tag should return the same as javascript_src_tag when passed a full path' do
|
|
19
|
+
assert_equal javascript_src_tag("file:///#{Rails.root.join('public', 'javascripts', 'pdf')}", {}),
|
|
20
|
+
wicked_pdf_javascript_src_tag('pdf')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test 'wicked_pdf_include_tag should return many wicked_pdf_javascript_src_tags' do
|
|
25
|
+
assert_equal [wicked_pdf_javascript_src_tag('foo'), wicked_pdf_javascript_src_tag('bar')].join("\n"),
|
|
26
|
+
wicked_pdf_javascript_include_tag('foo', 'bar')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Configure Rails Environment
|
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
|
5
|
+
|
|
6
|
+
require 'test/unit'
|
|
7
|
+
require 'mocha'
|
|
8
|
+
require 'rails/test_help'
|
|
9
|
+
require 'mocha/test_unit'
|
|
10
|
+
require 'webmock/minitest'
|
|
11
|
+
|
|
12
|
+
require 'wicked_pdf'
|
|
13
|
+
|
|
14
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
15
|
+
WickedPdf.silence_deprecations = true
|
|
16
|
+
|
|
17
|
+
if (assets_dir = Rails.root.join('app/assets')) && File.directory?(assets_dir)
|
|
18
|
+
# Copy CSS file
|
|
19
|
+
destination = assets_dir.join('stylesheets/wicked.css')
|
|
20
|
+
source = File.read('test/fixtures/wicked.css')
|
|
21
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
|
22
|
+
|
|
23
|
+
# Copy JS file
|
|
24
|
+
js_dir = assets_dir.join('javascripts')
|
|
25
|
+
Dir.mkdir(js_dir) unless File.directory?(js_dir)
|
|
26
|
+
destination = js_dir.join('wicked.js')
|
|
27
|
+
source = File.read('test/fixtures/wicked.js')
|
|
28
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
|
29
|
+
|
|
30
|
+
Dir.mkdir(js_dir.join('subdirectory')) unless File.directory?(js_dir.join('subdirectory'))
|
|
31
|
+
destination = js_dir.join('subdirectory/nested.js')
|
|
32
|
+
source = File.read('test/fixtures/subdirectory/nested.js')
|
|
33
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
|
34
|
+
|
|
35
|
+
config_dir = assets_dir.join('config')
|
|
36
|
+
Dir.mkdir(config_dir) unless File.directory?(config_dir)
|
|
37
|
+
source = File.read('test/fixtures/manifest.js')
|
|
38
|
+
destination = config_dir.join('manifest.js')
|
|
39
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
|
40
|
+
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,133 @@
|
|
|
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[allow].each do |o|
|
|
80
|
+
assert_equal "--#{o.to_s.tr('_', '-')} opts", parse_options(o => 'opts').strip
|
|
81
|
+
assert_equal "--#{o.to_s.tr('_', '-')} opts1 --#{o.to_s.tr('_', '-')} opts2", parse_options(o => %w[opts1 opts2]).strip
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
%i[cookie post].each do |o|
|
|
85
|
+
assert_equal "--#{o.to_s.tr('_', '-')} name value", parse_options(o => 'name value').strip
|
|
86
|
+
|
|
87
|
+
nv_formatter = proc { |number| "--#{o.to_s.tr('_', '-')} par#{number} val#{number}" }
|
|
88
|
+
assert_equal "#{nv_formatter.call(1)} #{nv_formatter.call(2)}", parse_options(o => ['par1 val1', 'par2 val2']).strip
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
%i[redirect_delay zoom page_offset].each do |o|
|
|
92
|
+
assert_equal "--#{o.to_s.tr('_', '-')} 5", parse_options(o => 5).strip
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
%i[
|
|
96
|
+
book default_header disable_javascript grayscale lowquality
|
|
97
|
+
enable_plugins disable_internal_links disable_external_links
|
|
98
|
+
print_media_type disable_smart_shrinking use_xserver no_background disable_local_file_access
|
|
99
|
+
].each do |o|
|
|
100
|
+
assert_equal "--#{o.to_s.tr('_', '-')}", parse_options(o => true).strip
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
test 'should not use double dash options for version without dashes' do
|
|
105
|
+
op = option_parser(WickedPdf::OptionParser::BINARY_VERSION_WITHOUT_DASHES)
|
|
106
|
+
|
|
107
|
+
%w[toc cover].each do |name|
|
|
108
|
+
assert_equal op.valid_option(name), name
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
test 'should use double dash options for version with dashes' do
|
|
113
|
+
op = option_parser(Gem::Version.new('0.11.0'))
|
|
114
|
+
|
|
115
|
+
%w[toc cover].each do |name|
|
|
116
|
+
assert_equal op.valid_option(name), "--#{name}"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
test '-- options should not be given after object' do
|
|
121
|
+
options = { :header => { :center => 3 }, :cover => 'http://example.org', :disable_javascript => true }
|
|
122
|
+
cover_option = option_parser.valid_option('cover')
|
|
123
|
+
assert_equal parse_options(options), "--disable-javascript --header-center 3 #{cover_option} http://example.org"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def parse_options(options, version = WickedPdf::DEFAULT_BINARY_VERSION)
|
|
127
|
+
option_parser(version).parse(options).join(' ')
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def option_parser(version = WickedPdf::DEFAULT_BINARY_VERSION)
|
|
131
|
+
WickedPdf::OptionParser.new(version)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
WickedPdf.config = { :exe_path => ENV['WKHTMLTOPDF_BIN'] || '/usr/local/bin/wkhtmltopdf' }
|
|
3
|
+
HTML_DOCUMENT = '<html><body>Hello World</body></html>'.freeze
|
|
4
|
+
|
|
5
|
+
class WickedPdfTest < ActiveSupport::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@wp = WickedPdf.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test 'should update config through .configure class method' do
|
|
11
|
+
WickedPdf.configure do |c|
|
|
12
|
+
c.test = 'foobar'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
assert WickedPdf.config == { :exe_path => ENV['WKHTMLTOPDF_BIN'] || '/usr/local/bin/wkhtmltopdf', :test => 'foobar' }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test 'should clear config through .clear_config class method' do
|
|
19
|
+
backup_config = WickedPdf.config
|
|
20
|
+
|
|
21
|
+
WickedPdf.clear_config
|
|
22
|
+
assert WickedPdf.config == {}
|
|
23
|
+
|
|
24
|
+
WickedPdf.config = backup_config
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'should generate PDF from html document' do
|
|
28
|
+
pdf = @wp.pdf_from_string HTML_DOCUMENT
|
|
29
|
+
assert pdf.start_with?('%PDF-1.4')
|
|
30
|
+
assert pdf.rstrip.end_with?('%%EOF')
|
|
31
|
+
assert pdf.length > 100
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
test 'should generate PDF from html document with long lines' do
|
|
35
|
+
document_with_long_line_file = File.new('test/fixtures/document_with_long_line.html', 'r')
|
|
36
|
+
pdf = @wp.pdf_from_string(document_with_long_line_file.read)
|
|
37
|
+
assert pdf.start_with?('%PDF-1.4')
|
|
38
|
+
assert pdf.rstrip.end_with?('%%EOF')
|
|
39
|
+
assert pdf.length > 100
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'should generate PDF from html existing HTML file without converting it to string' do
|
|
43
|
+
filepath = File.join(Dir.pwd, 'test/fixtures/document_with_long_line.html')
|
|
44
|
+
pdf = @wp.pdf_from_html_file(filepath)
|
|
45
|
+
assert pdf.start_with?('%PDF-1.4')
|
|
46
|
+
assert pdf.rstrip.end_with?('%%EOF')
|
|
47
|
+
assert pdf.length > 100
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test 'should raise exception when no path to wkhtmltopdf' do
|
|
51
|
+
assert_raise RuntimeError do
|
|
52
|
+
WickedPdf.new ' '
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
test 'should raise exception when wkhtmltopdf path is wrong' do
|
|
57
|
+
assert_raise RuntimeError do
|
|
58
|
+
WickedPdf.new '/i/do/not/exist/notwkhtmltopdf'
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test 'should raise exception when wkhtmltopdf is not executable' do
|
|
63
|
+
begin
|
|
64
|
+
tmp = Tempfile.new('wkhtmltopdf')
|
|
65
|
+
fp = tmp.path
|
|
66
|
+
File.chmod 0o000, fp
|
|
67
|
+
assert_raise RuntimeError do
|
|
68
|
+
WickedPdf.new fp
|
|
69
|
+
end
|
|
70
|
+
ensure
|
|
71
|
+
tmp.delete
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
test 'should raise exception when pdf generation fails' do
|
|
76
|
+
begin
|
|
77
|
+
tmp = Tempfile.new('wkhtmltopdf')
|
|
78
|
+
fp = tmp.path
|
|
79
|
+
File.chmod 0o777, fp
|
|
80
|
+
wp = WickedPdf.new fp
|
|
81
|
+
assert_raise RuntimeError do
|
|
82
|
+
wp.pdf_from_string HTML_DOCUMENT
|
|
83
|
+
end
|
|
84
|
+
ensure
|
|
85
|
+
tmp.delete
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
test 'should output progress when creating pdfs on compatible hosts' do
|
|
90
|
+
wp = WickedPdf.new
|
|
91
|
+
output = []
|
|
92
|
+
options = { :progress => proc { |o| output << o } }
|
|
93
|
+
wp.pdf_from_string HTML_DOCUMENT, options
|
|
94
|
+
if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
|
95
|
+
assert_empty output
|
|
96
|
+
else
|
|
97
|
+
assert(output.collect { |l| !l.match(/Loading/).nil? }.include?(true)) # should output something like "Loading pages (1/5)"
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
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
|