wicked_pdf 2.6.3 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efc167edf11352423548ba65167d53beb2e8e60691fb788df361d19c636e7f45
4
- data.tar.gz: e4c6e40dbbb8ba3867e3fbfa1aadbd151c87355f898dbad629f58a2e39f8a4c4
3
+ metadata.gz: 120e7e1b14e3e17ac6bc407dd6c7d27438543e87a979d684bab919440ebd7879
4
+ data.tar.gz: f9340f26589900f6f30c19f5631ca2104b48685b9ac102c3bdc2e9d168c0c847
5
5
  SHA512:
6
- metadata.gz: 345c533e38faa42be7700d76e6ff761583c1856f30bf12c55fbff410c77d224f5ed0f7698006316e3565d656a9e4db5cef1936f5ec718957e3652cce85e35b03
7
- data.tar.gz: 00b0cb2ee4c76840d71d984f39987dc04ea23a854d2f38c01b3f21f18ecb7f60c980f477e3eb94a8c1b2b79cda43cb050f521d0003d9306b31cebd8b273dd5ea
6
+ metadata.gz: f26972b5aa38ac4785ffddd283e787ec49361ae1891d66b8bfe92d3e9b196d4215a03cec3ffced97ec5269f0316f53f0a24374c26a1df255898a01241b85ce57
7
+ data.tar.gz: 0d00bcb4d776acb3a469dfb55e0994ca22eab620694b92f7433a4a93aa91a07653848bef7bd3eaff709d861fdf6bf1260cd8ad048be9e671f8f26d78f37d0300
@@ -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: /home/runner/work/wicked_pdf/wicked_pdf/gemfiles/${{ matrix.gemfile }}.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@v2
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 gem dependencies
53
- run: bundle install
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
@@ -2,10 +2,12 @@ inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
4
  NewCops: disable
5
+ SuggestExtensions: false
5
6
  TargetRubyVersion: 2.6
6
7
  Exclude:
7
8
  - 'gemfiles/bin/*'
8
9
  - 'test/dummy/**/*'
10
+ - 'vendor/**/*'
9
11
 
10
12
  Metrics/PerceivedComplexity:
11
13
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,45 +1,39 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-10-09 14:16:04 +0200 using RuboCop version 0.68.1.
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: 250
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: 40
22
+ Max: 34
26
23
 
27
- # Offense count: 2
28
- # Configuration parameters: CountComments.
24
+ # Offense count: 1
25
+ # Configuration parameters: CountComments, CountAsOne.
29
26
  Metrics/ModuleLength:
30
- Max: 147
27
+ Max: 104
31
28
 
32
- # Offense count: 6
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: 10
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
- # Cop supports --auto-correct.
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: 8
77
- # Cop supports --auto-correct.
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
- # Cop supports --auto-correct.
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: 6
100
- # Cop supports --auto-correct.
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: 111
110
- # Cop supports --auto-correct.
111
- # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
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
- Metrics/LineLength:
104
+ Layout/LineLength:
114
105
  Max: 563
data/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  ## [master branch] - Unreleased
6
6
  ### Breaking Changes
7
7
 
8
+ ## [2.7.0]
9
+ ### New Features
10
+ - [Support Shakapacker 7](https://github.com/mileszs/wicked_pdf/pull/1067)
11
+ - [Add option `delete_temporary_files` to keep the temporary files generated by `pdf_from_string` method](https://github.com/mileszs/wicked_pdf/pull/1068)
12
+ - [Add support for --allow flag](https://github.com/mileszs/wicked_pdf/pull/1030)
13
+
14
+ ## Fixes
15
+ - [Add require for `stringio`, which is no longer loaded by default in Ruby 3.1+](https://github.com/mileszs/wicked_pdf/pull/1062)
16
+ - [Fix CI build.](https://github.com/mileszs/wicked_pdf/pull/1055)
17
+ - [Fix Header/footer temporary file is removed before `wkhtmltopdf` is called](https://github.com/mileszs/wicked_pdf/pull/1039)
18
+ - [Bump rubocop to 1.46](https://github.com/mileszs/wicked_pdf/pull/1051)
19
+ - [Add Ruby 3.2 to the test matrix](https://github.com/mileszs/wicked_pdf/pull/1046)
20
+
8
21
  ## [2.6.3]
9
22
  ### Fixes
10
23
  - [Fix typo of #possible_binary_locations](https://github.com/mileszs/wicked_pdf/pull/1025)
data/README.md CHANGED
@@ -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,
@@ -258,7 +259,8 @@ class ThingsController < ApplicationController
258
259
  disable_toc_links: true,
259
260
  disable_back_links:true,
260
261
  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
262
+ progress: proc { |output| puts output }, # proc called when console output changes
263
+ delete_temporary_files: true # explicitly delete temporary files, default false
262
264
  end
263
265
  end
264
266
  end
@@ -293,14 +295,14 @@ pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here')
293
295
  # create a pdf from a URL
294
296
  pdf = WickedPdf.new.pdf_from_url('https://github.com/mileszs/wicked_pdf')
295
297
 
296
- # create a pdf from string using templates, layouts and content option for header or footer
298
+ # create a pdf from string using templates, layouts, and content option for header or footer
297
299
  pdf = WickedPdf.new.pdf_from_string(
298
300
  render_to_string('templates/pdf', layout: 'pdfs/layout_pdf.html'),
299
301
  footer: {
300
302
  content: render_to_string(
301
- 'templates/footer',
302
- layout: 'pdfs/layout_pdf.html'
303
- )
303
+ 'templates/footer',
304
+ layout: 'pdfs/layout_pdf.html'
305
+ )
304
306
  }
305
307
  )
306
308
 
data/gemfiles/6.1.gemfile CHANGED
@@ -7,6 +7,5 @@ gem 'webpacker'
7
7
  gem 'rdoc'
8
8
  gem 'sprockets', '~>3.0'
9
9
  gem 'sqlite3', '~> 1.4'
10
- gem 'rubocop', '1.11.0'
11
10
 
12
11
  gemspec :path => '../'
data/gemfiles/7.0.gemfile CHANGED
@@ -7,6 +7,5 @@ gem 'sprockets-rails'
7
7
  gem 'rdoc'
8
8
  gem 'sprockets', '~>3.0'
9
9
  gem 'sqlite3', '~> 1.4'
10
- gem 'rubocop', '1.11.0'
11
10
 
12
11
  gemspec :path => '../'
@@ -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 = WickedPdf::Tempfile.new("wicked_#{hf}_pdf.html"))
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
@@ -1,4 +1,5 @@
1
1
  require 'tempfile'
2
+ require 'stringio'
2
3
 
3
4
  class WickedPdf
4
5
  class Tempfile < ::Tempfile
@@ -1,3 +1,3 @@
1
1
  class WickedPdf
2
- VERSION = '2.6.3'.freeze
2
+ VERSION = '2.7.0'.freeze
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'delegate'
3
+ require 'stringio'
3
4
 
4
5
  class WickedPdf
5
6
  module WickedPdfHelper
@@ -230,12 +231,11 @@ class WickedPdf
230
231
  end
231
232
 
232
233
  def webpacker_version
233
- return unless defined?(Webpacker)
234
-
235
- # If webpacker is used, need to check for version
236
- require 'webpacker/version'
237
-
238
- Webpacker::VERSION
234
+ if defined?(Shakapacker)
235
+ Shakapacker::VERSION
236
+ elsif defined?(Webpacker)
237
+ Webpacker::VERSION
238
+ end
239
239
  end
240
240
  end
241
241
  end
data/lib/wicked_pdf.rb CHANGED
@@ -43,16 +43,20 @@ class WickedPdf
43
43
  string_file.write_in_chunks(string)
44
44
  pdf_from_html_file(string_file.path, options)
45
45
  ensure
46
- string_file.close if string_file
46
+ if options[:delete_temporary_files] && string_file
47
+ string_file.close!
48
+ elsif string_file
49
+ string_file.close
50
+ end
47
51
  end
48
52
 
49
- def pdf_from_url(url, options = {})
53
+ def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity
50
54
  # merge in global config options
51
55
  options.merge!(WickedPdf.config) { |_key, option, _config| option }
52
56
  generated_pdf_file = WickedPdf::Tempfile.new('wicked_pdf_generated_file.pdf', options[:temp_path])
53
57
  command = [@binary.path]
54
58
  command.unshift(@binary.xvfb_run_path) if options[:use_xvfb]
55
- command += parse_options(options)
59
+ command += option_parser.parse(options)
56
60
  command << url
57
61
  command << generated_pdf_file.path.to_s
58
62
 
@@ -61,9 +65,8 @@ class WickedPdf
61
65
  if track_progress?(options)
62
66
  invoke_with_progress(command, options)
63
67
  else
64
- err = Open3.popen3(*command) do |_stdin, _stdout, stderr|
65
- stderr.read
66
- end
68
+ _out, err, status = Open3.capture3(*command)
69
+ err = [status.to_s, err].join("\n") if !err.empty? || !status.success?
67
70
  end
68
71
  if options[:return_file]
69
72
  return_file = options.delete(:return_file)
@@ -79,6 +82,7 @@ class WickedPdf
79
82
  rescue StandardError => e
80
83
  raise "Failed to execute:\n#{command}\nError: #{e}"
81
84
  ensure
85
+ clean_temp_files
82
86
  generated_pdf_file.close! if generated_pdf_file && !return_file
83
87
  end
84
88
 
@@ -98,7 +102,13 @@ class WickedPdf
98
102
  Rails.logger.debug '[wicked_pdf]: ' + cmd
99
103
  end
100
104
 
101
- def parse_options(options)
102
- OptionParser.new(binary_version).parse(options)
105
+ def option_parser
106
+ @option_parser ||= OptionParser.new(binary_version)
107
+ end
108
+
109
+ def clean_temp_files
110
+ return unless option_parser.hf_tempfiles.present?
111
+
112
+ option_parser.hf_tempfiles.each { |file| File.delete(file) }
103
113
  end
104
114
  end
@@ -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
data/wicked_pdf.gemspec CHANGED
@@ -34,7 +34,7 @@ DESC
34
34
  spec.add_development_dependency 'mocha', '= 1.3'
35
35
  spec.add_development_dependency 'rails'
36
36
  spec.add_development_dependency 'rake'
37
- spec.add_development_dependency 'rubocop', '~> 1.24'
37
+ spec.add_development_dependency 'rubocop', '~> 1.46'
38
38
  spec.add_development_dependency 'sqlite3', '~> 1.3'
39
39
  spec.add_development_dependency 'test-unit'
40
40
  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.6.3
4
+ version: 2.7.0
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: 2022-05-19 00:00:00.000000000 Z
12
+ date: 2023-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '1.24'
90
+ version: '1.46'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '1.24'
97
+ version: '1.46'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: sqlite3
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements:
202
202
  - wkhtmltopdf
203
- rubygems_version: 3.2.3
203
+ rubygems_version: 3.3.7
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: PDF generator (from HTML) gem for Ruby on Rails