wicked_pdf 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/{CHANGLOG.md → CHANGELOG.md} +1 -3
- data/lib/wicked_pdf/pdf_helper.rb +1 -1
- data/lib/wicked_pdf/version.rb +1 -1
- data/lib/wicked_pdf/wicked_pdf_helper/assets.rb +18 -19
- data/test/functional/wicked_pdf_helper_assets_test.rb +52 -9
- data/test/test_helper.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb2f6a218b4808fb3f117148379101db09cffb8
|
4
|
+
data.tar.gz: 3d87582716a2d79e4f7b635f4297e50744d47e0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0579b69ec2897374a6bac52f44306e6c15da9252f09f3f0d6bbbc89a3161f5c4cf47218593a70d9884b9a043f0ca8c5d8c8fdebf38edb9457510cf6706cf2d2a
|
7
|
+
data.tar.gz: be80b3dd951f1a12065237cc5db3ab019b5e048c337e8c3666cc21d7a3685bcee3b5415d566a19ca73631adf7c5757c14115769460b96b13b9497ce18ec85e46
|
data/.travis.yml
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
language:
|
2
2
|
- ruby
|
3
|
+
before_install:
|
4
|
+
- sudo apt-get update -qq
|
5
|
+
- gem update bundler
|
3
6
|
bundler_args: --verbose
|
4
7
|
sudo: required
|
5
8
|
rvm:
|
@@ -26,6 +29,7 @@ matrix:
|
|
26
29
|
include:
|
27
30
|
- rvm: 1.8.7
|
28
31
|
before_install:
|
32
|
+
- sudo apt-get update -qq
|
29
33
|
- gem update --system 1.8.25
|
30
34
|
- gem --version
|
31
35
|
gemfile: gemfiles/2.3.gemfile
|
@@ -2,9 +2,7 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
-
##
|
6
|
-
|
7
|
-
## [1.0.1] - 2015-11-30
|
5
|
+
## [master] - Unpublished
|
8
6
|
### Changed
|
9
7
|
- The default dpi is now 72. Previously the default would be whatever your `wkhtmltopdf` version specified as the default. This change [speeds up generation of documents that contain `border-radius` dramatically](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1510)
|
10
8
|
|
data/lib/wicked_pdf/version.rb
CHANGED
@@ -21,8 +21,7 @@ module WickedPdfHelper
|
|
21
21
|
if Regexp.last_match[1].starts_with?('data:')
|
22
22
|
"url(#{Regexp.last_match[1]})"
|
23
23
|
else
|
24
|
-
|
25
|
-
"url(#{wicked_pdf_asset_path(asset)})" if asset_exists?(asset)
|
24
|
+
"url(#{wicked_pdf_asset_path(Regexp.last_match[1])})"
|
26
25
|
end
|
27
26
|
end.html_safe
|
28
27
|
end
|
@@ -57,15 +56,17 @@ module WickedPdfHelper
|
|
57
56
|
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}
|
58
57
|
|
59
58
|
def asset_pathname(source)
|
60
|
-
if
|
61
|
-
|
59
|
+
if precompiled_or_absolute_asset?(source)
|
60
|
+
asset = asset_path(source)
|
61
|
+
if (pathname = set_protocol(asset)) =~ URI_REGEXP
|
62
62
|
# asset_path returns an absolute URL using asset_host if asset_host is set
|
63
63
|
pathname
|
64
64
|
else
|
65
|
-
File.join(Rails.public_path,
|
65
|
+
File.join(Rails.public_path, asset.sub(/\A#{Rails.application.config.action_controller.relative_url_root}/, ''))
|
66
66
|
end
|
67
67
|
else
|
68
|
-
Rails.application.assets.find_asset(source)
|
68
|
+
asset = Rails.application.assets.find_asset(source)
|
69
|
+
asset ? asset.pathname : File.join(Rails.public_path, source)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
@@ -81,25 +82,27 @@ module WickedPdfHelper
|
|
81
82
|
source
|
82
83
|
end
|
83
84
|
|
84
|
-
def
|
85
|
-
Rails.configuration.assets.compile == false ||
|
85
|
+
def precompiled_or_absolute_asset?(source)
|
86
|
+
Rails.configuration.assets.compile == false ||
|
87
|
+
source.to_s[0] == '/' ||
|
88
|
+
source.to_s.match(/\Ahttps?\:\/\//)
|
86
89
|
end
|
87
90
|
|
88
91
|
def read_asset(source)
|
89
|
-
if
|
90
|
-
if
|
91
|
-
read_from_uri(
|
92
|
-
elsif
|
93
|
-
IO.read(
|
92
|
+
if precompiled_or_absolute_asset?(source)
|
93
|
+
if (pathname = asset_pathname(source)) =~ URI_REGEXP
|
94
|
+
read_from_uri(pathname)
|
95
|
+
elsif File.file?(pathname)
|
96
|
+
IO.read(pathname)
|
94
97
|
end
|
95
98
|
else
|
96
99
|
Rails.application.assets.find_asset(source).to_s
|
97
100
|
end
|
98
101
|
end
|
99
102
|
|
100
|
-
def read_from_uri(
|
103
|
+
def read_from_uri(uri)
|
101
104
|
encoding = ':UTF-8' if RUBY_VERSION > '1.8'
|
102
|
-
asset = open(
|
105
|
+
asset = open(uri, "r#{encoding}") { |f| f.read }
|
103
106
|
asset = gzip(asset) if WickedPdf.config[:expect_gzipped_remote_assets]
|
104
107
|
asset
|
105
108
|
end
|
@@ -110,9 +113,5 @@ module WickedPdfHelper
|
|
110
113
|
gzipper.read
|
111
114
|
rescue Zlib::GzipFile::Error
|
112
115
|
end
|
113
|
-
|
114
|
-
def asset_exists?(source)
|
115
|
-
Rails.application.assets.find_asset(source).present?
|
116
|
-
end
|
117
116
|
end
|
118
117
|
end
|
@@ -6,9 +6,6 @@ class WickedPdfHelperAssetsTest < ActionView::TestCase
|
|
6
6
|
|
7
7
|
if Rails::VERSION::MAJOR > 3 || (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0)
|
8
8
|
test 'wicked_pdf_asset_base64 returns a base64 encoded asset' do
|
9
|
-
source = File.new('test/fixtures/wicked.css', 'r')
|
10
|
-
destination = Rails.root.join('app', 'assets', 'stylesheets', 'wicked.css')
|
11
|
-
File.open(destination, 'w') { |f| f.write(source) }
|
12
9
|
assert_match /data:text\/css;base64,.+/, wicked_pdf_asset_base64('wicked.css')
|
13
10
|
end
|
14
11
|
|
@@ -18,28 +15,74 @@ class WickedPdfHelperAssetsTest < ActionView::TestCase
|
|
18
15
|
end
|
19
16
|
|
20
17
|
test 'wicked_pdf_asset_path should return a url when assets are served by an asset server using HTTPS' do
|
21
|
-
expects(:
|
18
|
+
Rails.configuration.assets.expects(:compile => false)
|
19
|
+
expects(:asset_path => 'https://assets.domain.com/dummy.png')
|
22
20
|
assert_equal 'https://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
23
21
|
end
|
24
22
|
|
25
23
|
test 'wicked_pdf_asset_path should return a url with a protocol when assets are served by an asset server with relative urls' do
|
24
|
+
Rails.configuration.assets.expects(:compile => false)
|
26
25
|
expects(:asset_path => '//assets.domain.com/dummy.png')
|
27
|
-
expects('precompiled_asset?' => true)
|
28
26
|
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
29
27
|
end
|
30
28
|
|
31
29
|
test 'wicked_pdf_asset_path should return a url with a protocol when assets are served by an asset server with no protocol set' do
|
30
|
+
Rails.configuration.assets.expects(:compile => false)
|
32
31
|
expects(:asset_path => 'assets.domain.com/dummy.png')
|
33
|
-
expects('precompiled_asset?' => true)
|
34
32
|
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
35
33
|
end
|
36
34
|
|
37
|
-
test 'wicked_pdf_asset_path should return a path
|
38
|
-
expects(
|
35
|
+
test 'wicked_pdf_asset_path should return a path' do
|
36
|
+
Rails.configuration.assets.expects(:compile => true)
|
39
37
|
path = wicked_pdf_asset_path('application.css')
|
40
38
|
|
41
|
-
assert path.include?('/assets/stylesheets/application.css')
|
39
|
+
assert path.include?('/app/assets/stylesheets/application.css')
|
42
40
|
assert path.include?('file:///')
|
41
|
+
|
42
|
+
Rails.configuration.assets.expects(:compile => false)
|
43
|
+
expects(:asset_path => '/assets/application-6fba03f13d6ff1553477dba03475c4b9b02542e9fb8913bd63c258f4de5b48d9.css')
|
44
|
+
path = wicked_pdf_asset_path('application.css')
|
45
|
+
|
46
|
+
assert path.include?('/public/assets/application-6fba03f13d6ff1553477dba03475c4b9b02542e9fb8913bd63c258f4de5b48d9.css')
|
47
|
+
assert path.include?('file:///')
|
48
|
+
end
|
49
|
+
|
50
|
+
# This assets does not exists so probably it doesn't matter what is
|
51
|
+
# returned, but lets ensure that returned value is the same when assets
|
52
|
+
# are precompiled and when they are not
|
53
|
+
test 'wicked_pdf_asset_path should return a path when asset does not exist' do
|
54
|
+
Rails.configuration.assets.expects(:compile => true)
|
55
|
+
path = wicked_pdf_asset_path('missing.png')
|
56
|
+
|
57
|
+
assert path.include?('/public/missing.png')
|
58
|
+
assert path.include?('file:///')
|
59
|
+
|
60
|
+
Rails.configuration.assets.expects(:compile => false)
|
61
|
+
expects(:asset_path => '/missing.png')
|
62
|
+
path = wicked_pdf_asset_path('missing.png')
|
63
|
+
|
64
|
+
assert path.include?('/public/missing.png')
|
65
|
+
assert path.include?('file:///')
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'wicked_pdf_asset_path should return a url when asset is url' do
|
69
|
+
Rails.configuration.assets.expects(:compile => true)
|
70
|
+
expects(:asset_path => 'http://example.com/rails.png')
|
71
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('http://example.com/rails.png')
|
72
|
+
|
73
|
+
Rails.configuration.assets.expects(:compile => false)
|
74
|
+
expects(:asset_path => 'http://example.com/rails.png')
|
75
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('http://example.com/rails.png')
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'wicked_pdf_asset_path should return a url when asset is url without protocol' do
|
79
|
+
Rails.configuration.assets.expects(:compile => true)
|
80
|
+
expects(:asset_path => '//example.com/rails.png')
|
81
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('//example.com/rails.png')
|
82
|
+
|
83
|
+
Rails.configuration.assets.expects(:compile => false)
|
84
|
+
expects(:asset_path => '//example.com/rails.png')
|
85
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('//example.com/rails.png')
|
43
86
|
end
|
44
87
|
|
45
88
|
test 'WickedPdfHelper::Assets::ASSET_URL_REGEX should match various URL data type formats' do
|
data/test/test_helper.rb
CHANGED
@@ -16,3 +16,9 @@ end
|
|
16
16
|
require 'wicked_pdf'
|
17
17
|
|
18
18
|
Rails.backtrace_cleaner.remove_silencers!
|
19
|
+
|
20
|
+
if (assets_dir = Rails.root.join('app/assets')) && File.directory?(assets_dir)
|
21
|
+
destination = assets_dir.join('stylesheets/wicked.css')
|
22
|
+
source = File.read('test/fixtures/wicked.css')
|
23
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wicked_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Z. Sterrett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -121,7 +121,7 @@ files:
|
|
121
121
|
- ".rubocop.yml"
|
122
122
|
- ".rubocop_todo.yml"
|
123
123
|
- ".travis.yml"
|
124
|
-
-
|
124
|
+
- CHANGELOG.md
|
125
125
|
- Gemfile
|
126
126
|
- LICENSE.txt
|
127
127
|
- README.md
|