wicked_pdf 2.0.2 → 2.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +56 -0
- data/.rubocop.yml +55 -1
- data/.rubocop_todo.yml +7 -86
- data/CHANGELOG.md +70 -4
- data/README.md +51 -11
- data/Rakefile +3 -10
- data/gemfiles/5.0.gemfile +2 -2
- data/gemfiles/5.1.gemfile +2 -2
- data/gemfiles/5.2.gemfile +3 -4
- data/gemfiles/6.0.gemfile +3 -4
- 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/wicked_pdf/binary.rb +65 -0
- data/lib/wicked_pdf/option_parser.rb +229 -0
- data/lib/wicked_pdf/pdf_helper.rb +29 -44
- data/lib/wicked_pdf/railtie.rb +3 -12
- data/lib/wicked_pdf/tempfile.rb +32 -3
- data/lib/wicked_pdf/version.rb +1 -1
- data/lib/wicked_pdf/wicked_pdf_helper/assets.rb +62 -6
- data/lib/wicked_pdf.rb +19 -257
- data/test/functional/pdf_helper_test.rb +1 -1
- 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 +0 -157
- data/test/unit/wkhtmltopdf_location_test.rb +0 -2
- data/wicked_pdf.gemspec +3 -4
- metadata +33 -29
- data/.travis.yml +0 -79
- data/gemfiles/4.0.gemfile +0 -7
- data/gemfiles/4.1.gemfile +0 -7
- data/gemfiles/4.2.gemfile +0 -9
- data/gemfiles/rails_edge.gemfile +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff321e074667535ecd017f0b594c1bd03a2c8cb73ef2c572ab93923e9ae1f201
|
4
|
+
data.tar.gz: 48349fe2254ef17953930e275e737d0c4462c89d700a54357429526eb0e95590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7877be9f6afe473fb57bafc09a2dc06668ee455e06f913461dff9ae863104ad98f54db77d528fdd228edfd4e2899f5e2869535bbf73b9a96b084525e0730a239
|
7
|
+
data.tar.gz: f61b96ab6eb10d5b9c9383419a6ee931946675f77a6a6abf27acc748ed52b63faa8fbb6c47245e3f3494d6bc3a542c0ce58a81044b9685de5c6950df40661fc9
|
@@ -0,0 +1,56 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request, workflow_dispatch]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
tests:
|
7
|
+
name: Tests with Ruby ${{ matrix.ruby-version }} and Rails ${{ matrix.gemfile }}
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
gemfile: ["5.0"]
|
12
|
+
ruby-version: [2.6]
|
13
|
+
include:
|
14
|
+
- gemfile: "5.0"
|
15
|
+
ruby-version: 2.7
|
16
|
+
- gemfile: "5.1"
|
17
|
+
ruby-version: 2.6
|
18
|
+
- gemfile: "5.1"
|
19
|
+
ruby-version: 2.7
|
20
|
+
- gemfile: "5.2"
|
21
|
+
ruby-version: 2.6
|
22
|
+
- gemfile: "5.2"
|
23
|
+
ruby-version: 2.7
|
24
|
+
- gemfile: "6.0"
|
25
|
+
ruby-version: 2.6
|
26
|
+
- gemfile: "6.0"
|
27
|
+
ruby-version: 2.7
|
28
|
+
- gemfile: "6.1"
|
29
|
+
ruby-version: 2.7
|
30
|
+
- gemfile: "6.1"
|
31
|
+
ruby-version: 3.0
|
32
|
+
- gemfile: "7.0"
|
33
|
+
ruby-version: 3.1
|
34
|
+
|
35
|
+
env:
|
36
|
+
BUNDLE_GEMFILE: /home/runner/work/wicked_pdf/wicked_pdf/gemfiles/${{ matrix.gemfile }}.gemfile
|
37
|
+
WKHTMLTOPDF_BIN: /usr/bin/wkhtmltopdf
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- uses: actions/checkout@v2
|
41
|
+
|
42
|
+
- name: Install Ruby ${{ matrix.ruby-version }}
|
43
|
+
uses: ruby/setup-ruby@v1
|
44
|
+
with:
|
45
|
+
ruby-version: ${{ matrix.ruby-version }}
|
46
|
+
|
47
|
+
- name: Install OS dependencies
|
48
|
+
run: |
|
49
|
+
sudo apt-get update -y -qq
|
50
|
+
sudo apt-get install -y wkhtmltopdf
|
51
|
+
|
52
|
+
- name: Install gem dependencies
|
53
|
+
run: bundle install
|
54
|
+
|
55
|
+
- name: Run tests with Ruby ${{ matrix.ruby-version }} and Rails ${{ matrix.gemfile }}
|
56
|
+
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,15 +1,69 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
|
4
|
+
NewCops: disable
|
5
|
+
TargetRubyVersion: 2.6
|
5
6
|
Exclude:
|
6
7
|
- 'gemfiles/bin/*'
|
7
8
|
- 'test/dummy/**/*'
|
8
9
|
|
10
|
+
Metrics/PerceivedComplexity:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Gemspec/RequiredRubyVersion:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Bundler/OrderedGems:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/FrozenStringLiteralComment:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/RedundantBegin:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/NumericPredicate:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/RedundantRegexpEscape:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/SafeNavigation:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Lint/SendWithMixinArgument:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Lint/RedundantCopDisableDirective:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Metrics/AbcSize:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/StringConcatenation:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/RedundantFetchBlock:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/CaseLikeIf:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/SoleNestedConditional:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Style/RedundantReturn:
|
56
|
+
Enabled: false
|
57
|
+
|
9
58
|
Metrics/BlockLength:
|
10
59
|
Exclude:
|
11
60
|
- 'wicked_pdf.gemspec'
|
12
61
|
|
62
|
+
Metrics/ModuleLength:
|
63
|
+
Exclude:
|
64
|
+
# Excluding to keep the logic in one module for the time being.
|
65
|
+
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
|
66
|
+
|
13
67
|
# I'd like wicked_pdf to keep Ruby 1.8 compatibility for now
|
14
68
|
Style/HashSyntax:
|
15
69
|
EnforcedStyle: hash_rockets
|
data/.rubocop_todo.yml
CHANGED
@@ -1,64 +1,11 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2019-10-
|
3
|
+
# on 2019-10-09 14:16:04 +0200 using RuboCop version 0.68.1.
|
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: 9
|
10
|
-
# Cop supports --auto-correct.
|
11
|
-
# Configuration parameters: TreatCommentsAsGroupSeparators, Include.
|
12
|
-
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
|
13
|
-
Bundler/OrderedGems:
|
14
|
-
Exclude:
|
15
|
-
- 'gemfiles/4.0.gemfile'
|
16
|
-
- 'gemfiles/4.1.gemfile'
|
17
|
-
- 'gemfiles/4.2.gemfile'
|
18
|
-
- 'gemfiles/5.0.gemfile'
|
19
|
-
- 'gemfiles/5.1.gemfile'
|
20
|
-
- 'gemfiles/5.2.gemfile'
|
21
|
-
- 'gemfiles/6.0.gemfile'
|
22
|
-
- 'gemfiles/rails_edge.gemfile'
|
23
|
-
|
24
|
-
# Offense count: 2
|
25
|
-
# Cop supports --auto-correct.
|
26
|
-
# Configuration parameters: TreatCommentsAsGroupSeparators, Include.
|
27
|
-
# Include: **/*.gemspec
|
28
|
-
Gemspec/OrderedDependencies:
|
29
|
-
Exclude:
|
30
|
-
- 'wicked_pdf.gemspec'
|
31
|
-
|
32
|
-
# Offense count: 16
|
33
|
-
# Cop supports --auto-correct.
|
34
|
-
Layout/EmptyLineAfterGuardClause:
|
35
|
-
Exclude:
|
36
|
-
- 'Rakefile'
|
37
|
-
- 'lib/wicked_pdf.rb'
|
38
|
-
- 'lib/wicked_pdf/pdf_helper.rb'
|
39
|
-
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
|
40
|
-
|
41
|
-
# Offense count: 2
|
42
|
-
# Cop supports --auto-correct.
|
43
|
-
Layout/LeadingBlankLines:
|
44
|
-
Exclude:
|
45
|
-
- 'test/unit/wkhtmltopdf_location_test.rb'
|
46
|
-
- 'wicked_pdf.gemspec'
|
47
|
-
|
48
|
-
# Offense count: 1
|
49
|
-
# Cop supports --auto-correct.
|
50
|
-
Layout/RescueEnsureAlignment:
|
51
|
-
Exclude:
|
52
|
-
- 'lib/wicked_pdf.rb'
|
53
|
-
|
54
|
-
# Offense count: 1
|
55
|
-
# Cop supports --auto-correct.
|
56
|
-
# Configuration parameters: EnforcedStyle.
|
57
|
-
# SupportedStyles: final_newline, final_blank_line
|
58
|
-
Layout/TrailingBlankLines:
|
59
|
-
Exclude:
|
60
|
-
- 'gemfiles/4.0.gemfile'
|
61
|
-
|
62
9
|
# Offense count: 11
|
63
10
|
Metrics/AbcSize:
|
64
11
|
Max: 45
|
@@ -66,16 +13,16 @@ Metrics/AbcSize:
|
|
66
13
|
# Offense count: 2
|
67
14
|
# Configuration parameters: CountComments.
|
68
15
|
Metrics/ClassLength:
|
69
|
-
Max:
|
16
|
+
Max: 250
|
70
17
|
|
71
18
|
# Offense count: 7
|
72
19
|
Metrics/CyclomaticComplexity:
|
73
|
-
Max:
|
20
|
+
Max: 13
|
74
21
|
|
75
22
|
# Offense count: 17
|
76
23
|
# Configuration parameters: CountComments, ExcludedMethods.
|
77
24
|
Metrics/MethodLength:
|
78
|
-
Max:
|
25
|
+
Max: 40
|
79
26
|
|
80
27
|
# Offense count: 2
|
81
28
|
# Configuration parameters: CountComments.
|
@@ -84,7 +31,7 @@ Metrics/ModuleLength:
|
|
84
31
|
|
85
32
|
# Offense count: 6
|
86
33
|
Metrics/PerceivedComplexity:
|
87
|
-
Max:
|
34
|
+
Max: 13
|
88
35
|
|
89
36
|
# Offense count: 2
|
90
37
|
Naming/AccessorMethodName:
|
@@ -92,11 +39,6 @@ Naming/AccessorMethodName:
|
|
92
39
|
- 'lib/wicked_pdf/middleware.rb'
|
93
40
|
- 'lib/wicked_pdf/pdf_helper.rb'
|
94
41
|
|
95
|
-
# Offense count: 1
|
96
|
-
Security/Open:
|
97
|
-
Exclude:
|
98
|
-
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
|
99
|
-
|
100
42
|
# Offense count: 1
|
101
43
|
Style/CaseEquality:
|
102
44
|
Exclude:
|
@@ -118,6 +60,8 @@ Style/Documentation:
|
|
118
60
|
- 'lib/wicked_pdf/pdf_helper.rb'
|
119
61
|
- 'lib/wicked_pdf/progress.rb'
|
120
62
|
- 'lib/wicked_pdf/railtie.rb'
|
63
|
+
- 'lib/wicked_pdf/binary.rb'
|
64
|
+
- 'lib/wicked_pdf/option_parser.rb'
|
121
65
|
- 'lib/wicked_pdf/tempfile.rb'
|
122
66
|
- 'lib/wicked_pdf/wicked_pdf_helper.rb'
|
123
67
|
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
|
@@ -144,14 +88,6 @@ Style/HashSyntax:
|
|
144
88
|
- 'gemfiles/6.0.gemfile'
|
145
89
|
- 'gemfiles/rails_edge.gemfile'
|
146
90
|
|
147
|
-
# Offense count: 3
|
148
|
-
# Cop supports --auto-correct.
|
149
|
-
Style/IfUnlessModifier:
|
150
|
-
Exclude:
|
151
|
-
- 'Rakefile'
|
152
|
-
- 'lib/wicked_pdf.rb'
|
153
|
-
- 'lib/wicked_pdf/railtie.rb'
|
154
|
-
|
155
91
|
# Offense count: 2
|
156
92
|
# Cop supports --auto-correct.
|
157
93
|
# Configuration parameters: EnforcedStyle.
|
@@ -170,21 +106,6 @@ Style/RegexpLiteral:
|
|
170
106
|
- 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
|
171
107
|
- 'test/unit/wicked_pdf_test.rb'
|
172
108
|
|
173
|
-
# Offense count: 1
|
174
|
-
# Cop supports --auto-correct.
|
175
|
-
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
176
|
-
# SupportedStyles: single_quotes, double_quotes
|
177
|
-
Style/StringLiterals:
|
178
|
-
Exclude:
|
179
|
-
- 'gemfiles/4.0.gemfile'
|
180
|
-
|
181
|
-
# Offense count: 29
|
182
|
-
# Cop supports --auto-correct.
|
183
|
-
# Configuration parameters: MinSize.
|
184
|
-
# SupportedStyles: percent, brackets
|
185
|
-
Style/SymbolArray:
|
186
|
-
EnforcedStyle: brackets
|
187
|
-
|
188
109
|
# Offense count: 111
|
189
110
|
# Cop supports --auto-correct.
|
190
111
|
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
data/CHANGELOG.md
CHANGED
@@ -4,11 +4,76 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
5
5
|
## [master branch] - Unreleased
|
6
6
|
### Breaking Changes
|
7
|
-
|
7
|
+
|
8
|
+
## [2.6.2]
|
9
|
+
### Fixes
|
10
|
+
- [Fix undefined local variable or method 'block' for render_to_string](https://github.com/mileszs/wicked_pdf/pull/962)
|
11
|
+
- [Add require for `delegate`, which is no longer loaded by default in Ruby 2.7+](https://github.com/mileszs/wicked_pdf/pull/1019)
|
12
|
+
## [2.6.0]
|
13
|
+
### New Features
|
14
|
+
- [Support Propshaft in find_asset helper](https://github.com/mileszs/wicked_pdf/pull/1010)
|
15
|
+
### Fixes
|
16
|
+
- [Update Changelog with changes from 2.1.0](https://github.com/mileszs/wicked_pdf/pull/1013)
|
17
|
+
- [Fix CI build for Rails 7.](https://github.com/mileszs/wicked_pdf/pull/1014)
|
18
|
+
|
19
|
+
## [2.5.4] December 20th 2021 769f9df487f3c1e31dc91431666baa78d2aa24fb
|
20
|
+
### New Features
|
21
|
+
- [Test with Rails 7](https://github.com/mileszs/wicked_pdf/pull/998)
|
22
|
+
### Fixes
|
23
|
+
- [Include view helper on view load.](https://github.com/mileszs/wicked_pdf/pull/992)
|
24
|
+
|
25
|
+
## [2.5.3] December 15th 2021 7991877de634067b4245fb47fdad65da43761887
|
26
|
+
- [Fix check for webpacker version](https://github.com/mileszs/wicked_pdf/pull/964)
|
27
|
+
- [Complete transition to Github actions](https://github.com/mileszs/wicked_pdf/pull/987)
|
28
|
+
|
29
|
+
## [2.5.2] November 2021 - fix webpacker_source_url bdd0ca3eca759e277ce5461141b1506f56fefcd1
|
30
|
+
- [fix: `webpacker_source_url`](https://github.com/mileszs/wicked_pdf/pull/993)
|
31
|
+
- [update README](https://github.com/mileszs/wicked_pdf/pull/968)
|
32
|
+
|
33
|
+
## [2.5.1] September 2021 - fix webpacker helper, github actions and Readme updates ae725e8055dc8f51a392c27767b4dcdcfffe155d
|
34
|
+
- [Add comment about enable_local_file_access to README](https://github.com/mileszs/wicked_pdf/commit/2dc96dde2e0fd7362395064f2480cac1edcc1f48)
|
35
|
+
- [README updates](https://github.com/mileszs/wicked_pdf/pull/974) &&
|
36
|
+
- [Github actions](https://github.com/mileszs/wicked_pdf/pull/986)
|
37
|
+
- [Screencast links](https://github.com/mileszs/wicked_pdf/pull/976)
|
38
|
+
- [fix url generating in webpacker helper](https://github.com/mileszs/wicked_pdf/pull/973)
|
39
|
+
|
40
|
+
## [2.5.0] November 2020 Release - 2b1d47a84fce3600e7cbe2f50843af1a7b84d4a6
|
41
|
+
- [Remove code for unsupported rails and ruby versions](https://github.com/mileszs/wicked_pdf/pull/925)
|
42
|
+
|
43
|
+
## [2.4.1] b56c46a05895def395ebc75ed8e822551c2c478f
|
44
|
+
- [Extract reading in chunk](https://github.com/mileszs/wicked_pdf/pull/951)
|
45
|
+
- [add ruby 2.7 to the test matrix](https://github.com/mileszs/wicked_pdf/pull/952)
|
46
|
+
|
47
|
+
## [2.4.0] 8c007a77057e1a6680469d1ef53aa19a108fe209
|
8
48
|
### New Features
|
9
|
-
-
|
49
|
+
- [Do not unlink HTML temp files immediately (to enable HTML tempfile inspection)](https://github.com/mileszs/wicked_pdf/pull/950)
|
50
|
+
- [Read HTML string and generated PDF file in chunks (to reduce memory overhead of generating large PDFs)](https://github.com/mileszs/wicked_pdf/pull/949)
|
51
|
+
- [Add `wicked_pdf_url_base64` helper](https://github.com/mileszs/wicked_pdf/pull/947)
|
52
|
+
|
53
|
+
## [2.3.1] - Allow bundler 2.x ee6a5e1f807c872af37c1382f629dd4cac3040a8
|
54
|
+
- [Adjust gemspec development dependencies](https://github.com/mileszs/wicked_pdf/pull/814)
|
55
|
+
|
56
|
+
## [2.3.0] - Remove support for Ruby 1.x and Rails 2.x 66149c67e54cd3a63dd27528f5b78255fdd5ac43
|
57
|
+
- [Remove support for Ruby 1.x and Rails 2.x](https://github.com/mileszs/wicked_pdf/pull/859)
|
58
|
+
|
59
|
+
## [2.2.0] - October 2020 release f8abe706f5eb6dba2fcded473c81f2176e9d717e
|
10
60
|
### Fixes
|
11
|
-
-
|
61
|
+
- [Make CI green again](https://github.com/mileszs/wicked_pdf/pull/939)
|
62
|
+
- [rubocop fixes](https://github.com/mileszs/wicked_pdf/pull/945)
|
63
|
+
### New Features
|
64
|
+
- [Add support for --keep-relative-links flag](https://github.com/mileszs/wicked_pdf/pull/930)
|
65
|
+
- [Encapsulate binary path and version handling](https://github.com/mileszs/wicked_pdf/pull/816) && [#815](https://github.com/mileszs/wicked_pdf/pull/815)
|
66
|
+
|
67
|
+
|
68
|
+
## [2.1.0] - 2020-06-14
|
69
|
+
### Fixes
|
70
|
+
- [Document no_stop_slow_scripts in README](https://github.com/mileszs/wicked_pdf/pull/905)
|
71
|
+
- [Document how to use locals in README](https://github.com/mileszs/wicked_pdf/pull/915)
|
72
|
+
|
73
|
+
### New Features
|
74
|
+
- [Improved support for Webpacker assets with `wicked_pdf_asset_pack_path`](https://github.com/mileszs/wicked_pdf/pull/896)
|
75
|
+
- [Support enabling/disabling local file access compatible with wkhtmltopdf 0.12.6](https://github.com/mileszs/wicked_pdf/pull/920)
|
76
|
+
- [Add option `use_xvfb` to emulate an X server](https://github.com/mileszs/wicked_pdf/pull/909)
|
12
77
|
|
13
78
|
## [2.0.2] - 2020-03-17
|
14
79
|
### Fixes
|
@@ -149,7 +214,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
149
214
|
- Asset helpers no longer add a file extension if it already is specified with one
|
150
215
|
|
151
216
|
# Compare Releases
|
152
|
-
- [2.0
|
217
|
+
- [2.1.0...HEAD (unreleased changes)](https://github.com/mileszs/wicked_pdf/compare/2.1.0...HEAD)
|
218
|
+
- [2.0.2...2.1.0](https://github.com/mileszs/wicked_pdf/compare/2.0.2...2.1.0)
|
153
219
|
- [2.0.0...2.0.2](https://github.com/mileszs/wicked_pdf/compare/2.0.0...2.0.2)
|
154
220
|
- [1.4.0...2.0.0](https://github.com/mileszs/wicked_pdf/compare/1.4.0...2.0.0)
|
155
221
|
- [1.3.0...1.4.0](https://github.com/mileszs/wicked_pdf/compare/1.3.0...1.4.0)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Wicked PDF [![Gem Version](https://badge.fury.io/rb/wicked_pdf.svg)](http://badge.fury.io/rb/wicked_pdf) [![Build Status](https://
|
1
|
+
# Wicked PDF [![Gem Version](https://badge.fury.io/rb/wicked_pdf.svg)](http://badge.fury.io/rb/wicked_pdf) [![Build Status](https://github.com/mileszs/wicked_pdf/actions/workflows/ci.yml/badge.svg)](https://github.com/mileszs/wicked_pdf/actions/workflows/ci.yml) [![Code Climate](https://codeclimate.com/github/mileszs/wicked_pdf/badges/gpa.svg)](https://codeclimate.com/github/mileszs/wicked_pdf) [![Open Source Helpers](https://www.codetriage.com/mileszs/wicked_pdf/badges/users.svg)](https://www.codetriage.com/mileszs/wicked_pdf)
|
2
2
|
|
3
3
|
## A PDF generation plugin for Ruby on Rails
|
4
4
|
|
@@ -43,7 +43,8 @@ If your wkhtmltopdf executable is not on your webserver's path, you can configur
|
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
WickedPdf.config = {
|
46
|
-
exe_path: '/usr/local/bin/wkhtmltopdf'
|
46
|
+
exe_path: '/usr/local/bin/wkhtmltopdf',
|
47
|
+
enable_local_file_access: true
|
47
48
|
}
|
48
49
|
```
|
49
50
|
|
@@ -109,10 +110,11 @@ Using wicked_pdf_helpers with asset pipeline raises `Asset names passed to helpe
|
|
109
110
|
|
110
111
|
#### Webpacker usage
|
111
112
|
|
112
|
-
wicked_pdf supports webpack
|
113
|
+
wicked_pdf supports webpack assets.
|
113
114
|
|
114
|
-
Use `wicked_pdf_stylesheet_pack_tag` for stylesheets
|
115
|
-
Use `wicked_pdf_javascript_pack_tag` for javascripts
|
115
|
+
- Use `wicked_pdf_stylesheet_pack_tag` for stylesheets
|
116
|
+
- Use `wicked_pdf_javascript_pack_tag` for javascripts
|
117
|
+
- Use `wicked_pdf_asset_pack_path` to access an asset directly, for example: `image_tag wicked_pdf_asset_pack_path("media/images/foobar.png")`
|
116
118
|
|
117
119
|
#### Asset pipeline usage
|
118
120
|
|
@@ -124,11 +126,11 @@ It is best to precompile assets used in PDF views. This will help avoid issues w
|
|
124
126
|
|
125
127
|
In this case, you can use that standard Rails helpers and point to the current CDN for whichever framework you are using. For jQuery, it would look somethng like this, given the current versions at the time of this writing.
|
126
128
|
```html
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
<!doctype html>
|
130
|
+
<html>
|
131
|
+
<head>
|
132
|
+
<%= javascript_include_tag "http://code.jquery.com/jquery-1.10.0.min.js" %>
|
133
|
+
<%= javascript_include_tag "http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" %>
|
132
134
|
```
|
133
135
|
|
134
136
|
### Advanced Usage with all available options
|
@@ -144,6 +146,7 @@ class ThingsController < ApplicationController
|
|
144
146
|
render pdf: 'file_name',
|
145
147
|
disposition: 'attachment', # default 'inline'
|
146
148
|
template: 'things/show',
|
149
|
+
locals: {foo: @bar},
|
147
150
|
file: "#{Rails.root}/files/foo.erb",
|
148
151
|
inline: '<!doctype html><html><head></head><body>INLINE HTML</body></html>',
|
149
152
|
layout: 'pdf', # for a pdf.pdf.erb file
|
@@ -182,11 +185,18 @@ class ThingsController < ApplicationController
|
|
182
185
|
enable_plugins: true,
|
183
186
|
disable_internal_links: true,
|
184
187
|
disable_external_links: true,
|
188
|
+
keep_relative_links: true,
|
185
189
|
print_media_type: true,
|
190
|
+
|
191
|
+
# define as true the key 'disable_local_file_access' or 'enable_local_file_access', not both
|
192
|
+
disable_local_file_access: true,
|
193
|
+
enable_local_file_access: false, # must be true when using wkhtmltopdf > 0.12.6
|
194
|
+
|
186
195
|
disable_smart_shrinking: true,
|
187
196
|
use_xserver: true,
|
188
197
|
background: false, # background needs to be true to enable background colors to render
|
189
198
|
no_background: true,
|
199
|
+
no_stop_slow_scripts: false,
|
190
200
|
viewport_size: 'TEXT', # available only with use_xserver or patched QT
|
191
201
|
extra: '', # directly inserted into the command to wkhtmltopdf
|
192
202
|
raise_on_all_errors: nil, # raise error for any stderr output. Such as missing media, image assets
|
@@ -421,8 +431,22 @@ JESii's post [WickedPDF, wkhtmltopdf, and Heroku...a tricky combination](http://
|
|
421
431
|
|
422
432
|
Berislav Babic's post [Send PDF attachments from Rails with WickedPdf and ActionMailer](http://berislavbabic.com/send-pdf-attachments-from-rails-with-wickedpdf-and-actionmailer/)
|
423
433
|
|
434
|
+
Corsego's 2021 post [Complete guide to generating PDFs with gem wicked_pdf](https://blog.corsego.com/gem-wicked-pdf)
|
435
|
+
|
436
|
+
PDFTron's post [How to Generate PDFs With Ruby on Rails](https://www.pdftron.com/blog/rails/how-to-generate-pdf-with-ruby-on-rails/)
|
437
|
+
|
424
438
|
StackOverflow [questions with the tag "wicked-pdf"](http://stackoverflow.com/questions/tagged/wicked-pdf)
|
425
439
|
|
440
|
+
### Screencasts
|
441
|
+
|
442
|
+
* SupeRails Screencast [EN]
|
443
|
+
|
444
|
+
[![Ruby on Rails #17 generate, save, send PDFs with gem wicked_pdf](https://i3.ytimg.com/vi/tFvtwEmW-GE/hqdefault.jpg)](https://youtu.be/tFvtwEmW-GE)
|
445
|
+
|
446
|
+
* codigofacilito Screencast [ES]
|
447
|
+
|
448
|
+
[![Generar PDF con Ruby on Rails - Tutorial](https://i3.ytimg.com/vi/jeWM_gusmJc/hqdefault.jpg)](https://youtu.be/jeWM_gusmJc)
|
449
|
+
|
426
450
|
### Debugging
|
427
451
|
|
428
452
|
Now you can use a debug param on the URL that shows you the content of the pdf in plain html to design it faster.
|
@@ -433,7 +457,7 @@ http://localhost:3001/CONTROLLER/X.pdf?debug
|
|
433
457
|
|
434
458
|
However, the wicked_pdf_* helpers will use file:/// paths for assets when using :show_as_html, and your browser's cross-domain safety feature will kick in, and not render them. To get around this, you can load your assets like so in your templates:
|
435
459
|
```html
|
436
|
-
|
460
|
+
<%= params.key?('debug') ? image_tag('foo') : wicked_pdf_image_tag('foo') %>
|
437
461
|
```
|
438
462
|
|
439
463
|
#### Gotchas
|
@@ -442,6 +466,22 @@ If one image from your HTML cannot be found (relative or wrong path for example)
|
|
442
466
|
|
443
467
|
wkhtmltopdf may render at different resolutions on different platforms. For example, Linux prints at 75 dpi (native for WebKit) while on Windows it's at the desktop's DPI (which is normally 96 dpi). [Use `:zoom => 0.78125`](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2184) (75/96) to match Linux rendering to Windows.
|
444
468
|
|
469
|
+
### Security considerations
|
470
|
+
|
471
|
+
WickedPdf renders page content on the server by saving HTML and assets to temporary files on disk, then executing `wkhtmltopdf` to convert that HTML to a PDF file.
|
472
|
+
|
473
|
+
It is highly recommended if you allow user-generated HTML/CSS/JS to be converted to PDF, you sanitize it first, or at least disallow requesting content from internal IP addresses and hostnames.
|
474
|
+
|
475
|
+
For example, these could potentially leak internal AWS metadata:
|
476
|
+
```html
|
477
|
+
<iframe src="http://169.254.169.254/latest/meta-data/"></iframe>
|
478
|
+
<object data="http://169.254.169.254/latest/meta-data/" type="text/html">
|
479
|
+
```
|
480
|
+
|
481
|
+
Thank you to Adam Gold from [Snyk](https://snyk.io) for reporting this.
|
482
|
+
We are considering adding host allow & block lists and/or potentially HTML element sanitizing.
|
483
|
+
Please open an issue or PR to help us out with this.
|
484
|
+
|
445
485
|
### Inspiration
|
446
486
|
|
447
487
|
You may have noticed: this plugin is heavily inspired by the PrinceXML plugin [princely](http://github.com/mbleigh/princely/tree/master). PrinceXML's cost was prohibitive for me. So, with a little help from some friends (thanks [jqr](http://github.com/jqr)), I tracked down wkhtmltopdf, and here we are.
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rails/version'
|
|
5
5
|
require 'bundler/gem_tasks'
|
6
6
|
|
7
7
|
desc 'Default: run unit tests.'
|
8
|
-
task :default => [
|
8
|
+
task :default => %i[setup_and_run_tests rubocop]
|
9
9
|
|
10
10
|
desc 'Test the wicked_pdf plugin.'
|
11
11
|
Rake::TestTask.new(:test) do |t|
|
@@ -17,16 +17,13 @@ end
|
|
17
17
|
|
18
18
|
desc 'Run RuboCop'
|
19
19
|
task :rubocop do
|
20
|
-
next unless RUBY_VERSION >= '2.0.0'
|
21
20
|
require 'rubocop/rake_task'
|
22
21
|
RuboCop::RakeTask.new
|
23
22
|
end
|
24
23
|
|
25
24
|
desc 'Setup and run all tests'
|
26
25
|
task :setup_and_run_tests do
|
27
|
-
unless File.exist?('test/dummy/config/environment.rb')
|
28
|
-
Rake::Task[:dummy_generate].invoke
|
29
|
-
end
|
26
|
+
Rake::Task[:dummy_generate].invoke unless File.exist?('test/dummy/config/environment.rb')
|
30
27
|
Rake::Task[:test].invoke
|
31
28
|
end
|
32
29
|
|
@@ -34,11 +31,7 @@ desc 'Generate dummy application for test cases'
|
|
34
31
|
task :dummy_generate do
|
35
32
|
Rake::Task[:dummy_remove].invoke
|
36
33
|
puts 'Creating dummy application to run tests'
|
37
|
-
|
38
|
-
system('rails new test/dummy --database=sqlite3')
|
39
|
-
else
|
40
|
-
system('rails test/dummy')
|
41
|
-
end
|
34
|
+
system('rails new test/dummy --database=sqlite3')
|
42
35
|
system('touch test/dummy/db/schema.rb')
|
43
36
|
FileUtils.cp 'test/fixtures/database.yml', 'test/dummy/config/'
|
44
37
|
FileUtils.rm_r Dir.glob('test/dummy/test/*')
|
data/gemfiles/5.0.gemfile
CHANGED
data/gemfiles/5.1.gemfile
CHANGED
data/gemfiles/5.2.gemfile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem '
|
3
|
+
gem 'bootsnap' # required to run `rake test` in Rails 5.2
|
4
4
|
gem 'rails', '~> 5.2'
|
5
|
-
gem '
|
5
|
+
gem 'rdoc'
|
6
6
|
gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
|
7
|
-
gem '
|
8
|
-
gem 'mocha', '= 1.3' # newer versions blow up
|
7
|
+
gem 'sqlite3', '~> 1.3.6'
|
9
8
|
|
10
9
|
gemspec path: '../'
|
data/gemfiles/6.0.gemfile
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
gem 'bootsnap' # required to run `rake test` in Rails 6.0
|
3
4
|
gem 'bundler', '~>2'
|
4
|
-
gem 'rdoc'
|
5
5
|
gem 'rails', '~>6.0.1'
|
6
|
-
gem '
|
6
|
+
gem 'rdoc'
|
7
7
|
gem 'sprockets', '~>3.0'
|
8
|
-
gem '
|
9
|
-
gem 'mocha', '= 1.3' # newer versions blow up
|
8
|
+
gem 'sqlite3', '~> 1.4'
|
10
9
|
|
11
10
|
gemspec path: '../'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'bootsnap' # required to run `rake test` in Rails 6.1
|
4
|
+
gem 'bundler', '~>2'
|
5
|
+
gem 'rails', '~>6.1.0'
|
6
|
+
gem 'webpacker'
|
7
|
+
gem 'rdoc'
|
8
|
+
gem 'sprockets', '~>3.0'
|
9
|
+
gem 'sqlite3', '~> 1.4'
|
10
|
+
gem 'rubocop', '1.11.0'
|
11
|
+
|
12
|
+
gemspec :path => '../'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'bootsnap' # required to run `rake test` in Rails 7.0
|
4
|
+
gem 'bundler', '~>2'
|
5
|
+
gem 'rails', '~>7.0.0'
|
6
|
+
gem 'sprockets-rails'
|
7
|
+
gem 'rdoc'
|
8
|
+
gem 'sprockets', '~>3.0'
|
9
|
+
gem 'sqlite3', '~> 1.4'
|
10
|
+
gem 'rubocop', '1.11.0'
|
11
|
+
|
12
|
+
gemspec :path => '../'
|
@@ -15,7 +15,16 @@ WickedPdf.config = {
|
|
15
15
|
# or
|
16
16
|
# exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
|
17
17
|
|
18
|
+
# Needed for wkhtmltopdf 0.12.6+ to use many wicked_pdf asset helpers
|
19
|
+
# enable_local_file_access: true,
|
20
|
+
|
18
21
|
# Layout file to be used for all PDFs
|
19
22
|
# (but can be overridden in `render :pdf` calls)
|
20
23
|
# layout: 'pdf.html',
|
24
|
+
|
25
|
+
# Using wkhtmltopdf without an X server can be achieved by enabling the
|
26
|
+
# 'use_xvfb' flag. This will wrap all wkhtmltopdf commands around the
|
27
|
+
# 'xvfb-run' command, in order to simulate an X server.
|
28
|
+
#
|
29
|
+
# use_xvfb: true,
|
21
30
|
}
|