Dhalang 0.2.0 → 0.6.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 +4 -4
- data/.gitignore +52 -51
- data/.travis.yml +12 -8
- data/Dhalang.gemspec +30 -39
- data/Gemfile +6 -6
- data/Gemfile.lock +18 -17
- data/LICENSE +21 -21
- data/README.md +108 -42
- data/Rakefile +6 -6
- data/lib/Dhalang.rb +14 -4
- data/lib/Dhalang/error.rb +1 -0
- data/lib/Dhalang/file_utils.rb +37 -0
- data/lib/Dhalang/puppeteer.rb +95 -0
- data/lib/Dhalang/url_utils.rb +14 -0
- data/lib/Dhalang/version.rb +3 -3
- data/lib/PDF.rb +54 -65
- data/lib/Screenshot.rb +57 -51
- data/lib/js/dhalang.js +146 -0
- data/lib/js/pdf-generator.js +30 -0
- data/lib/js/screenshot-generator.js +32 -0
- data/package-lock.json +990 -0
- data/package.json +25 -25
- metadata +14 -10
- data/lib/js/pdfgenerator.js +0 -27
- data/lib/js/screenshotgenerator.js +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2357c5cdfe5dd841c64329fdab12478c719c6839fce8567520916eefc487f4e
|
4
|
+
data.tar.gz: c2507de8a15eed19c3807ad43c4f64d58cd7f1a6c32a1a61a37f828fed08cab3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d127ec4402220b31566af6ef16a12e375329515c60d7d6070663379e8f90315340cc0cadf9c0aa89604b5cea371c75a6f8f90af0f87ba98535125e59a614e965
|
7
|
+
data.tar.gz: '055953f266b9ad18c24405e1cd8d9c455722d8dfc23ca20e0c0a3224710b5bf91e0d0b31a555403cb7f70ddd20e927de1d325e3d477b56ced98112a6a7fa2f88'
|
data/.gitignore
CHANGED
@@ -1,51 +1,52 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
/.config
|
4
|
-
/coverage/
|
5
|
-
/InstalledFiles
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/spec/examples.txt
|
9
|
-
/test/tmp/
|
10
|
-
/test/version_tmp/
|
11
|
-
/
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# .
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
build-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
/
|
36
|
-
/
|
37
|
-
/
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
/
|
42
|
-
/
|
43
|
-
|
44
|
-
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# .
|
48
|
-
# .ruby-
|
49
|
-
|
50
|
-
|
51
|
-
.
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/node_modules/
|
12
|
+
/tmp/
|
13
|
+
.idea/*
|
14
|
+
|
15
|
+
# Used by dotenv library to load environment variables.
|
16
|
+
# .env
|
17
|
+
|
18
|
+
## Specific to RubyMotion:
|
19
|
+
.dat*
|
20
|
+
.repl_history
|
21
|
+
build/
|
22
|
+
*.bridgesupport
|
23
|
+
build-iPhoneOS/
|
24
|
+
build-iPhoneSimulator/
|
25
|
+
|
26
|
+
## Specific to RubyMotion (use of CocoaPods):
|
27
|
+
#
|
28
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
29
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
30
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
31
|
+
#
|
32
|
+
# vendor/Pods/
|
33
|
+
|
34
|
+
## Documentation cache and generated files:
|
35
|
+
/.yardoc/
|
36
|
+
/_yardoc/
|
37
|
+
/doc/
|
38
|
+
/rdoc/
|
39
|
+
|
40
|
+
## Environment normalization:
|
41
|
+
/.bundle/
|
42
|
+
/vendor/bundle
|
43
|
+
/lib/bundler/man/
|
44
|
+
|
45
|
+
# for a library or gem, you might want to ignore these files since the code is
|
46
|
+
# intended to run in multiple environments; otherwise, check them in:
|
47
|
+
# Gemfile.lock
|
48
|
+
# .ruby-version
|
49
|
+
# .ruby-gemset
|
50
|
+
|
51
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
52
|
+
.rvmrc
|
data/.travis.yml
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
language: ruby
|
2
|
+
node_js:
|
3
|
+
- node
|
4
|
+
rvm:
|
5
|
+
- 2.6
|
6
|
+
addons:
|
7
|
+
chrome: stable
|
8
|
+
before_install:
|
9
|
+
- nvm install v15.0.1
|
10
|
+
install:
|
11
|
+
- bundle install
|
12
|
+
- npm install
|
9
13
|
script: bundle exec rake spec
|
data/Dhalang.gemspec
CHANGED
@@ -1,39 +1,30 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "Dhalang/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "Dhalang"
|
8
|
-
spec.version = Dhalang::VERSION
|
9
|
-
spec.authors = ["Niels Steensma"]
|
10
|
-
spec.email = ["nielssteensma@yahoo.nl"]
|
11
|
-
spec.licenses = ['MIT']
|
12
|
-
|
13
|
-
spec.summary = "Ruby wrapper for Puppeteer. Generate screenshots and PDF's from HTML!"
|
14
|
-
spec.homepage = "https://github.com/NielsSteensma/Dhalang"
|
15
|
-
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
spec.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
-
spec.require_paths = ["lib"]
|
33
|
-
|
34
|
-
spec.add_development_dependency "bundler", "~> 1.16"
|
35
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
-
spec.add_development_dependency "pdf-reader", "~> 2.2"
|
38
|
-
spec.add_development_dependency "fastimage", "~> 1.8"
|
39
|
-
end
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "Dhalang/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "Dhalang"
|
8
|
+
spec.version = Dhalang::VERSION
|
9
|
+
spec.authors = ["Niels Steensma"]
|
10
|
+
spec.email = ["nielssteensma@yahoo.nl"]
|
11
|
+
spec.licenses = ['MIT']
|
12
|
+
|
13
|
+
spec.summary = "Ruby wrapper for Puppeteer. Generate screenshots and PDF's from HTML!"
|
14
|
+
spec.homepage = "https://github.com/NielsSteensma/Dhalang"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 13.0.1"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_development_dependency "pdf-reader", "~> 2.2"
|
29
|
+
spec.add_development_dependency "fastimage", "~> 1.8"
|
30
|
+
end
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in Dhalang.gemspec
|
6
|
-
gemspec
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in Dhalang.gemspec
|
6
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
Dhalang (0.
|
4
|
+
Dhalang (0.6.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -13,30 +13,31 @@ GEM
|
|
13
13
|
fastimage (1.9.0)
|
14
14
|
addressable (~> 2.3.5)
|
15
15
|
hashery (2.1.2)
|
16
|
-
pdf-reader (2.
|
16
|
+
pdf-reader (2.4.0)
|
17
17
|
Ascii85 (~> 1.0.0)
|
18
18
|
afm (~> 0.2.1)
|
19
19
|
hashery (~> 2.0)
|
20
20
|
ruby-rc4
|
21
21
|
ttfunk
|
22
|
-
rake (
|
23
|
-
rspec (3.
|
24
|
-
rspec-core (~> 3.
|
25
|
-
rspec-expectations (~> 3.
|
26
|
-
rspec-mocks (~> 3.
|
27
|
-
rspec-core (3.
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-expectations (3.
|
22
|
+
rake (13.0.1)
|
23
|
+
rspec (3.9.0)
|
24
|
+
rspec-core (~> 3.9.0)
|
25
|
+
rspec-expectations (~> 3.9.0)
|
26
|
+
rspec-mocks (~> 3.9.0)
|
27
|
+
rspec-core (3.9.1)
|
28
|
+
rspec-support (~> 3.9.1)
|
29
|
+
rspec-expectations (3.9.0)
|
30
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-mocks (3.
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-mocks (3.9.1)
|
33
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.
|
35
|
-
rspec-support (3.
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-support (3.9.2)
|
36
36
|
ruby-rc4 (0.1.5)
|
37
|
-
ttfunk (1.
|
37
|
+
ttfunk (1.6.2.1)
|
38
38
|
|
39
39
|
PLATFORMS
|
40
|
+
ruby
|
40
41
|
x64-mingw32
|
41
42
|
|
42
43
|
DEPENDENCIES
|
@@ -44,8 +45,8 @@ DEPENDENCIES
|
|
44
45
|
bundler (~> 1.16)
|
45
46
|
fastimage (~> 1.8)
|
46
47
|
pdf-reader (~> 2.2)
|
47
|
-
rake (~>
|
48
|
+
rake (~> 13.0.1)
|
48
49
|
rspec (~> 3.0)
|
49
50
|
|
50
51
|
BUNDLED WITH
|
51
|
-
1.
|
52
|
+
1.17.3
|
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2019 NielsS
|
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.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 NielsS
|
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
CHANGED
@@ -1,42 +1,108 @@
|
|
1
|
-
# Dhalang [](https://travis-ci.com/NielsSteensma/Dhalang)
|
2
|
-
|
3
|
-
> Dhalang is a Ruby wrapper for Google's Puppeteer.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
* Generate PDFs from
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
1
|
+
# Dhalang [](https://travis-ci.com/NielsSteensma/Dhalang)
|
2
|
+
|
3
|
+
> Dhalang is a Ruby wrapper for Google's Puppeteer.
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
## Features
|
8
|
+
* Generate PDFs from pages
|
9
|
+
* Generate PDFs from html ( external images/stylesheets supported )
|
10
|
+
* Capture a screenshot of a webpage
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'Dhalang'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle update
|
22
|
+
|
23
|
+
Install puppeteer in your application's root directory:
|
24
|
+
|
25
|
+
$ npm install puppeteer
|
26
|
+
|
27
|
+
<sub>NodeJS v10.18.1 or greater is required</sub>
|
28
|
+
## Usage
|
29
|
+
__Get a PDF of a website url__
|
30
|
+
`Dhalang::PDF.get_from_url("https://www.google.com")`
|
31
|
+
It is important to pass the complete url, leaving out https://, http:// or www. will result in an error.
|
32
|
+
|
33
|
+
__Get a PDF of a HTML string__
|
34
|
+
`Dhalang::PDF.get_from_html("<html><head></head><body><h1>examplestring</h1></body></html>")`
|
35
|
+
|
36
|
+
__Get a PNG screenshot of a website__
|
37
|
+
`Dhalang::Screenshot.get_from_url_as_png("https://www.google.com")`
|
38
|
+
|
39
|
+
__Get a JPEG screenshot of a website__
|
40
|
+
`Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com")`
|
41
|
+
|
42
|
+
All methods return a string containing the PDF or JPEG/PNG in binary.
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
## Custom PDF/screenshot options
|
47
|
+
To override the default options that are set by Dhalang you can pass as last argument a hash with the custom options you want to set.
|
48
|
+
|
49
|
+
For example to set custom margins for PDFs:
|
50
|
+
|
51
|
+
`Dhalang::PDF.get_from_url("https://www.google.com", {margin: { top: 100, right: 100, bottom: 100, left: 100}})
|
52
|
+
`
|
53
|
+
|
54
|
+
For example to only take a screenshot of the visible part of the page:
|
55
|
+
`Dhalang::Screenshot.get_from_url_as_png("https://www.google.com", {fullPage: false})
|
56
|
+
`
|
57
|
+
|
58
|
+
A list of all possible PDF options that can be set, can be found at: https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions
|
59
|
+
|
60
|
+
A list of all possible screenshot options that can be set, can be found at: https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagescreenshotoptions
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
## Custom user options
|
66
|
+
You may want to change the way Dhalang interacts with Puppeteer in general. User options can be set by providing them in a hash as last argument to any calls you make to the library. Are you setting both custom PDF and user options? Then they should be passed as a single hash.
|
67
|
+
|
68
|
+
For example to set a custom navigation timeout:
|
69
|
+
`Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com", {navigationTimeout: 20000})`
|
70
|
+
|
71
|
+
Below table lists all possible configuration parameters that can be set:
|
72
|
+
| Key | Description | Default |
|
73
|
+
|--------------------|-----------------------------------------------------------------------------------------|---------------------------------|
|
74
|
+
| navigationTimeout | Amount of milliseconds until Puppeteer while timeout when navigating to the given page | 10000 |
|
75
|
+
| navigationWaitForSelector | If set, Dhalang will wait for the specified selector to appear before creating the screenshot or PDF | None |
|
76
|
+
| navigationWaitForXPath | If set, Dhalang will wait for the specified XPath to appear before creating the screenshot or PDF | None |
|
77
|
+
| userAgent | User agent to send with the request | Default Puppeteer one |
|
78
|
+
| isHeadless | Indicates if Chromium should be launched headless | true |
|
79
|
+
| isAutoHeight | When set to true the height of generated PDFs will be based on the scrollHeight property of the document body | false |
|
80
|
+
| viewPort | Custom viewport to use for the request | Default Puppeteer one |
|
81
|
+
| httpAuthenticationCredentials | Custom HTTP authentication credentials to use for the request | None |
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
## Examples of using Dhalang
|
86
|
+
To return a PDF from a Rails controller you can do the following:
|
87
|
+
```
|
88
|
+
def example_controller_method
|
89
|
+
binary_pdf = Dhalang::PDF.get_from_url("https://www.google.com")
|
90
|
+
send_data(binary_pdf, filename: 'pdfofgoogle.pdf', type: 'application/pdf')
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
To return a PNG from a Rails controller you can do the following:
|
95
|
+
```
|
96
|
+
def example_controller_method
|
97
|
+
binary_png = Dhalang::Screenshot.get_from_url_as_png("https://www.google.com")
|
98
|
+
send_data(binary_png, filename: 'screenshotofgoogle.png', type: 'image/png')
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
To return a JPEG from a Rails controller you can do the following:
|
103
|
+
```
|
104
|
+
def example_controller_method
|
105
|
+
binary_jpeg = Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com")
|
106
|
+
send_data(binary_jpeg, filename: 'screenshotofgoogle.jpeg', type: 'image/jpeg')
|
107
|
+
end
|
108
|
+
```
|