wicked_pdf 2.7.0 → 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/CHANGELOG.md +24 -13
- data/README.md +6 -5
- data/generators/wicked_pdf/templates/wicked_pdf.rb +7 -7
- data/lib/wicked_pdf/progress.rb +2 -2
- data/lib/wicked_pdf/tempfile.rb +3 -3
- data/lib/wicked_pdf/version.rb +1 -1
- data/lib/wicked_pdf/wicked_pdf_helper/assets.rb +102 -12
- data/lib/wicked_pdf.rb +19 -1
- 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_test.rb +17 -0
- data/wicked_pdf.gemspec +2 -0
- metadata +33 -3
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/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
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)
|
|
7
28
|
|
|
8
29
|
## [2.7.0]
|
|
9
30
|
### New Features
|
|
@@ -231,13 +252,3 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
231
252
|
- Issues with `url()` references and embedded `data:base64` assets in stylesheets rendered with `wicked_pdf_stylesheet_link_tag`
|
|
232
253
|
- Asset helpers no longer add a file extension if it already is specified with one
|
|
233
254
|
|
|
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
|
|
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/).
|
|
@@ -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.
|
|
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
|
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
|
@@ -23,9 +23,9 @@ class WickedPdf
|
|
|
23
23
|
def read_in_chunks
|
|
24
24
|
rewind
|
|
25
25
|
binmode
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
chunks = []
|
|
27
|
+
chunks << read(chunk_size) until eof?
|
|
28
|
+
chunks.join
|
|
29
29
|
rescue Errno::EINVAL => e
|
|
30
30
|
raise e, file_too_large_message
|
|
31
31
|
end
|
data/lib/wicked_pdf/version.rb
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
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
|
@@ -29,6 +29,7 @@ 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'
|
|
@@ -37,4 +38,5 @@ DESC
|
|
|
37
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
|
|
@@ -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
|