adzap-wicked_pdf 2.0.0.beta3 → 2.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wicked_pdf/asset_helper.rb +2 -3
- data/lib/wicked_pdf/command.rb +1 -0
- data/lib/wicked_pdf/document.rb +12 -10
- data/lib/wicked_pdf/railtie.rb +7 -5
- data/lib/wicked_pdf/tempfile.rb +34 -4
- data/lib/wicked_pdf/version.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/wicked_pdf.gemspec +3 -2
- metadata +28 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00a2f0d862aef8fdabd275049bdeb153fde574191baf868e38331e024f9c9a20
|
4
|
+
data.tar.gz: 9a3a4eab190d8e2eeffb72c3d7ef8dc9e682c08298c3865a500827fbb90f2418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35308c7be05d32e170d2de22e215a5c3c491cf111864c61ba9120e15fd635d7c0f41f6441df54d4605f39b3d8f690a8fbde26f1ee0b2cedc1ab22cc18064deab
|
7
|
+
data.tar.gz: 65925e576958b7bc555168c0c90f8d6040d0f4435dd6c8e55eff629b5d034ab30bb9d54a0d6fbf0095a5b2c9f7a0a0e47d94baf36980c6f83372471a80df36a3
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'net/http'
|
2
2
|
|
3
3
|
module WickedPdf
|
4
4
|
module AssetHelper
|
@@ -124,8 +124,7 @@ module WickedPdf
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def read_from_uri(uri)
|
127
|
-
|
128
|
-
asset = open(uri, "r#{encoding}", &:read)
|
127
|
+
asset = Net::HTTP.get(URI(uri))
|
129
128
|
asset = gzip(asset) if WickedPdf.config[:expect_gzipped_remote_assets]
|
130
129
|
asset
|
131
130
|
end
|
data/lib/wicked_pdf/command.rb
CHANGED
data/lib/wicked_pdf/document.rb
CHANGED
@@ -12,11 +12,12 @@ module WickedPdf
|
|
12
12
|
options = options.dup
|
13
13
|
options.merge!(WickedPdf.config) { |_key, option, _config| option }
|
14
14
|
string_file = WickedPdf::Tempfile.new('wicked_pdf.html', options[:temp_path])
|
15
|
-
string_file.
|
16
|
-
string_file.write(string)
|
17
|
-
string_file.close
|
15
|
+
string_file.write_in_chunks(string)
|
18
16
|
|
19
17
|
pdf_from_html_file(string_file.path, options)
|
18
|
+
rescue Errno::EINVAL => e
|
19
|
+
Rails.logger.error '[wicked_pdf] The HTML file is too large! Try reducing the size or using the return_file option instead.'
|
20
|
+
raise e
|
20
21
|
ensure
|
21
22
|
string_file.close! if string_file
|
22
23
|
end
|
@@ -25,21 +26,22 @@ module WickedPdf
|
|
25
26
|
# merge in global config options
|
26
27
|
options.merge!(WickedPdf.config) { |_key, option, _config| option }
|
27
28
|
generated_pdf_file = WickedPdf::Tempfile.new('wicked_pdf_generated_file.pdf', options[:temp_path])
|
29
|
+
return_file = options.delete(:return_file)
|
28
30
|
|
29
|
-
|
31
|
+
err = @command.execute(options, url, generated_pdf_file.path.to_s)
|
30
32
|
|
31
|
-
if
|
32
|
-
return_file = options.delete(:return_file)
|
33
|
+
if return_file
|
33
34
|
return generated_pdf_file
|
34
35
|
end
|
35
36
|
|
36
|
-
generated_pdf_file.
|
37
|
-
generated_pdf_file.binmode
|
38
|
-
pdf = generated_pdf_file.read
|
37
|
+
pdf = generated_pdf_file.read_in_chunks
|
39
38
|
|
40
|
-
raise "PDF could not be generated!\n Command Error: #{
|
39
|
+
raise "PDF could not be generated!\n Command Error: #{err}" if pdf && pdf.rstrip.empty?
|
41
40
|
|
42
41
|
pdf
|
42
|
+
rescue Errno::EINVAL => e
|
43
|
+
Rails.logger.error '[wicked_pdf] The PDF file is too large! Try reducing the size or using the return_file option instead.'
|
44
|
+
raise e
|
43
45
|
ensure
|
44
46
|
generated_pdf_file.close! if generated_pdf_file && !return_file
|
45
47
|
end
|
data/lib/wicked_pdf/railtie.rb
CHANGED
@@ -5,11 +5,13 @@ require 'wicked_pdf/asset_helper'
|
|
5
5
|
module WickedPdf
|
6
6
|
class Railtie < Rails::Railtie
|
7
7
|
initializer 'wicked_pdf.register' do |_app|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
ActiveSupport.on_load(:action_controller) {
|
9
|
+
ActionController::Base.send :prepend, PdfHelper
|
10
|
+
ActionController::Renderers.add :pdf do |template, options|
|
11
|
+
WickedPdf::Renderer.new(self).render(options.merge(pdf: template))
|
12
|
+
end
|
13
|
+
}
|
14
|
+
ActiveSupport.on_load(:action_view) { include WickedPdf::AssetHelper }
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
data/lib/wicked_pdf/tempfile.rb
CHANGED
@@ -1,13 +1,43 @@
|
|
1
1
|
require 'tempfile'
|
2
|
+
require 'stringio'
|
2
3
|
|
3
|
-
|
4
|
-
class Tempfile < Tempfile
|
5
|
-
# ensures the Tempfile's filename always keeps its extension
|
4
|
+
class WickedPdf
|
5
|
+
class Tempfile < ::Tempfile
|
6
6
|
def initialize(filename, temp_dir = nil)
|
7
7
|
temp_dir ||= Dir.tmpdir
|
8
8
|
extension = File.extname(filename)
|
9
|
-
basename
|
9
|
+
basename = File.basename(filename, extension)
|
10
10
|
super([basename, extension], temp_dir)
|
11
11
|
end
|
12
|
+
|
13
|
+
def write_in_chunks(input_string)
|
14
|
+
binmode
|
15
|
+
string_io = StringIO.new(input_string)
|
16
|
+
write(string_io.read(chunk_size)) until string_io.eof?
|
17
|
+
close
|
18
|
+
self
|
19
|
+
rescue Errno::EINVAL => e
|
20
|
+
raise e, file_too_large_message
|
21
|
+
end
|
22
|
+
|
23
|
+
def read_in_chunks
|
24
|
+
rewind
|
25
|
+
binmode
|
26
|
+
output_string = ''
|
27
|
+
output_string << read(chunk_size) until eof?
|
28
|
+
output_string
|
29
|
+
rescue Errno::EINVAL => e
|
30
|
+
raise e, file_too_large_message
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def chunk_size
|
36
|
+
1024 * 1024
|
37
|
+
end
|
38
|
+
|
39
|
+
def file_too_large_message
|
40
|
+
'The HTML file is too large! Try reducing the size or using the return_file option instead.'
|
41
|
+
end
|
12
42
|
end
|
13
43
|
end
|
data/lib/wicked_pdf/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -5,7 +5,7 @@ require 'combustion'
|
|
5
5
|
|
6
6
|
Combustion.path = 'test/dummy'
|
7
7
|
Combustion.initialize!(:all) do
|
8
|
-
if config.active_record.sqlite3.respond_to?(:represent_boolean_as_integer) # Rails 5.2
|
8
|
+
if Rails::VERSION::MAJOR < 6.0 && config.active_record.sqlite3.respond_to?(:represent_boolean_as_integer) # Rails 5.2
|
9
9
|
config.active_record.sqlite3.represent_boolean_as_integer = true
|
10
10
|
end
|
11
11
|
end
|
data/wicked_pdf.gemspec
CHANGED
@@ -28,11 +28,12 @@ DESC
|
|
28
28
|
|
29
29
|
spec.add_dependency 'activesupport'
|
30
30
|
|
31
|
-
spec.add_development_dependency 'rails'
|
31
|
+
spec.add_development_dependency 'rails', '< 6.0'
|
32
32
|
spec.add_development_dependency 'combustion'
|
33
33
|
spec.add_development_dependency 'bundler', '>= 1.3.0', '< 3'
|
34
34
|
spec.add_development_dependency 'rake'
|
35
35
|
spec.add_development_dependency 'rubocop', '~> 0.50.0'
|
36
|
-
spec.add_development_dependency 'sqlite3', '
|
36
|
+
spec.add_development_dependency 'sqlite3', '<= 1.4'
|
37
37
|
spec.add_development_dependency 'mocha', '= 1.3'
|
38
|
+
spec.add_development_dependency 'sprockets', '~> 3.0'
|
38
39
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adzap-wicked_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Z. Sterrett
|
8
8
|
- David Jones
|
9
9
|
- Adam Meehan
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-10-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -30,16 +30,16 @@ dependencies:
|
|
30
30
|
name: rails
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - "
|
33
|
+
- - "<"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
35
|
+
version: '6.0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - "
|
40
|
+
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0'
|
42
|
+
version: '6.0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: combustion
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,16 +106,16 @@ dependencies:
|
|
106
106
|
name: sqlite3
|
107
107
|
requirement: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - "<="
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: 1.
|
111
|
+
version: '1.4'
|
112
112
|
type: :development
|
113
113
|
prerelease: false
|
114
114
|
version_requirements: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - "
|
116
|
+
- - "<="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: 1.
|
118
|
+
version: '1.4'
|
119
119
|
- !ruby/object:Gem::Dependency
|
120
120
|
name: mocha
|
121
121
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +130,20 @@ dependencies:
|
|
130
130
|
- - '='
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '1.3'
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: sprockets
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.0'
|
140
|
+
type: :development
|
141
|
+
prerelease: false
|
142
|
+
version_requirements: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '3.0'
|
133
147
|
description: |
|
134
148
|
Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML.
|
135
149
|
In other words, rather than dealing with a PDF generation DSL of some sort,
|
@@ -201,7 +215,7 @@ homepage: https://github.com/adzap/wicked_pdf
|
|
201
215
|
licenses:
|
202
216
|
- MIT
|
203
217
|
metadata: {}
|
204
|
-
post_install_message:
|
218
|
+
post_install_message:
|
205
219
|
rdoc_options: []
|
206
220
|
require_paths:
|
207
221
|
- lib
|
@@ -217,9 +231,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
231
|
version: 1.3.1
|
218
232
|
requirements:
|
219
233
|
- wkhtmltopdf
|
220
|
-
|
221
|
-
|
222
|
-
signing_key:
|
234
|
+
rubygems_version: 3.4.19
|
235
|
+
signing_key:
|
223
236
|
specification_version: 4
|
224
237
|
summary: PDF generator (from HTML) gem for Ruby on Rails
|
225
238
|
test_files:
|