wicked_pdf 2.6.3 → 2.8.2
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 +4 -4
- data/.github/workflows/ci.yml +10 -10
- data/.rubocop.yml +2 -0
- data/.rubocop_todo.yml +28 -37
- data/CHANGELOG.md +37 -13
- data/README.md +13 -10
- data/gemfiles/6.1.gemfile +0 -1
- data/gemfiles/7.0.gemfile +0 -1
- data/generators/wicked_pdf/templates/wicked_pdf.rb +7 -7
- data/lib/wicked_pdf/option_parser.rb +4 -3
- data/lib/wicked_pdf/progress.rb +2 -2
- data/lib/wicked_pdf/tempfile.rb +4 -3
- data/lib/wicked_pdf/version.rb +1 -1
- data/lib/wicked_pdf/wicked_pdf_helper/assets.rb +108 -18
- data/lib/wicked_pdf.rb +37 -9
- data/test/fixtures/subdirectory/nested.js +1 -0
- data/test/functional/wicked_pdf_helper_assets_test.rb +129 -0
- data/test/test_helper.rb +7 -0
- data/test/unit/wicked_pdf_option_parser_test.rb +6 -1
- data/test/unit/wicked_pdf_test.rb +17 -0
- data/wicked_pdf.gemspec +3 -1
- metadata +35 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3f4ea7f135d4f4fc710ea43e0995b11afdce78631af49dda12dffa789071479
|
|
4
|
+
data.tar.gz: 1bab46b51b286f41c25536416e43e58123ecbc9d0c03bb263f4799a3e4363159
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea1929b8e9eaa18be71e0cd36e2075843d21be4925363c2e276941b4ec6ef7ec81283aa03d514b92992438e3bd80a53d1c5cdac32f5248afda536eedc928bb0d
|
|
7
|
+
data.tar.gz: 2f87dcc412541846b09f11ff4c6d2742a10f8b377224bcec05c3ca070c821498bf4c4d6ed86c1791436e3a28d9625ff0342b943177993a476339b2a0e07f9d3d
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -28,29 +28,29 @@ jobs:
|
|
|
28
28
|
- gemfile: "6.1"
|
|
29
29
|
ruby-version: 2.7
|
|
30
30
|
- gemfile: "6.1"
|
|
31
|
-
ruby-version: 3.0
|
|
31
|
+
ruby-version: '3.0'
|
|
32
32
|
- gemfile: "7.0"
|
|
33
33
|
ruby-version: 3.1
|
|
34
|
+
- gemfile: "7.0"
|
|
35
|
+
ruby-version: 3.2
|
|
34
36
|
|
|
35
37
|
env:
|
|
36
|
-
BUNDLE_GEMFILE: /
|
|
38
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
|
37
39
|
WKHTMLTOPDF_BIN: /usr/bin/wkhtmltopdf
|
|
38
40
|
|
|
39
41
|
steps:
|
|
40
|
-
- uses: actions/checkout@
|
|
41
|
-
|
|
42
|
-
- name: Install Ruby ${{ matrix.ruby-version }}
|
|
43
|
-
uses: ruby/setup-ruby@v1
|
|
44
|
-
with:
|
|
45
|
-
ruby-version: ${{ matrix.ruby-version }}
|
|
42
|
+
- uses: actions/checkout@v3
|
|
46
43
|
|
|
47
44
|
- name: Install OS dependencies
|
|
48
45
|
run: |
|
|
49
46
|
sudo apt-get update -y -qq
|
|
50
47
|
sudo apt-get install -y wkhtmltopdf
|
|
51
48
|
|
|
52
|
-
- name: Install
|
|
53
|
-
|
|
49
|
+
- name: Install Ruby ${{ matrix.ruby-version }}
|
|
50
|
+
uses: ruby/setup-ruby@v1
|
|
51
|
+
with:
|
|
52
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
53
|
+
bundler-cache: true
|
|
54
54
|
|
|
55
55
|
- name: Run tests with Ruby ${{ matrix.ruby-version }} and Rails ${{ matrix.gemfile }}
|
|
56
56
|
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on
|
|
3
|
+
# on 2023-01-24 11:24:49 UTC using RuboCop version 1.44.0.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
|
8
8
|
|
|
9
|
-
# Offense count: 11
|
|
10
|
-
Metrics/AbcSize:
|
|
11
|
-
Max: 45
|
|
12
|
-
|
|
13
9
|
# Offense count: 2
|
|
14
|
-
# Configuration parameters: CountComments.
|
|
10
|
+
# Configuration parameters: CountComments, CountAsOne.
|
|
15
11
|
Metrics/ClassLength:
|
|
16
|
-
Max:
|
|
12
|
+
Max: 203
|
|
17
13
|
|
|
18
14
|
# Offense count: 7
|
|
15
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
|
|
19
16
|
Metrics/CyclomaticComplexity:
|
|
20
17
|
Max: 13
|
|
21
18
|
|
|
22
19
|
# Offense count: 17
|
|
23
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
|
20
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
|
|
24
21
|
Metrics/MethodLength:
|
|
25
|
-
Max:
|
|
22
|
+
Max: 34
|
|
26
23
|
|
|
27
|
-
# Offense count:
|
|
28
|
-
# Configuration parameters: CountComments.
|
|
24
|
+
# Offense count: 1
|
|
25
|
+
# Configuration parameters: CountComments, CountAsOne.
|
|
29
26
|
Metrics/ModuleLength:
|
|
30
|
-
Max:
|
|
27
|
+
Max: 104
|
|
31
28
|
|
|
32
|
-
# Offense count:
|
|
33
|
-
Metrics/PerceivedComplexity:
|
|
34
|
-
Max: 13
|
|
35
|
-
|
|
36
|
-
# Offense count: 2
|
|
29
|
+
# Offense count: 1
|
|
37
30
|
Naming/AccessorMethodName:
|
|
38
31
|
Exclude:
|
|
39
32
|
- 'lib/wicked_pdf/middleware.rb'
|
|
40
|
-
- 'lib/wicked_pdf/pdf_helper.rb'
|
|
41
33
|
|
|
42
34
|
# Offense count: 1
|
|
35
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
36
|
+
# Configuration parameters: AllowOnConstant, AllowOnSelfClass.
|
|
43
37
|
Style/CaseEquality:
|
|
44
38
|
Exclude:
|
|
45
39
|
- 'lib/wicked_pdf/wicked_pdf_helper.rb'
|
|
@@ -49,66 +43,63 @@ Style/ClassVars:
|
|
|
49
43
|
Exclude:
|
|
50
44
|
- 'lib/wicked_pdf.rb'
|
|
51
45
|
|
|
52
|
-
# Offense count:
|
|
46
|
+
# Offense count: 13
|
|
47
|
+
# Configuration parameters: AllowedConstants.
|
|
53
48
|
Style/Documentation:
|
|
54
49
|
Exclude:
|
|
55
50
|
- 'spec/**/*'
|
|
56
51
|
- 'test/**/*'
|
|
57
52
|
- 'generators/wicked_pdf/wicked_pdf_generator.rb'
|
|
58
53
|
- 'lib/wicked_pdf.rb'
|
|
54
|
+
- 'lib/wicked_pdf/binary.rb'
|
|
59
55
|
- 'lib/wicked_pdf/middleware.rb'
|
|
56
|
+
- 'lib/wicked_pdf/option_parser.rb'
|
|
60
57
|
- 'lib/wicked_pdf/pdf_helper.rb'
|
|
61
58
|
- 'lib/wicked_pdf/progress.rb'
|
|
62
59
|
- 'lib/wicked_pdf/railtie.rb'
|
|
63
|
-
- 'lib/wicked_pdf/binary.rb'
|
|
64
|
-
- 'lib/wicked_pdf/option_parser.rb'
|
|
65
60
|
- 'lib/wicked_pdf/tempfile.rb'
|
|
66
61
|
- 'lib/wicked_pdf/wicked_pdf_helper.rb'
|
|
67
62
|
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
|
|
68
63
|
|
|
69
64
|
# Offense count: 2
|
|
70
|
-
#
|
|
65
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
71
66
|
Style/ExpandPathArguments:
|
|
72
67
|
Exclude:
|
|
73
68
|
- 'test/test_helper.rb'
|
|
74
69
|
- 'wicked_pdf.gemspec'
|
|
75
70
|
|
|
76
|
-
# Offense count:
|
|
77
|
-
#
|
|
78
|
-
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
|
71
|
+
# Offense count: 4
|
|
72
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
73
|
+
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
|
79
74
|
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
|
75
|
+
# SupportedShorthandSyntax: always, never, either, consistent
|
|
80
76
|
Style/HashSyntax:
|
|
81
77
|
Exclude:
|
|
82
|
-
- 'gemfiles/4.0.gemfile'
|
|
83
|
-
- 'gemfiles/4.1.gemfile'
|
|
84
|
-
- 'gemfiles/4.2.gemfile'
|
|
85
78
|
- 'gemfiles/5.0.gemfile'
|
|
86
79
|
- 'gemfiles/5.1.gemfile'
|
|
87
80
|
- 'gemfiles/5.2.gemfile'
|
|
88
81
|
- 'gemfiles/6.0.gemfile'
|
|
89
|
-
- 'gemfiles/rails_edge.gemfile'
|
|
90
82
|
|
|
91
83
|
# Offense count: 2
|
|
92
|
-
#
|
|
84
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
93
85
|
# Configuration parameters: EnforcedStyle.
|
|
94
86
|
# SupportedStyles: literals, strict
|
|
95
87
|
Style/MutableConstant:
|
|
96
88
|
Exclude:
|
|
97
89
|
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
|
|
98
90
|
|
|
99
|
-
# Offense count:
|
|
100
|
-
#
|
|
91
|
+
# Offense count: 5
|
|
92
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
101
93
|
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
|
|
102
94
|
# SupportedStyles: slashes, percent_r, mixed
|
|
103
95
|
Style/RegexpLiteral:
|
|
104
96
|
Exclude:
|
|
105
97
|
- 'lib/wicked_pdf/middleware.rb'
|
|
106
98
|
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
|
|
107
|
-
- 'test/unit/wicked_pdf_test.rb'
|
|
108
99
|
|
|
109
|
-
# Offense count:
|
|
110
|
-
#
|
|
111
|
-
# Configuration parameters:
|
|
100
|
+
# Offense count: 18
|
|
101
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
102
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
|
|
112
103
|
# URISchemes: http, https
|
|
113
|
-
|
|
104
|
+
Layout/LineLength:
|
|
114
105
|
Max: 563
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
1
|
# Change Log
|
|
2
|
-
All notable changes to this project
|
|
3
|
-
This project
|
|
2
|
+
All notable changes to this project should be documented in this file.
|
|
3
|
+
This project attempts to adhere to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
|
5
|
-
## [master branch] - Unreleased
|
|
5
|
+
## [[master branch] - Unreleased changes](https://github.com/mileszs/wicked_pdf/compare/2.8.2...HEAD)
|
|
6
6
|
### Breaking Changes
|
|
7
|
+
### New Features
|
|
8
|
+
### Fixes
|
|
9
|
+
|
|
10
|
+
## [2.8.2]
|
|
11
|
+
### Fixes
|
|
12
|
+
- [Fix for frozen_string_literal in Ruby 3.4](https://github.com/mileszs/wicked_pdf/pull/1118)
|
|
13
|
+
- [Add OpenStruct dependency explicitly for Ruby 3.5](https://github.com/mileszs/wicked_pdf/pull/1131)
|
|
14
|
+
|
|
15
|
+
## [2.8.1]
|
|
16
|
+
### Fixes
|
|
17
|
+
- [Explicitly require OpenStruct, which isn't loaded by default anymore in new versions of Rake](https://github.com/mileszs/wicked_pdf/pull/1110)
|
|
18
|
+
- [Ensure assets without extensions are handled correctly](https://github.com/mileszs/wicked_pdf/pull/1115)
|
|
19
|
+
|
|
20
|
+
## [2.8.0]
|
|
21
|
+
### New Features
|
|
22
|
+
- [Add New config option `raise_on_missing_assets`](https://github.com/mileszs/wicked_pdf/pull/1094)
|
|
23
|
+
- [Add support for truffleruby (22.1.0) on Linux](https://github.com/mileszs/wicked_pdf/pull/1028)
|
|
24
|
+
|
|
25
|
+
### Fixes
|
|
26
|
+
- [Fix Propshaft encoding issue](https://github.com/mileszs/wicked_pdf/pull/1096)
|
|
27
|
+
- [Fix Webpacker & Shakapacker compatibility issue](https://github.com/mileszs/wicked_pdf/pull/1099)
|
|
28
|
+
|
|
29
|
+
## [2.7.0]
|
|
30
|
+
### New Features
|
|
31
|
+
- [Support Shakapacker 7](https://github.com/mileszs/wicked_pdf/pull/1067)
|
|
32
|
+
- [Add option `delete_temporary_files` to keep the temporary files generated by `pdf_from_string` method](https://github.com/mileszs/wicked_pdf/pull/1068)
|
|
33
|
+
- [Add support for --allow flag](https://github.com/mileszs/wicked_pdf/pull/1030)
|
|
34
|
+
|
|
35
|
+
## Fixes
|
|
36
|
+
- [Add require for `stringio`, which is no longer loaded by default in Ruby 3.1+](https://github.com/mileszs/wicked_pdf/pull/1062)
|
|
37
|
+
- [Fix CI build.](https://github.com/mileszs/wicked_pdf/pull/1055)
|
|
38
|
+
- [Fix Header/footer temporary file is removed before `wkhtmltopdf` is called](https://github.com/mileszs/wicked_pdf/pull/1039)
|
|
39
|
+
- [Bump rubocop to 1.46](https://github.com/mileszs/wicked_pdf/pull/1051)
|
|
40
|
+
- [Add Ruby 3.2 to the test matrix](https://github.com/mileszs/wicked_pdf/pull/1046)
|
|
7
41
|
|
|
8
42
|
## [2.6.3]
|
|
9
43
|
### Fixes
|
|
@@ -218,13 +252,3 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
218
252
|
- Issues with `url()` references and embedded `data:base64` assets in stylesheets rendered with `wicked_pdf_stylesheet_link_tag`
|
|
219
253
|
- Asset helpers no longer add a file extension if it already is specified with one
|
|
220
254
|
|
|
221
|
-
# Compare Releases
|
|
222
|
-
- [2.1.0...HEAD (unreleased changes)](https://github.com/mileszs/wicked_pdf/compare/2.1.0...HEAD)
|
|
223
|
-
- [2.0.2...2.1.0](https://github.com/mileszs/wicked_pdf/compare/2.0.2...2.1.0)
|
|
224
|
-
- [2.0.0...2.0.2](https://github.com/mileszs/wicked_pdf/compare/2.0.0...2.0.2)
|
|
225
|
-
- [1.4.0...2.0.0](https://github.com/mileszs/wicked_pdf/compare/1.4.0...2.0.0)
|
|
226
|
-
- [1.3.0...1.4.0](https://github.com/mileszs/wicked_pdf/compare/1.3.0...1.4.0)
|
|
227
|
-
- [1.2.0...1.3.0](https://github.com/mileszs/wicked_pdf/compare/1.2.0...1.3.0)
|
|
228
|
-
- [1.1.0...1.2.0](https://github.com/mileszs/wicked_pdf/compare/1.1.0...1.2.0)
|
|
229
|
-
- [1.0.0...1.1.0](https://github.com/mileszs/wicked_pdf/compare/1.0.0...1.0.0)
|
|
230
|
-
- [0.11.0...1.0.0](https://github.com/mileszs/wicked_pdf/compare/0.11.0...1.0.0)
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Wicked PDF uses the shell utility [wkhtmltopdf](http://wkhtmltopdf.org) to serve a PDF file to a user from HTML. In other words, rather than dealing with a PDF generation DSL of some sort, you simply write an HTML view as you would normally, then let Wicked PDF take care of the hard stuff.
|
|
6
6
|
|
|
7
|
-
_Wicked PDF has been verified to work on Ruby versions 2.2 through 2
|
|
7
|
+
_Wicked PDF has been verified to work on Ruby versions 2.2 through 3.2; Rails 4 through 7.0_
|
|
8
8
|
|
|
9
9
|
### Installation
|
|
10
10
|
|
|
@@ -42,10 +42,10 @@ You can see what flags are supported for the current version in [wkhtmltopdf's a
|
|
|
42
42
|
If your wkhtmltopdf executable is not on your webserver's path, you can configure it in an initializer:
|
|
43
43
|
|
|
44
44
|
```ruby
|
|
45
|
-
WickedPdf.
|
|
46
|
-
exe_path
|
|
47
|
-
enable_local_file_access
|
|
48
|
-
|
|
45
|
+
WickedPdf.configure do |c|
|
|
46
|
+
c.exe_path = '/usr/local/bin/wkhtmltopdf'
|
|
47
|
+
c.enable_local_file_access = true
|
|
48
|
+
end
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
For more information about `wkhtmltopdf`, see the project's [homepage](http://wkhtmltopdf.org/).
|
|
@@ -191,6 +191,7 @@ class ThingsController < ApplicationController
|
|
|
191
191
|
# define as true the key 'disable_local_file_access' or 'enable_local_file_access', not both
|
|
192
192
|
disable_local_file_access: true,
|
|
193
193
|
enable_local_file_access: false, # must be true when using wkhtmltopdf > 0.12.6
|
|
194
|
+
allow: ["#{Rails.root}/public"], # could be an array or a single string
|
|
194
195
|
|
|
195
196
|
disable_smart_shrinking: true,
|
|
196
197
|
use_xserver: true,
|
|
@@ -200,6 +201,7 @@ class ThingsController < ApplicationController
|
|
|
200
201
|
viewport_size: 'TEXT', # available only with use_xserver or patched QT
|
|
201
202
|
extra: '', # directly inserted into the command to wkhtmltopdf
|
|
202
203
|
raise_on_all_errors: nil, # raise error for any stderr output. Such as missing media, image assets
|
|
204
|
+
raise_on_missing_assets: nil, # raise when trying to access a missing asset
|
|
203
205
|
log_level: 'info', # Available values: none, error, warn, or info - only available with wkhtmltopdf 0.12.5+
|
|
204
206
|
quiet: false, # `false` is same as `log_level: 'info'`, `true` is same as `log_level: 'none'`
|
|
205
207
|
outline: { outline: true,
|
|
@@ -258,7 +260,8 @@ class ThingsController < ApplicationController
|
|
|
258
260
|
disable_toc_links: true,
|
|
259
261
|
disable_back_links:true,
|
|
260
262
|
xsl_style_sheet: 'file.xsl'}, # optional XSLT stylesheet to use for styling table of contents
|
|
261
|
-
progress: proc { |output| puts output } # proc called when console output changes
|
|
263
|
+
progress: proc { |output| puts output }, # proc called when console output changes
|
|
264
|
+
delete_temporary_files: true # explicitly delete temporary files, default false
|
|
262
265
|
end
|
|
263
266
|
end
|
|
264
267
|
end
|
|
@@ -293,14 +296,14 @@ pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here')
|
|
|
293
296
|
# create a pdf from a URL
|
|
294
297
|
pdf = WickedPdf.new.pdf_from_url('https://github.com/mileszs/wicked_pdf')
|
|
295
298
|
|
|
296
|
-
# create a pdf from string using templates, layouts and content option for header or footer
|
|
299
|
+
# create a pdf from string using templates, layouts, and content option for header or footer
|
|
297
300
|
pdf = WickedPdf.new.pdf_from_string(
|
|
298
301
|
render_to_string('templates/pdf', layout: 'pdfs/layout_pdf.html'),
|
|
299
302
|
footer: {
|
|
300
303
|
content: render_to_string(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
+
'templates/footer',
|
|
305
|
+
layout: 'pdfs/layout_pdf.html'
|
|
306
|
+
)
|
|
304
307
|
}
|
|
305
308
|
)
|
|
306
309
|
|
data/gemfiles/6.1.gemfile
CHANGED
data/gemfiles/7.0.gemfile
CHANGED
|
@@ -8,23 +8,23 @@
|
|
|
8
8
|
#
|
|
9
9
|
# https://github.com/mileszs/wicked_pdf/blob/master/README.md
|
|
10
10
|
|
|
11
|
-
WickedPdf.
|
|
11
|
+
WickedPdf.configure do |config|
|
|
12
12
|
# Path to the wkhtmltopdf executable: This usually isn't needed if using
|
|
13
13
|
# one of the wkhtmltopdf-binary family of gems.
|
|
14
|
-
# exe_path
|
|
14
|
+
# config.exe_path = '/usr/local/bin/wkhtmltopdf'
|
|
15
15
|
# or
|
|
16
|
-
# exe_path
|
|
16
|
+
# config.exe_path = Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
|
|
17
17
|
|
|
18
18
|
# Needed for wkhtmltopdf 0.12.6+ to use many wicked_pdf asset helpers
|
|
19
|
-
# enable_local_file_access
|
|
19
|
+
# config.enable_local_file_access = true
|
|
20
20
|
|
|
21
21
|
# Layout file to be used for all PDFs
|
|
22
22
|
# (but can be overridden in `render :pdf` calls)
|
|
23
|
-
# layout
|
|
23
|
+
# config.layout = 'pdf.html'
|
|
24
24
|
|
|
25
25
|
# Using wkhtmltopdf without an X server can be achieved by enabling the
|
|
26
26
|
# 'use_xvfb' flag. This will wrap all wkhtmltopdf commands around the
|
|
27
27
|
# 'xvfb-run' command, in order to simulate an X server.
|
|
28
28
|
#
|
|
29
|
-
# use_xvfb
|
|
30
|
-
|
|
29
|
+
# config.use_xvfb = true
|
|
30
|
+
end
|
|
@@ -2,7 +2,7 @@ class WickedPdf
|
|
|
2
2
|
class OptionParser
|
|
3
3
|
BINARY_VERSION_WITHOUT_DASHES = Gem::Version.new('0.12.0')
|
|
4
4
|
|
|
5
|
-
attr_reader :binary_version
|
|
5
|
+
attr_reader :binary_version, :hf_tempfiles
|
|
6
6
|
|
|
7
7
|
def initialize(binary_version = WickedPdf::DEFAULT_BINARY_VERSION)
|
|
8
8
|
@binary_version = binary_version
|
|
@@ -61,7 +61,7 @@ class WickedPdf
|
|
|
61
61
|
r += make_options(opt_hf, [:line], hf.to_s, :boolean)
|
|
62
62
|
if options[hf] && options[hf][:content]
|
|
63
63
|
@hf_tempfiles = [] unless defined?(@hf_tempfiles)
|
|
64
|
-
@hf_tempfiles.push(tf =
|
|
64
|
+
@hf_tempfiles.push(tf = File.new(Dir::Tmpname.create(["wicked_#{hf}_pdf", '.html']) {}, 'w'))
|
|
65
65
|
tf.write options[hf][:content]
|
|
66
66
|
tf.flush
|
|
67
67
|
options[hf][:html] = {}
|
|
@@ -168,7 +168,8 @@ class WickedPdf
|
|
|
168
168
|
encoding
|
|
169
169
|
user_style_sheet
|
|
170
170
|
viewport_size
|
|
171
|
-
window_status
|
|
171
|
+
window_status
|
|
172
|
+
allow])
|
|
172
173
|
r += make_options(options, %i[cookie
|
|
173
174
|
post], '', :name_value)
|
|
174
175
|
r += make_options(options, %i[redirect_delay
|
data/lib/wicked_pdf/progress.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
class WickedPdf
|
|
2
2
|
module Progress
|
|
3
|
-
require 'pty' if RbConfig::CONFIG['target_os'] !~ /mswin|mingw/ # no support for windows
|
|
3
|
+
require 'pty' if RbConfig::CONFIG['target_os'] !~ /mswin|mingw/ && RUBY_ENGINE != 'truffleruby' # no support for windows and truffleruby
|
|
4
4
|
require 'English'
|
|
5
5
|
|
|
6
6
|
def track_progress?(options)
|
|
7
|
-
options[:progress] && !on_windows?
|
|
7
|
+
options[:progress] && !(on_windows? || RUBY_ENGINE == 'truffleruby')
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def invoke_with_progress(command, options)
|
data/lib/wicked_pdf/tempfile.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'tempfile'
|
|
2
|
+
require 'stringio'
|
|
2
3
|
|
|
3
4
|
class WickedPdf
|
|
4
5
|
class Tempfile < ::Tempfile
|
|
@@ -22,9 +23,9 @@ class WickedPdf
|
|
|
22
23
|
def read_in_chunks
|
|
23
24
|
rewind
|
|
24
25
|
binmode
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
chunks = []
|
|
27
|
+
chunks << read(chunk_size) until eof?
|
|
28
|
+
chunks.join
|
|
28
29
|
rescue Errno::EINVAL => e
|
|
29
30
|
raise e, file_too_large_message
|
|
30
31
|
end
|
data/lib/wicked_pdf/version.rb
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
require 'net/http'
|
|
2
2
|
require 'delegate'
|
|
3
|
+
require 'stringio'
|
|
3
4
|
|
|
4
5
|
class WickedPdf
|
|
5
6
|
module WickedPdfHelper
|
|
6
7
|
module Assets
|
|
7
8
|
ASSET_URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/
|
|
8
9
|
|
|
10
|
+
class MissingAsset < StandardError; end
|
|
11
|
+
|
|
12
|
+
class MissingLocalAsset < MissingAsset
|
|
13
|
+
attr_reader :path
|
|
14
|
+
|
|
15
|
+
def initialize(path)
|
|
16
|
+
@path = path
|
|
17
|
+
super("Could not find asset '#{path}'")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class MissingRemoteAsset < MissingAsset
|
|
22
|
+
attr_reader :url, :response
|
|
23
|
+
|
|
24
|
+
def initialize(url, response)
|
|
25
|
+
@url = url
|
|
26
|
+
@response = response
|
|
27
|
+
super("Could not fetch asset '#{url}': server responded with #{response.code} #{response.message}")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
9
31
|
class PropshaftAsset < SimpleDelegator
|
|
10
32
|
def content_type
|
|
11
33
|
super.to_s
|
|
@@ -20,9 +42,39 @@ class WickedPdf
|
|
|
20
42
|
end
|
|
21
43
|
end
|
|
22
44
|
|
|
45
|
+
class SprocketsEnvironment
|
|
46
|
+
def self.instance
|
|
47
|
+
@instance ||= Sprockets::Railtie.build_environment(Rails.application)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.find_asset(*args)
|
|
51
|
+
instance.find_asset(*args)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class LocalAsset
|
|
56
|
+
attr_reader :path
|
|
57
|
+
|
|
58
|
+
def initialize(path)
|
|
59
|
+
@path = path
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def content_type
|
|
63
|
+
Mime::Type.lookup_by_extension(File.extname(path).delete('.'))
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def to_s
|
|
67
|
+
IO.read(path)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def filename
|
|
71
|
+
path.to_s
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
23
75
|
def wicked_pdf_asset_base64(path)
|
|
24
76
|
asset = find_asset(path)
|
|
25
|
-
raise
|
|
77
|
+
raise MissingLocalAsset, path if asset.nil?
|
|
26
78
|
|
|
27
79
|
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, '')
|
|
28
80
|
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
|
|
@@ -149,8 +201,30 @@ class WickedPdf
|
|
|
149
201
|
Rails.application.assets.find_asset(path, :base_path => Rails.application.root.to_s)
|
|
150
202
|
elsif defined?(Propshaft::Assembly) && Rails.application.assets.is_a?(Propshaft::Assembly)
|
|
151
203
|
PropshaftAsset.new(Rails.application.assets.load_path.find(path))
|
|
204
|
+
elsif Rails.application.respond_to?(:assets_manifest)
|
|
205
|
+
relative_asset_path = get_asset_path_from_manifest(path)
|
|
206
|
+
return unless relative_asset_path
|
|
207
|
+
|
|
208
|
+
asset_path = File.join(Rails.application.assets_manifest.dir, relative_asset_path)
|
|
209
|
+
LocalAsset.new(asset_path) if File.file?(asset_path)
|
|
152
210
|
else
|
|
153
|
-
|
|
211
|
+
SprocketsEnvironment.find_asset(path, :base_path => Rails.application.root.to_s)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def get_asset_path_from_manifest(path)
|
|
216
|
+
assets = Rails.application.assets_manifest.assets
|
|
217
|
+
|
|
218
|
+
if File.extname(path).empty?
|
|
219
|
+
assets.find do |asset, _v|
|
|
220
|
+
directory = File.dirname(asset)
|
|
221
|
+
asset_path = File.basename(asset, File.extname(asset))
|
|
222
|
+
asset_path = File.join(directory, asset_path) if directory != '.'
|
|
223
|
+
|
|
224
|
+
asset_path == path
|
|
225
|
+
end&.last
|
|
226
|
+
else
|
|
227
|
+
assets[path]
|
|
154
228
|
end
|
|
155
229
|
end
|
|
156
230
|
|
|
@@ -174,20 +248,35 @@ class WickedPdf
|
|
|
174
248
|
end
|
|
175
249
|
|
|
176
250
|
def read_asset(source)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
251
|
+
asset = find_asset(source)
|
|
252
|
+
return asset.to_s.force_encoding('UTF-8') if asset
|
|
253
|
+
|
|
254
|
+
unless precompiled_or_absolute_asset?(source)
|
|
255
|
+
raise MissingLocalAsset, source if WickedPdf.config[:raise_on_missing_assets]
|
|
256
|
+
|
|
257
|
+
return
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
pathname = asset_pathname(source)
|
|
261
|
+
if pathname =~ URI_REGEXP
|
|
262
|
+
read_from_uri(pathname)
|
|
263
|
+
elsif File.file?(pathname)
|
|
264
|
+
IO.read(pathname)
|
|
265
|
+
elsif WickedPdf.config[:raise_on_missing_assets]
|
|
266
|
+
raise MissingLocalAsset, pathname if WickedPdf.config[:raise_on_missing_assets]
|
|
186
267
|
end
|
|
187
268
|
end
|
|
188
269
|
|
|
189
270
|
def read_from_uri(uri)
|
|
190
|
-
|
|
271
|
+
response = Net::HTTP.get_response(URI(uri))
|
|
272
|
+
|
|
273
|
+
unless response.is_a?(Net::HTTPSuccess)
|
|
274
|
+
raise MissingRemoteAsset.new(uri, response) if WickedPdf.config[:raise_on_missing_assets]
|
|
275
|
+
|
|
276
|
+
return
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
asset = response.body
|
|
191
280
|
asset.force_encoding('UTF-8') if asset
|
|
192
281
|
asset = gzip(asset) if WickedPdf.config[:expect_gzipped_remote_assets]
|
|
193
282
|
asset
|
|
@@ -230,12 +319,13 @@ class WickedPdf
|
|
|
230
319
|
end
|
|
231
320
|
|
|
232
321
|
def webpacker_version
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
322
|
+
if defined?(Shakapacker)
|
|
323
|
+
require 'shakapacker/version'
|
|
324
|
+
Shakapacker::VERSION
|
|
325
|
+
elsif defined?(Webpacker)
|
|
326
|
+
require 'webpacker/version'
|
|
327
|
+
Webpacker::VERSION
|
|
328
|
+
end
|
|
239
329
|
end
|
|
240
330
|
end
|
|
241
331
|
end
|
data/lib/wicked_pdf.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'logger'
|
|
|
5
5
|
require 'digest/md5'
|
|
6
6
|
require 'rbconfig'
|
|
7
7
|
require 'open3'
|
|
8
|
+
require 'ostruct'
|
|
8
9
|
|
|
9
10
|
require 'active_support/core_ext/module/attribute_accessors'
|
|
10
11
|
require 'active_support/core_ext/object/blank'
|
|
@@ -20,10 +21,27 @@ require 'wicked_pdf/progress'
|
|
|
20
21
|
class WickedPdf
|
|
21
22
|
DEFAULT_BINARY_VERSION = Gem::Version.new('0.9.9')
|
|
22
23
|
@@config = {}
|
|
23
|
-
cattr_accessor :config
|
|
24
|
+
cattr_accessor :config, :silence_deprecations
|
|
24
25
|
|
|
25
26
|
include Progress
|
|
26
27
|
|
|
28
|
+
def self.config=(config)
|
|
29
|
+
::Kernel.warn 'WickedPdf.config= is deprecated and will be removed in future versions. Use WickedPdf.configure instead.' unless @@silence_deprecations
|
|
30
|
+
|
|
31
|
+
@@config = config
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.configure
|
|
35
|
+
config = OpenStruct.new(@@config)
|
|
36
|
+
yield config
|
|
37
|
+
|
|
38
|
+
@@config.merge! config.to_h
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.clear_config
|
|
42
|
+
@@config = {}
|
|
43
|
+
end
|
|
44
|
+
|
|
27
45
|
def initialize(wkhtmltopdf_binary_path = nil)
|
|
28
46
|
@binary = Binary.new(wkhtmltopdf_binary_path, DEFAULT_BINARY_VERSION)
|
|
29
47
|
end
|
|
@@ -43,16 +61,20 @@ class WickedPdf
|
|
|
43
61
|
string_file.write_in_chunks(string)
|
|
44
62
|
pdf_from_html_file(string_file.path, options)
|
|
45
63
|
ensure
|
|
46
|
-
|
|
64
|
+
if options[:delete_temporary_files] && string_file
|
|
65
|
+
string_file.close!
|
|
66
|
+
elsif string_file
|
|
67
|
+
string_file.close
|
|
68
|
+
end
|
|
47
69
|
end
|
|
48
70
|
|
|
49
|
-
def pdf_from_url(url, options = {})
|
|
71
|
+
def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity
|
|
50
72
|
# merge in global config options
|
|
51
73
|
options.merge!(WickedPdf.config) { |_key, option, _config| option }
|
|
52
74
|
generated_pdf_file = WickedPdf::Tempfile.new('wicked_pdf_generated_file.pdf', options[:temp_path])
|
|
53
75
|
command = [@binary.path]
|
|
54
76
|
command.unshift(@binary.xvfb_run_path) if options[:use_xvfb]
|
|
55
|
-
command +=
|
|
77
|
+
command += option_parser.parse(options)
|
|
56
78
|
command << url
|
|
57
79
|
command << generated_pdf_file.path.to_s
|
|
58
80
|
|
|
@@ -61,9 +83,8 @@ class WickedPdf
|
|
|
61
83
|
if track_progress?(options)
|
|
62
84
|
invoke_with_progress(command, options)
|
|
63
85
|
else
|
|
64
|
-
err = Open3.
|
|
65
|
-
|
|
66
|
-
end
|
|
86
|
+
_out, err, status = Open3.capture3(*command)
|
|
87
|
+
err = [status.to_s, err].join("\n") if !err.empty? || !status.success?
|
|
67
88
|
end
|
|
68
89
|
if options[:return_file]
|
|
69
90
|
return_file = options.delete(:return_file)
|
|
@@ -79,6 +100,7 @@ class WickedPdf
|
|
|
79
100
|
rescue StandardError => e
|
|
80
101
|
raise "Failed to execute:\n#{command}\nError: #{e}"
|
|
81
102
|
ensure
|
|
103
|
+
clean_temp_files
|
|
82
104
|
generated_pdf_file.close! if generated_pdf_file && !return_file
|
|
83
105
|
end
|
|
84
106
|
|
|
@@ -98,7 +120,13 @@ class WickedPdf
|
|
|
98
120
|
Rails.logger.debug '[wicked_pdf]: ' + cmd
|
|
99
121
|
end
|
|
100
122
|
|
|
101
|
-
def
|
|
102
|
-
OptionParser.new(binary_version)
|
|
123
|
+
def option_parser
|
|
124
|
+
@option_parser ||= OptionParser.new(binary_version)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def clean_temp_files
|
|
128
|
+
return unless option_parser.hf_tempfiles.present?
|
|
129
|
+
|
|
130
|
+
option_parser.hf_tempfiles.each { |file| File.delete(file) }
|
|
103
131
|
end
|
|
104
132
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Nested js
|
|
@@ -4,17 +4,146 @@ require 'action_view/test_case'
|
|
|
4
4
|
class WickedPdfHelperAssetsTest < ActionView::TestCase
|
|
5
5
|
include WickedPdf::WickedPdfHelper::Assets
|
|
6
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
|
+
|
|
7
20
|
if Rails::VERSION::MAJOR > 3 || (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0)
|
|
8
21
|
test 'wicked_pdf_asset_base64 returns a base64 encoded asset' do
|
|
9
22
|
assert_match %r{data:text\/css;base64,.+}, wicked_pdf_asset_base64('wicked.css')
|
|
10
23
|
end
|
|
11
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
|
+
|
|
12
55
|
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in' do
|
|
13
56
|
Rails.configuration.assets.expects(:compile => true)
|
|
14
57
|
assert_equal "<style type='text/css'>/* Wicked styles */\n\n</style>",
|
|
15
58
|
wicked_pdf_stylesheet_link_tag('wicked')
|
|
16
59
|
end
|
|
17
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
|
+
|
|
18
147
|
test 'wicked_pdf_image_tag should return the same as image_tag when passed a full path' do
|
|
19
148
|
Rails.configuration.assets.expects(:compile => true)
|
|
20
149
|
assert_equal image_tag("file:///#{Rails.root.join('public', 'pdf')}"),
|
data/test/test_helper.rb
CHANGED
|
@@ -7,10 +7,12 @@ require 'test/unit'
|
|
|
7
7
|
require 'mocha'
|
|
8
8
|
require 'rails/test_help'
|
|
9
9
|
require 'mocha/test_unit'
|
|
10
|
+
require 'webmock/minitest'
|
|
10
11
|
|
|
11
12
|
require 'wicked_pdf'
|
|
12
13
|
|
|
13
14
|
Rails.backtrace_cleaner.remove_silencers!
|
|
15
|
+
WickedPdf.silence_deprecations = true
|
|
14
16
|
|
|
15
17
|
if (assets_dir = Rails.root.join('app/assets')) && File.directory?(assets_dir)
|
|
16
18
|
# Copy CSS file
|
|
@@ -25,6 +27,11 @@ if (assets_dir = Rails.root.join('app/assets')) && File.directory?(assets_dir)
|
|
|
25
27
|
source = File.read('test/fixtures/wicked.js')
|
|
26
28
|
File.open(destination, 'w') { |f| f.write(source) }
|
|
27
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
|
+
|
|
28
35
|
config_dir = assets_dir.join('config')
|
|
29
36
|
Dir.mkdir(config_dir) unless File.directory?(config_dir)
|
|
30
37
|
source = File.read('test/fixtures/manifest.js')
|
|
@@ -76,6 +76,11 @@ class WickedPdfOptionParserTest < ActiveSupport::TestCase
|
|
|
76
76
|
assert_equal "--#{o.to_s.tr('_', '-')} opts", parse_options(o => 'opts').strip
|
|
77
77
|
end
|
|
78
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
|
+
|
|
79
84
|
%i[cookie post].each do |o|
|
|
80
85
|
assert_equal "--#{o.to_s.tr('_', '-')} name value", parse_options(o => 'name value').strip
|
|
81
86
|
|
|
@@ -90,7 +95,7 @@ class WickedPdfOptionParserTest < ActiveSupport::TestCase
|
|
|
90
95
|
%i[
|
|
91
96
|
book default_header disable_javascript grayscale lowquality
|
|
92
97
|
enable_plugins disable_internal_links disable_external_links
|
|
93
|
-
print_media_type disable_smart_shrinking use_xserver no_background
|
|
98
|
+
print_media_type disable_smart_shrinking use_xserver no_background disable_local_file_access
|
|
94
99
|
].each do |o|
|
|
95
100
|
assert_equal "--#{o.to_s.tr('_', '-')}", parse_options(o => true).strip
|
|
96
101
|
end
|
|
@@ -7,6 +7,23 @@ class WickedPdfTest < ActiveSupport::TestCase
|
|
|
7
7
|
@wp = WickedPdf.new
|
|
8
8
|
end
|
|
9
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
|
+
|
|
10
27
|
test 'should generate PDF from html document' do
|
|
11
28
|
pdf = @wp.pdf_from_string HTML_DOCUMENT
|
|
12
29
|
assert pdf.start_with?('%PDF-1.4')
|
data/wicked_pdf.gemspec
CHANGED
|
@@ -29,12 +29,14 @@ DESC
|
|
|
29
29
|
spec.requirements << 'wkhtmltopdf'
|
|
30
30
|
|
|
31
31
|
spec.add_dependency 'activesupport'
|
|
32
|
+
spec.add_dependency 'ostruct'
|
|
32
33
|
|
|
33
34
|
spec.add_development_dependency 'bundler'
|
|
34
35
|
spec.add_development_dependency 'mocha', '= 1.3'
|
|
35
36
|
spec.add_development_dependency 'rails'
|
|
36
37
|
spec.add_development_dependency 'rake'
|
|
37
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
|
38
|
+
spec.add_development_dependency 'rubocop', '~> 1.46'
|
|
38
39
|
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
|
39
40
|
spec.add_development_dependency 'test-unit'
|
|
41
|
+
spec.add_development_dependency 'webmock', '~> 3.19'
|
|
40
42
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wicked_pdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.8.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miles Z. Sterrett
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2024-10-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -25,6 +25,20 @@ dependencies:
|
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
27
|
version: '0'
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: ostruct
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
type: :runtime
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
28
42
|
- !ruby/object:Gem::Dependency
|
|
29
43
|
name: bundler
|
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -87,14 +101,14 @@ dependencies:
|
|
|
87
101
|
requirements:
|
|
88
102
|
- - "~>"
|
|
89
103
|
- !ruby/object:Gem::Version
|
|
90
|
-
version: '1.
|
|
104
|
+
version: '1.46'
|
|
91
105
|
type: :development
|
|
92
106
|
prerelease: false
|
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
|
94
108
|
requirements:
|
|
95
109
|
- - "~>"
|
|
96
110
|
- !ruby/object:Gem::Version
|
|
97
|
-
version: '1.
|
|
111
|
+
version: '1.46'
|
|
98
112
|
- !ruby/object:Gem::Dependency
|
|
99
113
|
name: sqlite3
|
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -123,6 +137,20 @@ dependencies:
|
|
|
123
137
|
- - ">="
|
|
124
138
|
- !ruby/object:Gem::Version
|
|
125
139
|
version: '0'
|
|
140
|
+
- !ruby/object:Gem::Dependency
|
|
141
|
+
name: webmock
|
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
|
143
|
+
requirements:
|
|
144
|
+
- - "~>"
|
|
145
|
+
- !ruby/object:Gem::Version
|
|
146
|
+
version: '3.19'
|
|
147
|
+
type: :development
|
|
148
|
+
prerelease: false
|
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
150
|
+
requirements:
|
|
151
|
+
- - "~>"
|
|
152
|
+
- !ruby/object:Gem::Version
|
|
153
|
+
version: '3.19'
|
|
126
154
|
description: |
|
|
127
155
|
Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML.
|
|
128
156
|
In other words, rather than dealing with a PDF generation DSL of some sort,
|
|
@@ -168,6 +196,7 @@ files:
|
|
|
168
196
|
- test/fixtures/database.yml
|
|
169
197
|
- test/fixtures/document_with_long_line.html
|
|
170
198
|
- test/fixtures/manifest.js
|
|
199
|
+
- test/fixtures/subdirectory/nested.js
|
|
171
200
|
- test/fixtures/wicked.css
|
|
172
201
|
- test/fixtures/wicked.js
|
|
173
202
|
- test/functional/pdf_helper_test.rb
|
|
@@ -200,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
200
229
|
version: '0'
|
|
201
230
|
requirements:
|
|
202
231
|
- wkhtmltopdf
|
|
203
|
-
rubygems_version: 3.
|
|
232
|
+
rubygems_version: 3.4.19
|
|
204
233
|
signing_key:
|
|
205
234
|
specification_version: 4
|
|
206
235
|
summary: PDF generator (from HTML) gem for Ruby on Rails
|
|
@@ -208,6 +237,7 @@ test_files:
|
|
|
208
237
|
- test/fixtures/database.yml
|
|
209
238
|
- test/fixtures/document_with_long_line.html
|
|
210
239
|
- test/fixtures/manifest.js
|
|
240
|
+
- test/fixtures/subdirectory/nested.js
|
|
211
241
|
- test/fixtures/wicked.css
|
|
212
242
|
- test/fixtures/wicked.js
|
|
213
243
|
- test/functional/pdf_helper_test.rb
|