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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a9bd19353fd98c1329694e7e28958e05dd01d97
4
- data.tar.gz: 33413fa1202def89fa910d38996ea732ac86b706
3
+ metadata.gz: 6bb2f6a218b4808fb3f117148379101db09cffb8
4
+ data.tar.gz: 3d87582716a2d79e4f7b635f4297e50744d47e0a
5
5
  SHA512:
6
- metadata.gz: a7c925ec176e0976cede93924098016466bd8627a99af611b89c283792ccbd9a154a450a2d9370079d9f6f72d1d48c8c57e0ef5ab3d25f235b242222aa4deabe
7
- data.tar.gz: 44b674f5bc1efd1bdb54354f0cc05d13442af7427c53c903821951491f17923466d9d8223303e0519d6b37ba8e2fce8ba534b1d88fcda33c139f61db9d7e1b61
6
+ metadata.gz: 0579b69ec2897374a6bac52f44306e6c15da9252f09f3f0d6bbbc89a3161f5c4cf47218593a70d9884b9a043f0ca8c5d8c8fdebf38edb9457510cf6706cf2d2a
7
+ data.tar.gz: be80b3dd951f1a12065237cc5db3ab019b5e048c337e8c3666cc21d7a3685bcee3b5415d566a19ca73631adf7c5757c14115769460b96b13b9497ce18ec85e46
@@ -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
 
@@ -38,7 +38,7 @@ module PdfHelper
38
38
  private
39
39
 
40
40
  def log_pdf_creation
41
- logger.info '*' * 15 + 'WICKED' + '*' * 15 unless logger.nil?
41
+ logger.info '*' * 15 + 'WICKED' + '*' * 15 if logger && logger.respond_to?(:info)
42
42
  end
43
43
 
44
44
  def set_basic_auth(options = {})
@@ -1,3 +1,3 @@
1
1
  class WickedPdf
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -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
- asset = Regexp.last_match[1]
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 precompiled_asset?(source)
61
- if (pathname = set_protocol(asset_path(source))) =~ URI_REGEXP
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, asset_path(source).sub(/\A#{Rails.application.config.action_controller.relative_url_root}/, ''))
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).pathname
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 precompiled_asset?(source)
85
- Rails.configuration.assets.compile == false || source.to_s[0] == '/'
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 precompiled_asset?(source)
90
- if set_protocol(asset_path(source)) =~ URI_REGEXP
91
- read_from_uri(source)
92
- elsif asset_exists?(source)
93
- IO.read(asset_pathname(source))
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(source)
103
+ def read_from_uri(uri)
101
104
  encoding = ':UTF-8' if RUBY_VERSION > '1.8'
102
- asset = open(asset_pathname(source), "r#{encoding}") { |f| f.read }
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(:asset_path => 'https://assets.domain.com/dummy.png', 'precompiled_asset?' => true)
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 when assets are precompiled' do
38
- expects('precompiled_asset?' => false)
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
@@ -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.3
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: 2015-12-02 00:00:00.000000000 Z
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
- - CHANGLOG.md
124
+ - CHANGELOG.md
125
125
  - Gemfile
126
126
  - LICENSE.txt
127
127
  - README.md