wicked_pdf 2.8.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: ad0741c1e5c8b253601a248d448f53fe359547238517a6340c7ac340f4bf2e15
4
- data.tar.gz: 1da781d4aa577dd9afb1e90c734c1507d4458d85d7a381dc0f005582dcd064a5
3
+ metadata.gz: a0ccf42076502bc818ca5387b97d300bad8ebf99c0ecdcc024ea1a2e4d2c45a6
4
+ data.tar.gz: aaa9779f4c8ee4baf5b6e5ce27d7ebd7396e6b565c59263fc0a7db6f6e0518e9
5
5
  SHA512:
6
- metadata.gz: dd1a3651d3ad14d2c0c8515e81f9cc75bbe617633e956127f77e6d287a761402f5b8d1448641772bf7e69cb16fefd5b38547da9628df43fdb0e6623b11527e9d
7
- data.tar.gz: f4d1cd6cd91e60f4874e4ad269056a5af32da101e0e03a54231d701958d304f14beacfa9b262559fb56c5375b6899046c8a23090afde226721613d4e0db4f118
6
+ metadata.gz: d2e93a8024b529dadccf861026e916c4d75270d821f038bb4c5dd8d12f1bd73bae451ba288fc62e7e10d35380a573a4d554c8da0d39c2490c6ca38b6666590a7
7
+ data.tar.gz: 5624cbb405350aa731ffc9910e70d286dabdb833b15a38235f2b933a842e3c6ce9342001bd779a72abac668fe84455f32f9cb58cdad7417e62e2fcec6817856f
data/CHANGELOG.md CHANGED
@@ -2,11 +2,16 @@
2
2
  All notable changes to this project should be documented in this file.
3
3
  This project attempts to adhere to [Semantic Versioning](http://semver.org/).
4
4
 
5
- ## [[master branch] - Unreleased changes](https://github.com/mileszs/wicked_pdf/compare/2.8.0...HEAD)
5
+ ## [[master branch] - Unreleased changes](https://github.com/mileszs/wicked_pdf/compare/2.8.1...HEAD)
6
6
  ### Breaking Changes
7
7
  ### New Features
8
8
  ### Fixes
9
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
+
10
15
  ## [2.8.0]
11
16
  ### New Features
12
17
  - [Add New config option `raise_on_missing_assets`](https://github.com/mileszs/wicked_pdf/pull/1094)
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
 
@@ -43,9 +43,9 @@ If your wkhtmltopdf executable is not on your webserver's path, you can configur
43
43
 
44
44
  ```ruby
45
45
  WickedPdf.configure do |c|
46
- c.exe_path = '/usr/local/bin/wkhtmltopdf',
46
+ c.exe_path = '/usr/local/bin/wkhtmltopdf'
47
47
  c.enable_local_file_access = true
48
- }
48
+ end
49
49
  ```
50
50
 
51
51
  For more information about `wkhtmltopdf`, see the project's [homepage](http://wkhtmltopdf.org/).
@@ -11,20 +11,20 @@
11
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
- # config.exe_path = '/usr/local/bin/wkhtmltopdf',
14
+ # config.exe_path = '/usr/local/bin/wkhtmltopdf'
15
15
  # or
16
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
- # config.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
- # config.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
- # config.use_xvfb = true,
29
+ # config.use_xvfb = true
30
30
  end
@@ -1,3 +1,3 @@
1
1
  class WickedPdf
2
- VERSION = '2.8.0'.freeze
2
+ VERSION = '2.8.1'.freeze
3
3
  end
@@ -202,13 +202,32 @@ class WickedPdf
202
202
  elsif defined?(Propshaft::Assembly) && Rails.application.assets.is_a?(Propshaft::Assembly)
203
203
  PropshaftAsset.new(Rails.application.assets.load_path.find(path))
204
204
  elsif Rails.application.respond_to?(:assets_manifest)
205
- asset_path = File.join(Rails.application.assets_manifest.dir, Rails.application.assets_manifest.assets[path])
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)
206
209
  LocalAsset.new(asset_path) if File.file?(asset_path)
207
210
  else
208
211
  SprocketsEnvironment.find_asset(path, :base_path => Rails.application.root.to_s)
209
212
  end
210
213
  end
211
214
 
215
+ def get_asset_path_from_manifest(path)
216
+ assets = Rails.application.assets_manifest.assets
217
+
218
+ if File.extname(path).empty?
219
+ assets.find do |asset, _v|
220
+ directory = File.dirname(asset)
221
+ asset_path = File.basename(asset, File.extname(asset))
222
+ asset_path = File.join(directory, asset_path) if directory != '.'
223
+
224
+ asset_path == path
225
+ end&.last
226
+ else
227
+ assets[path]
228
+ end
229
+ end
230
+
212
231
  # will prepend a http or default_protocol to a protocol relative URL
213
232
  # or when no protcol is set.
214
233
  def prepend_protocol(source)
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'
@@ -0,0 +1 @@
1
+ // Nested js
@@ -11,6 +11,10 @@ class WickedPdfHelperAssetsTest < ActionView::TestCase
11
11
 
12
12
  teardown do
13
13
  WickedPdf.config = @saved_config
14
+
15
+ # @see freerange/mocha#331
16
+ Rails.application.unstub(:assets)
17
+ Rails.application.unstub(:assets_manifest)
14
18
  end
15
19
 
16
20
  if Rails::VERSION::MAJOR > 3 || (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0)
@@ -18,12 +22,61 @@ class WickedPdfHelperAssetsTest < ActionView::TestCase
18
22
  assert_match %r{data:text\/css;base64,.+}, wicked_pdf_asset_base64('wicked.css')
19
23
  end
20
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
+
21
55
  test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in' do
22
56
  Rails.configuration.assets.expects(:compile => true)
23
57
  assert_equal "<style type='text/css'>/* Wicked styles */\n\n</style>",
24
58
  wicked_pdf_stylesheet_link_tag('wicked')
25
59
  end
26
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
+
27
80
  test 'wicked_pdf_stylesheet_link_tag should raise if the stylesheet is not available and config is set' do
28
81
  Rails.configuration.assets.expects(:compile => true)
29
82
  WickedPdf.config[:raise_on_missing_assets] = true
@@ -60,6 +113,21 @@ class WickedPdfHelperAssetsTest < ActionView::TestCase
60
113
  wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
61
114
  end
62
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
+
63
131
  test 'wicked_pdf_stylesheet_link_tag should raise if remote assets are not available and config is set' do
64
132
  WickedPdf.config[:raise_on_missing_assets] = true
65
133
  stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 404, :body => 'File not found')
data/test/test_helper.rb CHANGED
@@ -27,6 +27,11 @@ if (assets_dir = Rails.root.join('app/assets')) && File.directory?(assets_dir)
27
27
  source = File.read('test/fixtures/wicked.js')
28
28
  File.open(destination, 'w') { |f| f.write(source) }
29
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
+
30
35
  config_dir = assets_dir.join('config')
31
36
  Dir.mkdir(config_dir) unless File.directory?(config_dir)
32
37
  source = File.read('test/fixtures/manifest.js')
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.8.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: 2024-02-27 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
@@ -182,6 +182,7 @@ files:
182
182
  - test/fixtures/database.yml
183
183
  - test/fixtures/document_with_long_line.html
184
184
  - test/fixtures/manifest.js
185
+ - test/fixtures/subdirectory/nested.js
185
186
  - test/fixtures/wicked.css
186
187
  - test/fixtures/wicked.js
187
188
  - test/functional/pdf_helper_test.rb
@@ -222,6 +223,7 @@ test_files:
222
223
  - test/fixtures/database.yml
223
224
  - test/fixtures/document_with_long_line.html
224
225
  - test/fixtures/manifest.js
226
+ - test/fixtures/subdirectory/nested.js
225
227
  - test/fixtures/wicked.css
226
228
  - test/fixtures/wicked.js
227
229
  - test/functional/pdf_helper_test.rb