my_pdfkit 0.1.0.0
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 +7 -0
- data/.document +5 -0
- data/.github/workflows/release-drafter.yml +19 -0
- data/.github/workflows/stale.yml +19 -0
- data/.github/workflows/test.yml +71 -0
- data/.gitignore +25 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +46 -0
- data/CHANGELOG.md +154 -0
- data/Gemfile +12 -0
- data/LICENSE +20 -0
- data/POST_INSTALL +14 -0
- data/README.md +190 -0
- data/Rakefile +24 -0
- data/lib/my_pdfkit/configuration.rb +89 -0
- data/lib/my_pdfkit/html_preprocessor.rb +25 -0
- data/lib/my_pdfkit/middleware.rb +117 -0
- data/lib/my_pdfkit/os.rb +21 -0
- data/lib/my_pdfkit/pdfkit.rb +153 -0
- data/lib/my_pdfkit/source.rb +52 -0
- data/lib/my_pdfkit/version.rb +5 -0
- data/lib/my_pdfkit/wkhtmltopdf.rb +82 -0
- data/lib/my_pdfkit.rb +10 -0
- data/my_pdfkit.gemspec +33 -0
- data/spec/configuration_spec.rb +171 -0
- data/spec/fixtures/example.css +1 -0
- data/spec/fixtures/example.html +5 -0
- data/spec/fixtures/example_with_hex_symbol.css +3 -0
- data/spec/html_preprocessor_spec.rb +71 -0
- data/spec/middleware_spec.rb +531 -0
- data/spec/os_spec.rb +67 -0
- data/spec/pdfkit_spec.rb +608 -0
- data/spec/source_spec.rb +125 -0
- data/spec/spec_helper.rb +33 -0
- metadata +175 -0
data/spec/source_spec.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe MyPDFKit::Source do
|
6
|
+
describe "#url?" do
|
7
|
+
it "returns true if passed a url like string" do
|
8
|
+
source = MyPDFKit::Source.new('http://google.com')
|
9
|
+
expect(source).to be_url
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns false if passed a file" do
|
13
|
+
source = MyPDFKit::Source.new(File.new(__FILE__))
|
14
|
+
expect(source).not_to be_url
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns false if passed a tempfile" do
|
18
|
+
source = MyPDFKit::Source.new(::Tempfile.new(__FILE__))
|
19
|
+
expect(source).not_to be_url
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false if passed HTML" do
|
23
|
+
source = MyPDFKit::Source.new('<blink>Oh Hai!</blink>')
|
24
|
+
expect(source).not_to be_url
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns false if passed HTML with embedded urls at the beginning of a line" do
|
28
|
+
source = MyPDFKit::Source.new("<blink>Oh Hai!</blink>\nhttp://www.google.com")
|
29
|
+
expect(source).not_to be_url
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#file?" do
|
34
|
+
it "returns true if passed a file" do
|
35
|
+
source = MyPDFKit::Source.new(::File.new(__FILE__))
|
36
|
+
expect(source).to be_file
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns true if passed a tempfile" do
|
40
|
+
source = MyPDFKit::Source.new(::Tempfile.new(__FILE__))
|
41
|
+
expect(source).to be_file
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns false if passed a url like string" do
|
45
|
+
source = MyPDFKit::Source.new('http://google.com')
|
46
|
+
expect(source).not_to be_file
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns false if passed HTML" do
|
50
|
+
source = MyPDFKit::Source.new('<blink>Oh Hai!</blink>')
|
51
|
+
expect(source).not_to be_file
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#html?" do
|
56
|
+
it "returns true if passed HTML" do
|
57
|
+
source = MyPDFKit::Source.new('<blink>Oh Hai!</blink>')
|
58
|
+
expect(source).to be_html
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns false if passed a file" do
|
62
|
+
source = MyPDFKit::Source.new(::File.new(__FILE__))
|
63
|
+
expect(source).not_to be_html
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns false if passed a tempfile" do
|
67
|
+
source = MyPDFKit::Source.new(::Tempfile.new(__FILE__))
|
68
|
+
expect(source).not_to be_html
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns false if passed a url like string" do
|
72
|
+
source = MyPDFKit::Source.new('http://google.com')
|
73
|
+
expect(source).not_to be_html
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#to_input_for_command" do
|
78
|
+
it "URI escapes source URI" do
|
79
|
+
source = MyPDFKit::Source.new("https://www.google.com/search?q=foo bar")
|
80
|
+
expect(source.to_input_for_command).to eq "https://www.google.com/search?q=foo%20bar"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "does not URI escape previously escaped source URLs" do
|
84
|
+
source = MyPDFKit::Source.new("https://www.google.com/search?q=foo%20bar")
|
85
|
+
expect(source.to_input_for_command).to eq "https://www.google.com/search?q=foo%20bar"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns a '-' for HTML strings to indicate that we send that content through STDIN" do
|
89
|
+
source = MyPDFKit::Source.new('<blink>Oh Hai!</blink>')
|
90
|
+
expect(source.to_input_for_command).to eq '-'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns the file path for file sources" do
|
94
|
+
source = MyPDFKit::Source.new(::File.new(__FILE__))
|
95
|
+
expect(source.to_input_for_command).to match 'spec/source_spec.rb'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns the file path for tempfile sources" do
|
99
|
+
source = MyPDFKit::Source.new(file = ::Tempfile.new(__FILE__))
|
100
|
+
expect(source.to_input_for_command).to match file.path
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#to_s" do
|
105
|
+
it "returns the HTML if passed HTML" do
|
106
|
+
source = MyPDFKit::Source.new('<blink>Oh Hai!</blink>')
|
107
|
+
expect(source.to_s).to eq('<blink>Oh Hai!</blink>')
|
108
|
+
end
|
109
|
+
|
110
|
+
it "returns a path if passed a file" do
|
111
|
+
source = MyPDFKit::Source.new(::File.new(__FILE__))
|
112
|
+
expect(source.to_s).to eq(__FILE__)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "returns a path if passed a tempfile" do
|
116
|
+
source = MyPDFKit::Source.new(file = ::Tempfile.new(__FILE__))
|
117
|
+
expect(source.to_s).to eq(file.path)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "returns the url if passed a url like string" do
|
121
|
+
source = MyPDFKit::Source.new('http://google.com')
|
122
|
+
expect(source.to_s).to eq('http://google.com')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SPEC_ROOT = File.dirname(__FILE__)
|
4
|
+
$LOAD_PATH.unshift(SPEC_ROOT)
|
5
|
+
$LOAD_PATH.unshift(File.join(SPEC_ROOT, '..', 'lib'))
|
6
|
+
require 'simplecov'
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter 'spec/'
|
9
|
+
end
|
10
|
+
|
11
|
+
Warning[:deprecated] = true if defined?(Warning.[]=)
|
12
|
+
|
13
|
+
require 'pdfkit'
|
14
|
+
require 'rspec'
|
15
|
+
require 'mocha'
|
16
|
+
require 'rack'
|
17
|
+
require 'rack/test'
|
18
|
+
require 'active_support'
|
19
|
+
require 'custom_wkhtmltopdf_path' if File.exist?(File.join(SPEC_ROOT, 'custom_wkhtmltopdf_path.rb'))
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
include Rack::Test::Methods
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec::Matchers.define :contain do |expected|
|
26
|
+
match do |actual|
|
27
|
+
(0..(actual.length - expected.length)).any? do |base_index|
|
28
|
+
expected.each_with_index.all? do |expected_element,index|
|
29
|
+
actual[base_index+index] == expected_element
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: my_pdfkit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared Pace
|
8
|
+
- Relevance
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2024-09-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 4.1.11
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 4.1.11
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: mocha
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.9.10
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.9.10
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rack-test
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.5.6
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.5.6
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 12.3.3
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 12.3.3
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rdoc
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 4.0.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 4.0.1
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '3.0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '3.0'
|
98
|
+
description: Uses wkhtmltopdf to create PDFs using HTML
|
99
|
+
email:
|
100
|
+
- jared@codewordstudios.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".document"
|
106
|
+
- ".github/workflows/release-drafter.yml"
|
107
|
+
- ".github/workflows/stale.yml"
|
108
|
+
- ".github/workflows/test.yml"
|
109
|
+
- ".gitignore"
|
110
|
+
- ".rspec"
|
111
|
+
- ".ruby-gemset"
|
112
|
+
- ".ruby-version"
|
113
|
+
- ".travis.yml"
|
114
|
+
- CHANGELOG.md
|
115
|
+
- Gemfile
|
116
|
+
- LICENSE
|
117
|
+
- POST_INSTALL
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- lib/my_pdfkit.rb
|
121
|
+
- lib/my_pdfkit/configuration.rb
|
122
|
+
- lib/my_pdfkit/html_preprocessor.rb
|
123
|
+
- lib/my_pdfkit/middleware.rb
|
124
|
+
- lib/my_pdfkit/os.rb
|
125
|
+
- lib/my_pdfkit/pdfkit.rb
|
126
|
+
- lib/my_pdfkit/source.rb
|
127
|
+
- lib/my_pdfkit/version.rb
|
128
|
+
- lib/my_pdfkit/wkhtmltopdf.rb
|
129
|
+
- my_pdfkit.gemspec
|
130
|
+
- spec/configuration_spec.rb
|
131
|
+
- spec/fixtures/example.css
|
132
|
+
- spec/fixtures/example.html
|
133
|
+
- spec/fixtures/example_with_hex_symbol.css
|
134
|
+
- spec/html_preprocessor_spec.rb
|
135
|
+
- spec/middleware_spec.rb
|
136
|
+
- spec/os_spec.rb
|
137
|
+
- spec/pdfkit_spec.rb
|
138
|
+
- spec/source_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
homepage: https://github.com/pdfkit/pdfkit
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '2.5'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements:
|
159
|
+
- wkhtmltopdf
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.6.14
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: HTML+CSS -> PDF
|
165
|
+
test_files:
|
166
|
+
- spec/configuration_spec.rb
|
167
|
+
- spec/fixtures/example.css
|
168
|
+
- spec/fixtures/example.html
|
169
|
+
- spec/fixtures/example_with_hex_symbol.css
|
170
|
+
- spec/html_preprocessor_spec.rb
|
171
|
+
- spec/middleware_spec.rb
|
172
|
+
- spec/os_spec.rb
|
173
|
+
- spec/pdfkit_spec.rb
|
174
|
+
- spec/source_spec.rb
|
175
|
+
- spec/spec_helper.rb
|