wicked_pdf 2.7.0 → 2.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 120e7e1b14e3e17ac6bc407dd6c7d27438543e87a979d684bab919440ebd7879
4
- data.tar.gz: f9340f26589900f6f30c19f5631ca2104b48685b9ac102c3bdc2e9d168c0c847
3
+ metadata.gz: a0ccf42076502bc818ca5387b97d300bad8ebf99c0ecdcc024ea1a2e4d2c45a6
4
+ data.tar.gz: aaa9779f4c8ee4baf5b6e5ce27d7ebd7396e6b565c59263fc0a7db6f6e0518e9
5
5
  SHA512:
6
- metadata.gz: f26972b5aa38ac4785ffddd283e787ec49361ae1891d66b8bfe92d3e9b196d4215a03cec3ffced97ec5269f0316f53f0a24374c26a1df255898a01241b85ce57
7
- data.tar.gz: 0d00bcb4d776acb3a469dfb55e0994ca22eab620694b92f7433a4a93aa91a07653848bef7bd3eaff709d861fdf6bf1260cd8ad048be9e671f8f26d78f37d0300
6
+ metadata.gz: d2e93a8024b529dadccf861026e916c4d75270d821f038bb4c5dd8d12f1bd73bae451ba288fc62e7e10d35380a573a4d554c8da0d39c2490c6ca38b6666590a7
7
+ data.tar.gz: 5624cbb405350aa731ffc9910e70d286dabdb833b15a38235f2b933a842e3c6ce9342001bd779a72abac668fe84455f32f9cb58cdad7417e62e2fcec6817856f
data/CHANGELOG.md CHANGED
@@ -1,9 +1,25 @@
1
1
  # Change Log
2
- All notable changes to this project will be documented in this file.
3
- This project adheres to [Semantic Versioning](http://semver.org/).
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.1...HEAD)
6
6
  ### Breaking Changes
7
+ ### New Features
8
+ ### Fixes
9
+
10
+ ## [2.8.1]
11
+ ### Fixes
12
+ - [Explicitly require OpenStruct, which isn't loaded by default anymore in new versions of Rake](https://github.com/mileszs/wicked_pdf/pull/1110)
13
+ - [Ensure assets without extensions are handled correctly](https://github.com/mileszs/wicked_pdf/pull/1115)
14
+
15
+ ## [2.8.0]
16
+ ### New Features
17
+ - [Add New config option `raise_on_missing_assets`](https://github.com/mileszs/wicked_pdf/pull/1094)
18
+ - [Add support for truffleruby (22.1.0) on Linux](https://github.com/mileszs/wicked_pdf/pull/1028)
19
+
20
+ ### Fixes
21
+ - [Fix Propshaft encoding issue](https://github.com/mileszs/wicked_pdf/pull/1096)
22
+ - [Fix Webpacker & Shakapacker compatibility issue](https://github.com/mileszs/wicked_pdf/pull/1099)
7
23
 
8
24
  ## [2.7.0]
9
25
  ### New Features
@@ -231,13 +247,3 @@ This project adheres to [Semantic Versioning](http://semver.org/).
231
247
  - Issues with `url()` references and embedded `data:base64` assets in stylesheets rendered with `wicked_pdf_stylesheet_link_tag`
232
248
  - Asset helpers no longer add a file extension if it already is specified with one
233
249
 
234
- # Compare Releases
235
- - [2.1.0...HEAD (unreleased changes)](https://github.com/mileszs/wicked_pdf/compare/2.1.0...HEAD)
236
- - [2.0.2...2.1.0](https://github.com/mileszs/wicked_pdf/compare/2.0.2...2.1.0)
237
- - [2.0.0...2.0.2](https://github.com/mileszs/wicked_pdf/compare/2.0.0...2.0.2)
238
- - [1.4.0...2.0.0](https://github.com/mileszs/wicked_pdf/compare/1.4.0...2.0.0)
239
- - [1.3.0...1.4.0](https://github.com/mileszs/wicked_pdf/compare/1.3.0...1.4.0)
240
- - [1.2.0...1.3.0](https://github.com/mileszs/wicked_pdf/compare/1.2.0...1.3.0)
241
- - [1.1.0...1.2.0](https://github.com/mileszs/wicked_pdf/compare/1.1.0...1.2.0)
242
- - [1.0.0...1.1.0](https://github.com/mileszs/wicked_pdf/compare/1.0.0...1.0.0)
243
- - [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.6; Rails 4 through 6.1_
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.config = {
46
- exe_path: '/usr/local/bin/wkhtmltopdf',
47
- enable_local_file_access: true
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/).
@@ -201,6 +201,7 @@ class ThingsController < ApplicationController
201
201
  viewport_size: 'TEXT', # available only with use_xserver or patched QT
202
202
  extra: '', # directly inserted into the command to wkhtmltopdf
203
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
204
205
  log_level: 'info', # Available values: none, error, warn, or info - only available with wkhtmltopdf 0.12.5+
205
206
  quiet: false, # `false` is same as `log_level: 'info'`, `true` is same as `log_level: 'none'`
206
207
  outline: { outline: true,
@@ -8,23 +8,23 @@
8
8
  #
9
9
  # https://github.com/mileszs/wicked_pdf/blob/master/README.md
10
10
 
11
- WickedPdf.config = {
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: '/usr/local/bin/wkhtmltopdf',
14
+ # config.exe_path = '/usr/local/bin/wkhtmltopdf'
15
15
  # or
16
- # exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
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: true,
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: 'pdf.html',
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: true,
30
- }
29
+ # config.use_xvfb = true
30
+ end
@@ -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)
@@ -1,3 +1,3 @@
1
1
  class WickedPdf
2
- VERSION = '2.7.0'.freeze
2
+ VERSION = '2.8.1'.freeze
3
3
  end
@@ -7,6 +7,27 @@ class WickedPdf
7
7
  module Assets
8
8
  ASSET_URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/
9
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
+
10
31
  class PropshaftAsset < SimpleDelegator
11
32
  def content_type
12
33
  super.to_s
@@ -21,9 +42,39 @@ class WickedPdf
21
42
  end
22
43
  end
23
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
+
24
75
  def wicked_pdf_asset_base64(path)
25
76
  asset = find_asset(path)
26
- raise "Could not find asset '#{path}'" if asset.nil?
77
+ raise MissingLocalAsset, path if asset.nil?
27
78
 
28
79
  base64 = Base64.encode64(asset.to_s).gsub(/\s+/, '')
29
80
  "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
@@ -150,8 +201,30 @@ class WickedPdf
150
201
  Rails.application.assets.find_asset(path, :base_path => Rails.application.root.to_s)
151
202
  elsif defined?(Propshaft::Assembly) && Rails.application.assets.is_a?(Propshaft::Assembly)
152
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)
210
+ else
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
153
226
  else
154
- Sprockets::Railtie.build_environment(Rails.application).find_asset(path, :base_path => Rails.application.root.to_s)
227
+ assets[path]
155
228
  end
156
229
  end
157
230
 
@@ -175,20 +248,35 @@ class WickedPdf
175
248
  end
176
249
 
177
250
  def read_asset(source)
178
- if precompiled_or_absolute_asset?(source)
179
- pathname = asset_pathname(source)
180
- if pathname =~ URI_REGEXP
181
- read_from_uri(pathname)
182
- elsif File.file?(pathname)
183
- IO.read(pathname)
184
- end
185
- else
186
- find_asset(source).to_s
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]
187
267
  end
188
268
  end
189
269
 
190
270
  def read_from_uri(uri)
191
- asset = Net::HTTP.get(URI(uri))
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
192
280
  asset.force_encoding('UTF-8') if asset
193
281
  asset = gzip(asset) if WickedPdf.config[:expect_gzipped_remote_assets]
194
282
  asset
@@ -232,8 +320,10 @@ class WickedPdf
232
320
 
233
321
  def webpacker_version
234
322
  if defined?(Shakapacker)
323
+ require 'shakapacker/version'
235
324
  Shakapacker::VERSION
236
325
  elsif defined?(Webpacker)
326
+ require 'webpacker/version'
237
327
  Webpacker::VERSION
238
328
  end
239
329
  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
@@ -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')
@@ -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
@@ -37,4 +37,5 @@ DESC
37
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
+ spec.add_development_dependency 'webmock', '~> 3.19'
40
41
  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.7.0
4
+ version: 2.8.1
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: 2023-08-24 00:00:00.000000000 Z
12
+ date: 2024-08-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: webmock
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '3.19'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '3.19'
126
140
  description: |
127
141
  Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML.
128
142
  In other words, rather than dealing with a PDF generation DSL of some sort,
@@ -168,6 +182,7 @@ files:
168
182
  - test/fixtures/database.yml
169
183
  - test/fixtures/document_with_long_line.html
170
184
  - test/fixtures/manifest.js
185
+ - test/fixtures/subdirectory/nested.js
171
186
  - test/fixtures/wicked.css
172
187
  - test/fixtures/wicked.js
173
188
  - test/functional/pdf_helper_test.rb
@@ -200,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
215
  version: '0'
201
216
  requirements:
202
217
  - wkhtmltopdf
203
- rubygems_version: 3.3.7
218
+ rubygems_version: 3.4.19
204
219
  signing_key:
205
220
  specification_version: 4
206
221
  summary: PDF generator (from HTML) gem for Ruby on Rails
@@ -208,6 +223,7 @@ test_files:
208
223
  - test/fixtures/database.yml
209
224
  - test/fixtures/document_with_long_line.html
210
225
  - test/fixtures/manifest.js
226
+ - test/fixtures/subdirectory/nested.js
211
227
  - test/fixtures/wicked.css
212
228
  - test/fixtures/wicked.js
213
229
  - test/functional/pdf_helper_test.rb