Dhalang 0.2.0 → 0.3.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 +8 -8
- data/Dhalang.gemspec +32 -39
- data/Gemfile +6 -6
- data/Gemfile.lock +18 -17
- data/LICENSE +21 -21
- data/README.md +63 -42
- data/Rakefile +6 -6
- data/lib/Dhalang.rb +10 -3
- data/lib/Dhalang/file_utils.rb +37 -0
- data/lib/Dhalang/puppeteer.rb +17 -0
- data/lib/Dhalang/url_utils.rb +14 -0
- data/lib/Dhalang/version.rb +3 -3
- data/lib/PDF.rb +51 -65
- data/lib/Screenshot.rb +43 -51
- data/lib/js/dhalang.js +54 -0
- data/lib/js/pdf-generator.js +33 -0
- data/lib/js/screenshot-generator.js +27 -0
- data/package-lock.json +367 -0
- data/package.json +25 -25
- metadata +13 -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: 0e81627f9004f346443d46b9ab0befaec1c11c95a6c81521c9e1340901d97427
|
4
|
+
data.tar.gz: adb156ead06f2b4886f7ce0972b4477f56a1a793d3fa4fd9fe289e899088f309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6019c5635f2020d8c49c5dfc4cab09f4bd59c5445402016e894579fd4a68097b2675559950aa7f2a8cdf014db4ae1d0381682ecbcc04e7de6bf0e57195caf1fa
|
7
|
+
data.tar.gz: c833cdfb54c3f4f99b3e047fa1381555025c1faf48f723ec38eff8a29ad572b20b22d9dfada76fda0b71d9c45b734ea3fbae378ef5d4ca7872aa07f1abd698e6
|
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,9 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.6
|
4
|
-
addons:
|
5
|
-
chrome: stable
|
6
|
-
install:
|
7
|
-
- bundle install
|
8
|
-
- npm install
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.6
|
4
|
+
addons:
|
5
|
+
chrome: stable
|
6
|
+
install:
|
7
|
+
- bundle install
|
8
|
+
- npm install
|
9
9
|
script: bundle exec rake spec
|
data/Dhalang.gemspec
CHANGED
@@ -1,39 +1,32 @@
|
|
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
|
-
spec.
|
31
|
-
spec.
|
32
|
-
|
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
|
+
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0.1"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "pdf-reader", "~> 2.2"
|
31
|
+
spec.add_development_dependency "fastimage", "~> 1.8"
|
32
|
+
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.2.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.2
|
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,63 @@
|
|
1
|
-
# Dhalang [](https://travis-ci.com/NielsSteensma/Dhalang)
|
2
|
-
|
3
|
-
> Dhalang is a Ruby wrapper for Google's Puppeteer.
|
4
|
-
|
5
|
-
|
6
|
-
## Features
|
7
|
-
* Generate PDFs from pages
|
8
|
-
* Generate PDFs from html ( external images/stylesheets supported )
|
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
|
+
## Features
|
7
|
+
* Generate PDFs from pages
|
8
|
+
* Generate PDFs from html ( external images/stylesheets supported )
|
9
|
+
* Capture a screenshot of a webpage
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'Dhalang'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle update
|
19
|
+
|
20
|
+
Install puppeteer in your application's root directory:
|
21
|
+
|
22
|
+
$ npm install puppeteer
|
23
|
+
|
24
|
+
<sub>NodeJS v7.6.0 or greater is required</sub>
|
25
|
+
## Usage
|
26
|
+
__Get a PDF of a website url__
|
27
|
+
`Dhalang::PDF.get_from_url("https://www.google.com")`
|
28
|
+
It is important to pass the complete url, leaving out https://, http:// or www. will result in an error.
|
29
|
+
|
30
|
+
__Get a PDF of a HTML string__
|
31
|
+
`Dhalang::PDF.get_from_html("<html><head></head><body><h1>examplestring</h1></body></html>")`
|
32
|
+
|
33
|
+
__Get a PNG screenshot of a website__
|
34
|
+
`Dhalang::Screenshot.get_from_url_as_png("https://www.google.com")`
|
35
|
+
|
36
|
+
__Get a JPEG screenshot of a website__
|
37
|
+
`Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com")`
|
38
|
+
|
39
|
+
All methods return a string containing the PDF or JPEG/PNG in binary.
|
40
|
+
|
41
|
+
To return the PDF from a Rails controller you can do the following:
|
42
|
+
```
|
43
|
+
def example_controller_method
|
44
|
+
binary_pdf = Dhalang::PDF.get_from_url("https://www.google.com")
|
45
|
+
send_data(binary_pdf, filename: 'pdfofgoogle.pdf', type: 'application/pdf')
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
To return the PNG from a Rails controller you can do the following:
|
50
|
+
```
|
51
|
+
def example_controller_method
|
52
|
+
binary_png = Dhalang::Screenshot.get_from_url_as_png("https://www.google.com")
|
53
|
+
send_data(binary_png, filename: 'screenshotofgoogle.png', type: 'image/png')
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
To return the JPEG from a Rails controller you can do the following:
|
58
|
+
```
|
59
|
+
def example_controller_method
|
60
|
+
binary_jpeg = Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com")
|
61
|
+
send_data(binary_jpeg, filename: 'screenshotofgoogle.jpeg', type: 'image/jpeg')
|
62
|
+
end
|
63
|
+
```
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|