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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 976f451a66958a17261f84b2f79c2740323f74efc48c2e003fdb95b3f72111fd
4
- data.tar.gz: 75e517eea1ec5a62a26a7beccdd3ee5adcf6c257e4cc5eb96782548728e00868
3
+ metadata.gz: a2357c5cdfe5dd841c64329fdab12478c719c6839fce8567520916eefc487f4e
4
+ data.tar.gz: c2507de8a15eed19c3807ad43c4f64d58cd7f1a6c32a1a61a37f828fed08cab3
5
5
  SHA512:
6
- metadata.gz: 3ae7a907a31cf50d0bd5e6f78a27b4ccd77e2a9c6baa13b8430f48f00944af5160844a84ae428f1f0db8cba9afa083560f22d50de1f492052702773d1464ce77
7
- data.tar.gz: 1244560c1a4cd3b2ae2a1020c79c99f30bfa6ce1b2fe413dabc5d24e7ba66f16101c8f1460b69d35edfbffcaa86c22e6687fed1cef39f2c785bc822bd03bbe66
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
- /tmp/
12
- .idea/*
13
-
14
- # Used by dotenv library to load environment variables.
15
- # .env
16
-
17
- ## Specific to RubyMotion:
18
- .dat*
19
- .repl_history
20
- build/
21
- *.bridgesupport
22
- build-iPhoneOS/
23
- build-iPhoneSimulator/
24
-
25
- ## Specific to RubyMotion (use of CocoaPods):
26
- #
27
- # We recommend against adding the Pods directory to your .gitignore. However
28
- # you should judge for yourself, the pros and cons are mentioned at:
29
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
- #
31
- # vendor/Pods/
32
-
33
- ## Documentation cache and generated files:
34
- /.yardoc/
35
- /_yardoc/
36
- /doc/
37
- /rdoc/
38
-
39
- ## Environment normalization:
40
- /.bundle/
41
- /vendor/bundle
42
- /lib/bundler/man/
43
-
44
- # for a library or gem, you might want to ignore these files since the code is
45
- # intended to run in multiple environments; otherwise, check them in:
46
- # Gemfile.lock
47
- # .ruby-version
48
- # .ruby-gemset
49
-
50
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
- .rvmrc
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
@@ -1,9 +1,13 @@
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
+ 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
@@ -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
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against " \
22
- "public gem pushes."
23
- end
24
-
25
- # Specify which files should be added to the gem when it is released.
26
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
- end
30
- spec.bindir = "exe"
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Dhalang (0.1.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.2.0)
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 (10.5.0)
23
- rspec (3.8.0)
24
- rspec-core (~> 3.8.0)
25
- rspec-expectations (~> 3.8.0)
26
- rspec-mocks (~> 3.8.0)
27
- rspec-core (3.8.0)
28
- rspec-support (~> 3.8.0)
29
- rspec-expectations (3.8.2)
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.8.0)
32
- rspec-mocks (3.8.0)
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.8.0)
35
- rspec-support (3.8.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.2)
36
36
  ruby-rc4 (0.1.5)
37
- ttfunk (1.5.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 (~> 10.0)
48
+ rake (~> 13.0.1)
48
49
  rspec (~> 3.0)
49
50
 
50
51
  BUNDLED WITH
51
- 1.16.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 [![Build Status](https://travis-ci.com/NielsSteensma/Dhalang.svg?token=XZgKAByw2KZjcrsCh8gW&branch=master)](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
- More will come.
11
-
12
- ## Installation
13
- Add this line to your application's Gemfile:
14
-
15
- gem 'Dhalang'
16
-
17
- And then execute:
18
-
19
- $ bundle update
20
-
21
- Install puppeteer in your application's root directory:
22
-
23
- $ npm install puppeteer
24
-
25
- <sub>NodeJS v7.6.0 or greater is required</sub>
26
- ## Usage
27
- __Get a PDF of a website url__
28
- `Dhalang::PDF.get_from_url("https://www.google.com")`
29
- It is important to pass the complete url, leaving out https://, http:// or www. will result in an error.
30
-
31
- __Get a PDF of a HTML string__
32
- `Dhalang::PDF.get_from_html("<html><head></head><body><h1>examplestring</h1></body></html>")`
33
-
34
- Both methods return a string containing the PDF in binary.
35
-
36
- To return the PDF from a Rails controller you can do the following:
37
- ```
38
- def example_controller_method
39
- binary_pdf = Dhalang::PDF.get_from_url("https://www.google.com")
40
- send_data(binary_pdf, filename: 'pdfofgoogle.pdf', type: 'application/pdf')
41
- end
42
- ```
1
+ # Dhalang [![Build Status](https://travis-ci.com/NielsSteensma/Dhalang.svg?token=XZgKAByw2KZjcrsCh8gW&branch=master)](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
+ ```