pdfkit 0.8.4.3.1 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pdfkit might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/workflows/release-drafter.yml +19 -0
- data/.github/workflows/test.yml +59 -0
- data/.ruby-version +1 -1
- data/.travis.yml +32 -2
- data/CHANGELOG.md +17 -0
- data/Gemfile +1 -1
- data/README.md +5 -0
- data/lib/pdfkit/configuration.rb +3 -1
- data/lib/pdfkit/html_preprocessor.rb +2 -0
- data/lib/pdfkit/middleware.rb +30 -29
- data/lib/pdfkit/os.rb +2 -0
- data/lib/pdfkit/pdfkit.rb +11 -5
- data/lib/pdfkit/source.rb +6 -2
- data/lib/pdfkit/version.rb +3 -1
- data/lib/pdfkit/wkhtmltopdf.rb +4 -2
- data/lib/pdfkit.rb +3 -0
- data/pdfkit.gemspec +4 -2
- data/spec/configuration_spec.rb +2 -0
- data/spec/html_preprocessor_spec.rb +2 -0
- data/spec/middleware_spec.rb +27 -10
- data/spec/os_spec.rb +2 -0
- data/spec/pdfkit_spec.rb +16 -6
- data/spec/source_spec.rb +2 -0
- data/spec/spec_helper.rb +5 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c5255fcf07a7c382fc239a68a805d8a2950df682166a5913ca60c34bac9fe44
|
4
|
+
data.tar.gz: 43555629ecdba193f051ab0ea10f025f7917acf558af58ea30ae69cac6f6b210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb5f31eb9f0f84eb8d9b626c5c804f4f58ab0230b410740cad8810c4b0f673608ebb4874a0aa5f3fffade6c78b551e2a3fa339075fe0aad0f446117eb4af23bb
|
7
|
+
data.tar.gz: a9e6dd403b4ec4795e9af96fd1d2e896d1d1cb497adaca1fd96044504877bf264dfd5cf3a161012430a5930aaf4921271b1ad4ee294ec1e357f3e39366ec6be3
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Release Drafter
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
# branches to consider in the event; optional, defaults to all
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
update_release_draft:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
# Drafts your next Release notes as Pull Requests are merged into "master"
|
14
|
+
- uses: release-drafter/release-drafter@v5
|
15
|
+
# with:
|
16
|
+
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
|
17
|
+
# config-name: my-config.yml
|
18
|
+
env:
|
19
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
name: Test workflow
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
os: [ubuntu-latest]
|
11
|
+
ruby:
|
12
|
+
- '2.5'
|
13
|
+
- '2.6'
|
14
|
+
- '2.7'
|
15
|
+
- '3.0'
|
16
|
+
- '3.1'
|
17
|
+
rails:
|
18
|
+
- '~> 4.1'
|
19
|
+
- '~> 5.2'
|
20
|
+
- '~> 6.0.0'
|
21
|
+
- '~> 6.1'
|
22
|
+
- '~> 7.0.0'
|
23
|
+
exclude:
|
24
|
+
- ruby: '2.5'
|
25
|
+
rails: '~> 7.0.0'
|
26
|
+
- ruby: '2.6'
|
27
|
+
rails: '~> 7.0.0'
|
28
|
+
- ruby: '2.7'
|
29
|
+
rails: '~> 4.1'
|
30
|
+
- ruby: '3.0'
|
31
|
+
rails: '~> 4.1'
|
32
|
+
- ruby: '3.0'
|
33
|
+
rails: '~> 5.2'
|
34
|
+
- ruby: '3.1'
|
35
|
+
rails: '~> 4.1'
|
36
|
+
- ruby: '3.1'
|
37
|
+
rails: '~> 5.2'
|
38
|
+
- ruby: '3.1'
|
39
|
+
rails: '~> 6.0.0'
|
40
|
+
runs-on: ${{ matrix.os }}
|
41
|
+
env:
|
42
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
43
|
+
steps:
|
44
|
+
- uses: actions/checkout@v2
|
45
|
+
- uses: ruby/setup-ruby@v1
|
46
|
+
with:
|
47
|
+
ruby-version: ${{ matrix.ruby }}
|
48
|
+
rubygems: latest
|
49
|
+
bundler: latest
|
50
|
+
bundler-cache: true
|
51
|
+
|
52
|
+
- name: Setup wkhtmltopdf
|
53
|
+
run: |
|
54
|
+
sudo apt-get install -y xfonts-base xfonts-75dpi
|
55
|
+
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
|
56
|
+
sudo dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb
|
57
|
+
|
58
|
+
- name: Run tests
|
59
|
+
run: bundle exec rake
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6.
|
1
|
+
2.6.9
|
data/.travis.yml
CHANGED
@@ -1,10 +1,40 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 2.3
|
5
|
-
- 2.4
|
6
4
|
- 2.5
|
7
5
|
- 2.6
|
6
|
+
- 2.7
|
7
|
+
- 3.0
|
8
|
+
- 3.1
|
9
|
+
|
10
|
+
env:
|
11
|
+
matrix:
|
12
|
+
- RAILS_VERSION="~> 4.1"
|
13
|
+
- RAILS_VERSION="~> 5.2"
|
14
|
+
- RAILS_VERSION="~> 6.0.0"
|
15
|
+
- RAILS_VERSION="~> 6.1"
|
16
|
+
- RAILS_VERSION="~> 7.0.0"
|
17
|
+
|
18
|
+
jobs:
|
19
|
+
exclude:
|
20
|
+
- rvm: 2.5
|
21
|
+
env: RAILS_VERSION="~> 7.0.0"
|
22
|
+
- rvm: 2.6
|
23
|
+
env: RAILS_VERSION="~> 7.0.0"
|
24
|
+
- rvm: 2.7
|
25
|
+
env: RAILS_VERSION="~> 4.1"
|
26
|
+
- rvm: 3.0
|
27
|
+
env: RAILS_VERSION="~> 4.1"
|
28
|
+
- rvm: 3.0
|
29
|
+
env: RAILS_VERSION="~> 5.2"
|
30
|
+
- rvm: 3.1
|
31
|
+
env: RAILS_VERSION="~> 4.1"
|
32
|
+
- rvm: 3.1
|
33
|
+
env: RAILS_VERSION="~> 5.2"
|
34
|
+
- rvm: 3.1
|
35
|
+
env: RAILS_VERSION="~> 6.0.0"
|
36
|
+
|
37
|
+
cache: bundler
|
8
38
|
|
9
39
|
before_install:
|
10
40
|
- gem update --system
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
2022-04-11
|
2
|
+
=================
|
3
|
+
* Bump to 0.8.6
|
4
|
+
* Update ruby and rails versions
|
5
|
+
|
6
|
+
2021-01-23
|
7
|
+
=================
|
8
|
+
* Bump to 0.8.5
|
9
|
+
* Make `PDFKit::VERSION` public (#484)
|
10
|
+
* Fix to render stylesheets as html safe string on Rails 6 (#483)
|
11
|
+
* Adds support for Rails 6
|
12
|
+
|
13
|
+
2020-08-16
|
14
|
+
=================
|
15
|
+
* Bump to 0.8.4.3.2
|
16
|
+
* Reduce scope of middleware exception handling (#476)
|
17
|
+
|
1
18
|
2020-07-05
|
2
19
|
=================
|
3
20
|
* Bump to 0.8.4.3.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
Create PDFs using plain old HTML+CSS. Uses [wkhtmltopdf](http://github.com/antialize/wkhtmltopdf) on the back-end which renders HTML using Webkit.
|
4
4
|
|
5
|
+
## Supported versions
|
6
|
+
|
7
|
+
- Ruby 2.5, 2.6, 2.7, 3.0, 3.1
|
8
|
+
- Rails 4.2, 5.2, 6.0, 6.1, 7.0
|
9
|
+
|
5
10
|
## Install
|
6
11
|
|
7
12
|
### PDFKit
|
data/lib/pdfkit/configuration.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class PDFKit
|
2
4
|
class Configuration
|
3
5
|
attr_accessor :meta_tag_prefix, :root_url
|
@@ -26,7 +28,7 @@ class PDFKit
|
|
26
28
|
|
27
29
|
def default_wkhtmltopdf
|
28
30
|
return @default_command_path if @default_command_path
|
29
|
-
if defined?(Bundler::GemfileError) && File.
|
31
|
+
if defined?(Bundler::GemfileError) && File.exist?('Gemfile')
|
30
32
|
@default_command_path = `bundle exec which wkhtmltopdf`.chomp.lines.last
|
31
33
|
end
|
32
34
|
@default_command_path = `which wkhtmltopdf`.chomp if @default_command_path.nil? || @default_command_path.empty?
|
data/lib/pdfkit/middleware.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class PDFKit
|
2
4
|
class Middleware
|
3
5
|
def initialize(app, options = {}, conditions = {})
|
@@ -19,43 +21,42 @@ class PDFKit
|
|
19
21
|
set_request_to_render_as_pdf(env) if render_as_pdf?
|
20
22
|
status, headers, response = @app.call(env)
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
begin
|
25
|
+
if rendering_pdf? && headers['Content-Type'] =~ /text\/html|application\/xhtml\+xml/
|
26
|
+
body = response.respond_to?(:body) ? response.body : response.join
|
27
|
+
body = body.join if body.is_a?(Array)
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
root_url = root_url(env)
|
30
|
+
protocol = protocol(env)
|
31
|
+
options = @options.merge(root_url: root_url, protocol: protocol)
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
if headers['PDFKit-javascript-delay']
|
34
|
+
options.merge!(javascript_delay: headers.delete('PDFKit-javascript-delay').to_i)
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
37
|
+
body = PDFKit.new(body, options).to_pdf
|
38
|
+
response = [body]
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
if headers['PDFKit-save-pdf']
|
41
|
+
File.open(headers['PDFKit-save-pdf'], 'wb') { |file| file.write(body) } rescue nil
|
42
|
+
headers.delete('PDFKit-save-pdf')
|
43
|
+
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
unless @caching
|
46
|
+
# Do not cache PDFs
|
47
|
+
headers.delete('ETag')
|
48
|
+
headers.delete('Cache-Control')
|
49
|
+
end
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
headers['Content-Length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
|
52
|
+
headers['Content-Type'] = 'application/pdf'
|
53
|
+
headers['Content-Disposition'] ||= @conditions[:disposition] || 'inline'
|
54
|
+
end
|
55
|
+
rescue StandardError => e
|
56
|
+
status = 500
|
57
|
+
response = [e.message]
|
51
58
|
end
|
52
59
|
|
53
|
-
[status, headers, response]
|
54
|
-
|
55
|
-
rescue StandardError => e
|
56
|
-
status = 500
|
57
|
-
response = [e.message]
|
58
|
-
|
59
60
|
[status, headers, response]
|
60
61
|
end
|
61
62
|
|
data/lib/pdfkit/os.rb
CHANGED
data/lib/pdfkit/pdfkit.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'shellwords'
|
2
4
|
require 'tempfile'
|
3
5
|
|
@@ -6,8 +8,8 @@ class PDFKit
|
|
6
8
|
|
7
9
|
class NoExecutableError < Error
|
8
10
|
def initialize
|
9
|
-
msg
|
10
|
-
|
11
|
+
msg = "No wkhtmltopdf executable found at #{PDFKit.configuration.wkhtmltopdf}\n" \
|
12
|
+
">> Please install wkhtmltopdf - https://github.com/pdfkit/PDFKit/wiki/Installing-WKHTMLTOPDF"
|
11
13
|
super(msg)
|
12
14
|
end
|
13
15
|
end
|
@@ -40,7 +42,7 @@ class PDFKit
|
|
40
42
|
@renderer = WkHTMLtoPDF.new options
|
41
43
|
@renderer.normalize_options
|
42
44
|
|
43
|
-
raise NoExecutableError unless File.
|
45
|
+
raise NoExecutableError unless File.exist?(PDFKit.configuration.wkhtmltopdf)
|
44
46
|
end
|
45
47
|
|
46
48
|
def command(path = nil)
|
@@ -114,7 +116,9 @@ class PDFKit
|
|
114
116
|
end
|
115
117
|
|
116
118
|
def style_tag_for(stylesheet)
|
117
|
-
"<style>#{File.read(stylesheet)}</style>"
|
119
|
+
style = "<style>#{File.read(stylesheet)}</style>"
|
120
|
+
style = style.html_safe if style.respond_to?(:html_safe)
|
121
|
+
style
|
118
122
|
end
|
119
123
|
|
120
124
|
def preprocess_html
|
@@ -129,7 +133,9 @@ class PDFKit
|
|
129
133
|
|
130
134
|
stylesheets.each do |stylesheet|
|
131
135
|
if @source.to_s.match(/<\/head>/)
|
132
|
-
@source = Source.new(@source.to_s.gsub(/(<\/head>)/) {|s|
|
136
|
+
@source = Source.new(@source.to_s.gsub(/(<\/head>)/) {|s|
|
137
|
+
style_tag_for(stylesheet) + (s.respond_to?(:html_safe) ? s.html_safe : s)
|
138
|
+
})
|
133
139
|
else
|
134
140
|
@source.to_s.insert(0, style_tag_for(stylesheet))
|
135
141
|
end
|
data/lib/pdfkit/source.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tempfile'
|
2
4
|
require 'uri'
|
3
5
|
|
@@ -7,6 +9,8 @@ class PDFKit
|
|
7
9
|
|
8
10
|
def initialize(url_file_or_html)
|
9
11
|
@source = url_file_or_html
|
12
|
+
# @source is assumed to be modifiable, so make sure it is.
|
13
|
+
@source = @source.dup if @source.is_a?(String) && @source.frozen?
|
10
14
|
end
|
11
15
|
|
12
16
|
def url?
|
@@ -38,11 +42,11 @@ class PDFKit
|
|
38
42
|
private
|
39
43
|
|
40
44
|
def shell_safe_url
|
41
|
-
url_needs_escaping? ? URI::escape(@source) : @source
|
45
|
+
url_needs_escaping? ? URI::DEFAULT_PARSER.escape(@source) : @source
|
42
46
|
end
|
43
47
|
|
44
48
|
def url_needs_escaping?
|
45
|
-
URI::
|
49
|
+
URI::DEFAULT_PARSER.unescape(@source) == @source
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
data/lib/pdfkit/version.rb
CHANGED
data/lib/pdfkit/wkhtmltopdf.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class PDFKit
|
2
4
|
class WkHTMLtoPDF
|
3
5
|
attr_reader :options
|
4
6
|
# Pulled from:
|
5
7
|
# https://github.com/wkhtmltopdf/wkhtmltopdf/blob/ebf9b6cfc4c58a31349fb94c568b254fac37b3d3/README_WKHTMLTOIMAGE#L27
|
6
|
-
REPEATABLE_OPTIONS = %w[--allow --cookie --custom-header --post --post-file --run-script]
|
7
|
-
SPECIAL_OPTIONS = %w[cover toc]
|
8
|
+
REPEATABLE_OPTIONS = %w[--allow --cookie --custom-header --post --post-file --run-script].freeze
|
9
|
+
SPECIAL_OPTIONS = %w[cover toc].freeze
|
8
10
|
|
9
11
|
def initialize(options)
|
10
12
|
@options = options
|
data/lib/pdfkit.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pdfkit/source'
|
2
4
|
require 'pdfkit/pdfkit'
|
3
5
|
require 'pdfkit/middleware'
|
@@ -5,3 +7,4 @@ require 'pdfkit/html_preprocessor'
|
|
5
7
|
require 'pdfkit/os'
|
6
8
|
require 'pdfkit/configuration'
|
7
9
|
require 'pdfkit/wkhtmltopdf'
|
10
|
+
require 'pdfkit/version'
|
data/pdfkit.gemspec
CHANGED
@@ -18,13 +18,15 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
s.required_ruby_version = ">= 2.5"
|
22
|
+
|
21
23
|
s.requirements << "wkhtmltopdf"
|
22
24
|
|
23
25
|
# Development Dependencies
|
24
26
|
s.add_development_dependency(%q<activesupport>, [">= 4.1.11"])
|
25
27
|
s.add_development_dependency(%q<mocha>, [">= 0.9.10"])
|
26
28
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.6"])
|
27
|
-
s.add_development_dependency(%q<rake>, ["
|
28
|
-
s.add_development_dependency(%q<rdoc>, ["
|
29
|
+
s.add_development_dependency(%q<rake>, [">= 12.3.3"])
|
30
|
+
s.add_development_dependency(%q<rdoc>, [">= 4.0.1"])
|
29
31
|
s.add_development_dependency(%q<rspec>, ["~> 3.0"])
|
30
32
|
end
|
data/spec/configuration_spec.rb
CHANGED
data/spec/middleware_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
def app; Rack::Lint.new(@app); end
|
@@ -267,8 +269,8 @@ describe PDFKit::Middleware do
|
|
267
269
|
describe "saving generated pdf to disk" do
|
268
270
|
before do
|
269
271
|
#make sure tests don't find an old test_save.pdf
|
270
|
-
File.delete('spec/test_save.pdf') if File.
|
271
|
-
expect(File.
|
272
|
+
File.delete('spec/test_save.pdf') if File.exist?('spec/test_save.pdf')
|
273
|
+
expect(File.exist?('spec/test_save.pdf')).to eq(false)
|
272
274
|
end
|
273
275
|
|
274
276
|
context "when header PDFKit-save-pdf is present" do
|
@@ -276,7 +278,7 @@ describe PDFKit::Middleware do
|
|
276
278
|
headers = { 'PDFKit-save-pdf' => 'spec/test_save.pdf' }
|
277
279
|
mock_app({}, {only: '/public'}, headers)
|
278
280
|
get 'http://www.example.org/public/test_save.pdf'
|
279
|
-
expect(File.
|
281
|
+
expect(File.exist?('spec/test_save.pdf')).to eq(true)
|
280
282
|
end
|
281
283
|
|
282
284
|
it "does not raise when target directory does not exist" do
|
@@ -292,7 +294,7 @@ describe PDFKit::Middleware do
|
|
292
294
|
it "does not saved the .pdf to disk" do
|
293
295
|
mock_app({}, {only: '/public'}, {} )
|
294
296
|
get 'http://www.example.org/public/test_save.pdf'
|
295
|
-
expect(File.
|
297
|
+
expect(File.exist?('spec/test_save.pdf')).to eq(false)
|
296
298
|
end
|
297
299
|
end
|
298
300
|
end
|
@@ -395,12 +397,27 @@ describe PDFKit::Middleware do
|
|
395
397
|
end
|
396
398
|
|
397
399
|
describe "error handling" do
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
400
|
+
let(:error) { StandardError.new("Something went wrong") }
|
401
|
+
|
402
|
+
context "errors raised by PDF generation" do
|
403
|
+
specify do
|
404
|
+
mock_app
|
405
|
+
allow(PDFKit).to receive(:new).and_raise(error)
|
406
|
+
get 'http://www.example.org/public/test.pdf'
|
407
|
+
expect(last_response.status).to eq(500)
|
408
|
+
expect(last_response.body).to eq(error.message)
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
context "errors raised upstream" do
|
413
|
+
specify do
|
414
|
+
mock_app
|
415
|
+
allow(@app).to receive(:call).and_raise(error)
|
416
|
+
|
417
|
+
expect {
|
418
|
+
get 'http://www.example.org/public/test.pdf'
|
419
|
+
}.to raise_error(error)
|
420
|
+
end
|
404
421
|
end
|
405
422
|
end
|
406
423
|
end
|
data/spec/os_spec.rb
CHANGED
data/spec/pdfkit_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
3
5
|
|
4
6
|
describe PDFKit do
|
@@ -27,7 +29,7 @@ describe PDFKit do
|
|
27
29
|
file_path = File.join(SPEC_ROOT,'fixtures','example.html')
|
28
30
|
pdfkit = PDFKit.new(Tempfile.new(file_path))
|
29
31
|
expect(pdfkit.source).to be_file
|
30
|
-
expect(pdfkit.source.to_s).to match
|
32
|
+
expect(pdfkit.source.to_s).to match(/^#{Dir.tmpdir}/)
|
31
33
|
end
|
32
34
|
|
33
35
|
# Options
|
@@ -239,12 +241,12 @@ describe PDFKit do
|
|
239
241
|
|
240
242
|
it "read the source from stdin if it is html" do
|
241
243
|
pdfkit = PDFKit.new('html')
|
242
|
-
expect(pdfkit.command).to match
|
244
|
+
expect(pdfkit.command).to match(/- -$/)
|
243
245
|
end
|
244
246
|
|
245
247
|
it "specifies the URL to the source if it is a url" do
|
246
248
|
pdfkit = PDFKit.new('http://google.com')
|
247
|
-
expect(pdfkit.command).to match
|
249
|
+
expect(pdfkit.command).to match(/"http:\/\/google.com" -$/)
|
248
250
|
end
|
249
251
|
|
250
252
|
it "does not break Windows paths" do
|
@@ -256,19 +258,19 @@ describe PDFKit do
|
|
256
258
|
it "specifies the path to the source if it is a file" do
|
257
259
|
file_path = File.join(SPEC_ROOT,'fixtures','example.html')
|
258
260
|
pdfkit = PDFKit.new(File.new(file_path))
|
259
|
-
expect(pdfkit.command).to match
|
261
|
+
expect(pdfkit.command).to match(/#{file_path} -$/)
|
260
262
|
end
|
261
263
|
|
262
264
|
it "specifies the path to the source if it is a tempfile" do
|
263
265
|
file_path = File.join(SPEC_ROOT,'fixtures','example.html')
|
264
266
|
pdfkit = PDFKit.new(Tempfile.new(file_path))
|
265
|
-
expect(pdfkit.command).to match
|
267
|
+
expect(pdfkit.command).to match(/#{Dir.tmpdir}\S+ -$/)
|
266
268
|
end
|
267
269
|
|
268
270
|
it "specifies the path for the ouput if a path is given" do
|
269
271
|
file_path = "/path/to/output.pdf"
|
270
272
|
pdfkit = PDFKit.new("html")
|
271
|
-
expect(pdfkit.command(file_path)).to match
|
273
|
+
expect(pdfkit.command(file_path)).to match(/#{file_path}$/)
|
272
274
|
end
|
273
275
|
|
274
276
|
it "detects special pdfkit meta tags" do
|
@@ -501,6 +503,14 @@ describe PDFKit do
|
|
501
503
|
expect(pdfkit.source.to_s).to include("<style>#{File.read(css)}</style></head>")
|
502
504
|
end
|
503
505
|
|
506
|
+
it "can deal with ActiveSupport::SafeBuffer if the HTML doesn't have a head tag" do
|
507
|
+
pdfkit = PDFKit.new(ActiveSupport::SafeBuffer.new "<html><body>Hai!</body></html>")
|
508
|
+
css = File.join(SPEC_ROOT,'fixtures','example.css')
|
509
|
+
pdfkit.stylesheets << css
|
510
|
+
pdfkit.to_pdf
|
511
|
+
expect(pdfkit.source.to_s).to include("<style>#{File.read(css)}</style>")
|
512
|
+
end
|
513
|
+
|
504
514
|
it "escapes \\X in stylesheets" do
|
505
515
|
pdfkit = PDFKit.new("<html><head></head><body>Hai!</body></html>")
|
506
516
|
css = File.join(SPEC_ROOT,'fixtures','example_with_hex_symbol.css')
|
data/spec/source_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
SPEC_ROOT = File.dirname(__FILE__)
|
2
4
|
$LOAD_PATH.unshift(SPEC_ROOT)
|
3
5
|
$LOAD_PATH.unshift(File.join(SPEC_ROOT, '..', 'lib'))
|
@@ -6,13 +8,15 @@ SimpleCov.start do
|
|
6
8
|
add_filter 'spec/'
|
7
9
|
end
|
8
10
|
|
11
|
+
Warning[:deprecated] = true if defined?(Warning.[]=)
|
12
|
+
|
9
13
|
require 'pdfkit'
|
10
14
|
require 'rspec'
|
11
15
|
require 'mocha'
|
12
16
|
require 'rack'
|
13
17
|
require 'rack/test'
|
14
18
|
require 'active_support'
|
15
|
-
require 'custom_wkhtmltopdf_path' if File.
|
19
|
+
require 'custom_wkhtmltopdf_path' if File.exist?(File.join(SPEC_ROOT, 'custom_wkhtmltopdf_path.rb'))
|
16
20
|
|
17
21
|
RSpec.configure do |config|
|
18
22
|
include Rack::Test::Methods
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Pace
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -57,28 +57,28 @@ dependencies:
|
|
57
57
|
name: rake
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 12.3.3
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 12.3.3
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rdoc
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: 4.0.1
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: 4.0.1
|
84
84
|
- !ruby/object:Gem::Dependency
|
@@ -103,7 +103,9 @@ extensions: []
|
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
105
|
- ".document"
|
106
|
+
- ".github/workflows/release-drafter.yml"
|
106
107
|
- ".github/workflows/stale.yml"
|
108
|
+
- ".github/workflows/test.yml"
|
107
109
|
- ".gitignore"
|
108
110
|
- ".rspec"
|
109
111
|
- ".ruby-gemset"
|
@@ -147,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
149
|
requirements:
|
148
150
|
- - ">="
|
149
151
|
- !ruby/object:Gem::Version
|
150
|
-
version: '
|
152
|
+
version: '2.5'
|
151
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
154
|
requirements:
|
153
155
|
- - ">="
|
@@ -155,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
157
|
version: '0'
|
156
158
|
requirements:
|
157
159
|
- wkhtmltopdf
|
158
|
-
rubygems_version: 3.0.3
|
160
|
+
rubygems_version: 3.0.3.1
|
159
161
|
signing_key:
|
160
162
|
specification_version: 4
|
161
163
|
summary: HTML+CSS -> PDF
|