grover 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +7 -0
- data/lib/grover.rb +5 -0
- data/lib/grover/grover.rb +42 -0
- data/lib/grover/processor.rb +31 -0
- data/lib/grover/utils.rb +13 -0
- data/lib/grover/version.rb +1 -1
- metadata +22 -10
- data/.gitignore +0 -2
- data/.rubocop.yml +0 -2
- data/.travis.yml +0 -29
- data/Gemfile +0 -4
- data/LICENSE +0 -21
- data/README.md +0 -8
- data/Rakefile +0 -8
- data/grover.gemspec +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ffddd7bbedda30ce0a9012ddb9bf2ad8cca7b31
|
4
|
+
data.tar.gz: '052654614238c49a142f05a4e723b3551a0f728e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa584f02ecff16ce4fc95f03a99fce1911c919e6b1957b49fe79430504ae6564962d1108d39114f4f4f1cf6df3ae99920a8da9d7d2f0bcbc445edd0cdb09ca5c
|
7
|
+
data.tar.gz: 0d47f71cd8b25638cfd3cc64831a3efaedbe6caa7ab69fafc25965aa1de3a086fe4cb98466ef873478f23ef58eab762dc28025b1bb911ee024947f25fce51f9a
|
data/bin/console
ADDED
data/lib/grover.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Grover interface for converting HTML to PDF
|
3
|
+
#
|
4
|
+
class Grover
|
5
|
+
#
|
6
|
+
# @param [String] url URL of the page to convert
|
7
|
+
# @param [Hash] options Optional parameters to pass to PDF processor
|
8
|
+
# see https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions
|
9
|
+
#
|
10
|
+
def initialize(url, options = {})
|
11
|
+
@url = url
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Request URL with provided options and create PDF
|
17
|
+
#
|
18
|
+
# @param [String] path Optional path to write the PDF to
|
19
|
+
# @return [Array<Integer>] Byte array of the resulting PDF
|
20
|
+
#
|
21
|
+
def to_pdf(path = nil)
|
22
|
+
options = @options.dup
|
23
|
+
options[:path] = path if path
|
24
|
+
result = Grover::Processor.new(root_path).convert_pdf(@url, options)
|
25
|
+
result['data'].pack('c*')
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
format(
|
30
|
+
'#<%<class_name>s:0x%<object_id>p @url="%<url>s">',
|
31
|
+
class_name: self.class.name,
|
32
|
+
object_id: object_id,
|
33
|
+
url: url
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def root_path
|
40
|
+
File.expand_path(__dir__)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'schmooze'
|
2
|
+
|
3
|
+
class Grover
|
4
|
+
#
|
5
|
+
# Processor helper class for calling out to Puppeteer NodeJS library
|
6
|
+
#
|
7
|
+
class Processor < Schmooze::Base
|
8
|
+
dependencies puppeteer: 'puppeteer'
|
9
|
+
|
10
|
+
def self.launch_params
|
11
|
+
ENV['CI'] == 'true' ? "{args: ['--no-sandbox', '--disable-setuid-sandbox']}" : ''
|
12
|
+
end
|
13
|
+
private_class_method :launch_params
|
14
|
+
|
15
|
+
method :convert_pdf, Utils.squish(<<-FUNCTION)
|
16
|
+
async (url, options) => {
|
17
|
+
let browser;
|
18
|
+
try {
|
19
|
+
browser = await puppeteer.launch(#{launch_params});
|
20
|
+
const page = await browser.newPage();
|
21
|
+
await page.goto(url, { waitUntil: 'networkidle2' });
|
22
|
+
return await page.pdf(options);
|
23
|
+
} finally {
|
24
|
+
if (browser) {
|
25
|
+
await browser.close();
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
FUNCTION
|
30
|
+
end
|
31
|
+
end
|
data/lib/grover/utils.rb
ADDED
data/lib/grover/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Bromwich
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: schmooze
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,18 +97,16 @@ dependencies:
|
|
83
97
|
description: A Ruby gem to transform HTML into PDFs using Google Puppeteer/Chromium
|
84
98
|
email:
|
85
99
|
- abromwich@studiosity.com
|
86
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- console
|
87
102
|
extensions: []
|
88
103
|
extra_rdoc_files: []
|
89
104
|
files:
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
94
|
-
-
|
95
|
-
- README.md
|
96
|
-
- Rakefile
|
97
|
-
- grover.gemspec
|
105
|
+
- bin/console
|
106
|
+
- lib/grover.rb
|
107
|
+
- lib/grover/grover.rb
|
108
|
+
- lib/grover/processor.rb
|
109
|
+
- lib/grover/utils.rb
|
98
110
|
- lib/grover/version.rb
|
99
111
|
homepage: http://github.com/Studiosity/grover
|
100
112
|
licenses:
|
data/.gitignore
DELETED
data/.rubocop.yml
DELETED
data/.travis.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
env:
|
2
|
-
global:
|
3
|
-
- CC_TEST_REPORTER_ID=5cfed40102c670b5c9e509730782b751939ddbe53fc57c317b718f635bab1ce8
|
4
|
-
|
5
|
-
language: ruby
|
6
|
-
rvm:
|
7
|
-
- 2.2
|
8
|
-
- 2.3
|
9
|
-
- 2.4
|
10
|
-
- 2.5
|
11
|
-
|
12
|
-
before_install:
|
13
|
-
- gem update bundler
|
14
|
-
|
15
|
-
install:
|
16
|
-
- bundle install --jobs=3 --retry=3
|
17
|
-
- gem install rubocop
|
18
|
-
|
19
|
-
before_script:
|
20
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
21
|
-
- chmod +x ./cc-test-reporter
|
22
|
-
- ./cc-test-reporter before-build
|
23
|
-
|
24
|
-
script:
|
25
|
-
- rubocop
|
26
|
-
- bundle exec rspec
|
27
|
-
|
28
|
-
after_script:
|
29
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile
DELETED
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2018 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 NONINFRINGEMENT. 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/README.md
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
[![Travis Build Status](http://img.shields.io/travis/Studiosity/grover.svg?style=flat)](https://travis-ci.org/Studiosity/grover)
|
2
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/37609653789bcf2c8d94/maintainability)](https://codeclimate.com/github/Studiosity/grover/maintainability)
|
3
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/37609653789bcf2c8d94/test_coverage)](https://codeclimate.com/github/Studiosity/grover/test_coverage)
|
4
|
-
[![Gem Version](http://img.shields.io/gem/v/grover.svg?style=flat)](#)
|
5
|
-
|
6
|
-
# Grover
|
7
|
-
|
8
|
-
A Ruby gem to transform HTML into PDFs using Google Puppeteer
|
data/Rakefile
DELETED
data/grover.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
lib = File.expand_path('lib', __dir__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
|
4
|
-
require 'grover/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'grover'
|
8
|
-
spec.version = Grover::VERSION
|
9
|
-
spec.authors = ['Andrew Bromwich']
|
10
|
-
spec.email = %w[abromwich@studiosity.com]
|
11
|
-
spec.description = 'A Ruby gem to transform HTML into PDFs using Google Puppeteer/Chromium'
|
12
|
-
spec.summary = 'A Ruby gem to transform HTML into PDFs wrapper the NodeJS Google Puppeteer project using Chromium'
|
13
|
-
spec.homepage = 'http://github.com/Studiosity/grover'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split("\n")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ['lib']
|
20
|
-
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
-
spec.add_development_dependency 'rake', '~> 12.3'
|
23
|
-
spec.add_development_dependency 'rspec', '~> 3.7'
|
24
|
-
spec.add_development_dependency 'rubocop', '~> 0.53'
|
25
|
-
spec.add_development_dependency 'simplecov', '~> 0.15'
|
26
|
-
end
|