grover 0.12.2 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/lib/grover.rb +2 -2
- data/lib/grover/configuration.rb +2 -1
- data/lib/grover/js/processor.js +1 -1
- data/lib/grover/middleware.rb +23 -5
- data/lib/grover/options_builder.rb +1 -1
- data/lib/grover/processor.rb +3 -1
- data/lib/grover/version.rb +1 -1
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b599a5462dc8008f92d9ea95c949d8de0cfd0786792b303c1e78f22a104a503d
|
4
|
+
data.tar.gz: bb4dbd2d6d336e88f71668853b2d9819e314a87b3b55c7c4f211f3d94ddcfe25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc644ef00aa06d6ebb2e146165fe300f94c73749cffaa6e4e409d78e6ed5d376421a4163137557f551ea90ef984a52bda42f5db01bad1f81d03c5fb209ed5863
|
7
|
+
data.tar.gz: 872dd3bde76e74f201d0dc52f46614434bdb52ea7ef43deb205783241c54a4c0f107f69812a9fa70f3af1e25a46edb3ac6e13e7d17bc51ba6f3b2223c0f69f92
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018-2020 Studiosity
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/lib/grover.rb
CHANGED
@@ -33,8 +33,8 @@ class Grover
|
|
33
33
|
# see https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions
|
34
34
|
#
|
35
35
|
def initialize(url, options = {})
|
36
|
-
@url = url
|
37
|
-
@options = OptionsBuilder.new(options, url)
|
36
|
+
@url = url.to_s
|
37
|
+
@options = OptionsBuilder.new(options, @url)
|
38
38
|
@root_path = @options.delete 'root_path'
|
39
39
|
@front_cover_path = @options.delete 'front_cover_path'
|
40
40
|
@back_cover_path = @options.delete 'back_cover_path'
|
data/lib/grover/configuration.rb
CHANGED
@@ -5,13 +5,14 @@ class Grover
|
|
5
5
|
# Configuration of the options for Grover HTML to PDF conversion
|
6
6
|
#
|
7
7
|
class Configuration
|
8
|
-
attr_accessor :options, :meta_tag_prefix, :ignore_path,
|
8
|
+
attr_accessor :options, :meta_tag_prefix, :ignore_path, :root_url,
|
9
9
|
:use_pdf_middleware, :use_png_middleware, :use_jpeg_middleware
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@options = {}
|
13
13
|
@meta_tag_prefix = 'grover-'
|
14
14
|
@ignore_path = nil
|
15
|
+
@root_url = nil
|
15
16
|
@use_pdf_middleware = true
|
16
17
|
@use_png_middleware = false
|
17
18
|
@use_jpeg_middleware = false
|
data/lib/grover/js/processor.js
CHANGED
@@ -82,7 +82,7 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
82
82
|
requestOptions.waitUntil = waitUntil || 'networkidle0';
|
83
83
|
await page.setRequestInterception(true);
|
84
84
|
page.once('request', request => {
|
85
|
-
request.respond({ body: urlOrHtml });
|
85
|
+
request.respond({ body: urlOrHtml === '' ? ' ' : urlOrHtml });
|
86
86
|
// Reset the request interception
|
87
87
|
// (we only want to intercept the first request - ie our HTML)
|
88
88
|
page.on('request', request => request.continue());
|
data/lib/grover/middleware.rb
CHANGED
@@ -9,12 +9,15 @@ class Grover
|
|
9
9
|
# Much of this code was sourced from the PDFKit project
|
10
10
|
# @see https://github.com/pdfkit/pdfkit
|
11
11
|
#
|
12
|
-
class Middleware
|
13
|
-
def initialize(app)
|
12
|
+
class Middleware # rubocop:disable Metrics/ClassLength
|
13
|
+
def initialize(app, *args)
|
14
14
|
@app = app
|
15
15
|
@pdf_request = false
|
16
16
|
@png_request = false
|
17
17
|
@jpeg_request = false
|
18
|
+
|
19
|
+
@root_url =
|
20
|
+
args.last.is_a?(Hash) && args.last.key?(:root_url) ? args.last[:root_url] : Grover.configuration.root_url
|
18
21
|
end
|
19
22
|
|
20
23
|
def call(env)
|
@@ -30,6 +33,8 @@ class Grover
|
|
30
33
|
response = update_response response, headers if grover_request? && html_content?(headers)
|
31
34
|
|
32
35
|
[status, headers, response]
|
36
|
+
ensure
|
37
|
+
restore_env_from_grover_request(env) if grover_request?
|
33
38
|
end
|
34
39
|
|
35
40
|
private
|
@@ -94,14 +99,14 @@ class Grover
|
|
94
99
|
end
|
95
100
|
end
|
96
101
|
|
97
|
-
def create_grover_for_response(response)
|
102
|
+
def create_grover_for_response(response) # rubocop:disable Metrics/AbcSize
|
98
103
|
body = response.respond_to?(:body) ? response.body : response.join
|
99
104
|
body = body.join if body.is_a?(Array)
|
100
105
|
body = HTMLPreprocessor.process body, root_url, protocol
|
101
106
|
|
102
107
|
options = { display_url: request_url }
|
103
108
|
cookies = Rack::Utils.parse_cookies(env).map do |name, value|
|
104
|
-
{ name: name, value: value, domain: env['HTTP_HOST'] }
|
109
|
+
{ name: name, value: Rack::Utils.escape(value), domain: env['HTTP_HOST'] }
|
105
110
|
end
|
106
111
|
options[:cookies] = cookies if cookies.any?
|
107
112
|
|
@@ -135,11 +140,24 @@ class Grover
|
|
135
140
|
end
|
136
141
|
|
137
142
|
def configure_env_for_grover_request(env)
|
138
|
-
env
|
143
|
+
# Save the env params we're overriding so we can restore them after the response is fetched
|
144
|
+
@pre_request_env_params = env.slice('PATH_INFO', 'REQUEST_URI', 'HTTP_ACCEPT')
|
145
|
+
|
146
|
+
# Override path/URI so any downstream middleware/app doesn't try actioning the request as PDF
|
147
|
+
env['PATH_INFO'] = path_without_extension
|
148
|
+
env['REQUEST_URI'] = @request.url
|
139
149
|
env['HTTP_ACCEPT'] = concat(env['HTTP_ACCEPT'], Rack::Mime.mime_type('.html'))
|
140
150
|
env['Rack-Middleware-Grover'] = 'true'
|
141
151
|
end
|
142
152
|
|
153
|
+
def restore_env_from_grover_request(env)
|
154
|
+
return unless @pre_request_env_params.is_a? Hash
|
155
|
+
|
156
|
+
# Restore the path/URI so any upstream middleware doesn't get confused
|
157
|
+
env.merge! @pre_request_env_params
|
158
|
+
env['REQUEST_URI'] = @request.url unless @pre_request_env_params.key? 'REQUEST_URI'
|
159
|
+
end
|
160
|
+
|
143
161
|
def concat(accepts, type)
|
144
162
|
(accepts || '').split(',').unshift(type).compact.join(',')
|
145
163
|
end
|
@@ -8,7 +8,7 @@ class Grover
|
|
8
8
|
# Build options from Grover.configuration, meta_options, and passed-in options
|
9
9
|
#
|
10
10
|
class OptionsBuilder < Hash
|
11
|
-
def initialize(options, url)
|
11
|
+
def initialize(options, url) # rubocop:disable Lint/MissingSuper
|
12
12
|
@url = url
|
13
13
|
combined = grover_configuration
|
14
14
|
Utils.deep_merge! combined, Utils.deep_stringify_keys(options)
|
data/lib/grover/processor.rb
CHANGED
@@ -76,7 +76,7 @@ class Grover
|
|
76
76
|
@package_json ||= JSON.parse(File.read(package_json_path))
|
77
77
|
end
|
78
78
|
|
79
|
-
def call_js_method(method, url_or_html, options) # rubocop:disable Metrics/MethodLength
|
79
|
+
def call_js_method(method, url_or_html, options) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
80
80
|
stdin.puts JSON.dump([method, url_or_html, options])
|
81
81
|
input = stdout.gets
|
82
82
|
raise Errno::EPIPE, "Can't read from worker" if input.nil?
|
@@ -90,6 +90,8 @@ class Grover
|
|
90
90
|
else
|
91
91
|
raise Grover::JavaScript.const_get(error_class, false), message
|
92
92
|
end
|
93
|
+
rescue JSON::ParserError
|
94
|
+
raise Grover::Error, 'Malformed worker response'
|
93
95
|
rescue Errno::EPIPE, IOError
|
94
96
|
raise Grover::Error, "Worker process failed:\n#{stderr.read}"
|
95
97
|
end
|
data/lib/grover/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Bromwich
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: combine_pdf
|
@@ -163,6 +163,7 @@ executables: []
|
|
163
163
|
extensions: []
|
164
164
|
extra_rdoc_files: []
|
165
165
|
files:
|
166
|
+
- LICENSE
|
166
167
|
- lib/active_support_ext/object/deep_dup.rb
|
167
168
|
- lib/active_support_ext/object/duplicable.rb
|
168
169
|
- lib/grover.rb
|
@@ -180,7 +181,7 @@ homepage: https://github.com/Studiosity/grover
|
|
180
181
|
licenses:
|
181
182
|
- MIT
|
182
183
|
metadata: {}
|
183
|
-
post_install_message:
|
184
|
+
post_install_message:
|
184
185
|
rdoc_options: []
|
185
186
|
require_paths:
|
186
187
|
- lib
|
@@ -188,15 +189,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
189
|
requirements:
|
189
190
|
- - ">="
|
190
191
|
- !ruby/object:Gem::Version
|
191
|
-
version:
|
192
|
+
version: 2.5.0
|
193
|
+
- - "<"
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: 3.1.0
|
192
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
197
|
requirements:
|
194
198
|
- - ">="
|
195
199
|
- !ruby/object:Gem::Version
|
196
200
|
version: '0'
|
197
201
|
requirements: []
|
198
|
-
rubygems_version: 3.
|
199
|
-
signing_key:
|
202
|
+
rubygems_version: 3.2.3
|
203
|
+
signing_key:
|
200
204
|
specification_version: 4
|
201
205
|
summary: A Ruby gem to transform HTML into PDF, PNG or JPEG by wrapping the NodeJS
|
202
206
|
Google Puppeteer driver for Chromium
|