Dhalang 0.6.2 → 0.6.3

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: 0b5a8f2427673c1a21cbbfcc3f9b3119c11890b9dbb21a1656ec970c14b4faef
4
- data.tar.gz: d98cac7a86e5c12c0fc845e71a8810c3adaa3c583fb53a4139f2e1408231cceb
3
+ metadata.gz: affc5a7a677cade8adf37073ab71155ad812fdb0765c947c560ecb8de50dafc3
4
+ data.tar.gz: 72a7122ea73080759aef9d5ccd375167da9efffee1836f92df990c7046df08d7
5
5
  SHA512:
6
- metadata.gz: 142fcef44cc80374790a915356c7eda5b5a5d91e532c44a4a81515f07454b9c2a7a04d34d53b3cb481fb0ed2f58cc6a0ed974a0ad4d244e9622f754e32e47624
7
- data.tar.gz: 8379ed46f315e7cf3cfa657c2972fbdc3e34bee4255f2be741e84835c82536d4ace52290fb0197e1638a77667fa0a59309357ce62bca3887ba746c44665d8e9c
6
+ metadata.gz: a007aa999b92d55b8d10bf6e0683d9f5ddf833f5a3f26914abfbdda562a25bb197ba29595f4d55edbcd9c11ea15eb0a2c57da8bb5595e38f521e5a465c13aa24
7
+ data.tar.gz: 2bdf23451af29feaa0ba70b78c7af7ca603bc02db2dfffcbbd815dd766b4fc99972328a7cf2d6b15dad23dadfc51aa8f3ea10713652ed087df4fa46890211f3e
data/.travis.yml CHANGED
@@ -1,13 +1,21 @@
1
1
  language: ruby
2
2
  node_js:
3
- - node
3
+ - node
4
4
  rvm:
5
- - 2.6
5
+ - 2.6
6
6
  addons:
7
7
  chrome: stable
8
8
  before_install:
9
- - nvm install v15.0.1
9
+ - nvm install v15.0.1
10
10
  install:
11
- - bundle install
12
- - npm install
13
- script: bundle exec rake spec
11
+ - bundle install
12
+ - npm install
13
+ script: bundle exec rake spec
14
+ deploy:
15
+ provider: rubygems
16
+ gemspec: Dhalang.gemspec
17
+ api_key:
18
+ secure: PMiaYF8Xtyyl9Kuhf9WwDRaUzUcqbe430DF8Rwk2qYM1oI8eiYbESswHVavAnrT+ZLKZVzp0+avXJ1TFjoz2tHBa7YVmmz76+RvECozwBXFVofK0GX8c6PVZTuuHgoanr1RVv0KTJOZXs5Aa+372Er31ESuwaaRPU2y/d8aotxtoe7MUoVle67S7Z28H53jwDCut54WFq6hKi+gNO/B+7y/e2efPgrqSktHxaPDGcaUaX9v8fAYBJgAulJLYMeRj+m7IQccajIjppr7vWDE1m9XEDAK71i3EZis96/z+KexB2bo3+Qc+TvpTWP5NeKw61uhtPn9HU4+XCaOV8Vz0e6PH2JfS82h333BcSifXjcFb9iQU8aEMpSpcjraUvvvu8JZepUUO//vtGEJLyOJ0L4f9XiUPhQ15OYjBsJ2ADFdNcqyFeASDuLoeKbAQrWunyTStb+wFrr5TzAoQp9ItZbEt6eHaI6WSd4qhJfzqU7NOzE06Ns03J1jMdmzMxREl8ENJFle65fQouQfRnfcZTS6qW7UX/7YZUiMw60Cpa15qHW+92glCkOuiZUhr4D999ejqMFY5Jd3tHGVBX0/1MWc2jl0fPk2/fueA/YW8xLd3xKP9p0KhbqWZhiMxIct5w718nfOLuSoL1VLJRImj4HAKmoCFKP4RE+1Vl95UwEY=
19
+ on:
20
+ branch: master
21
+ tags: true
data/Dhalang.gemspec CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.16"
26
- spec.add_development_dependency "rake", "~> 13.0.1"
25
+ spec.add_development_dependency "bundler", "~> 2.3.6"
26
+ spec.add_development_dependency "fastimage", "~> 2.2.6"
27
+ spec.add_development_dependency "pdf-reader", "~> 2.9.0"
28
+ spec.add_development_dependency "rake", "~> 13.0.6"
27
29
  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
30
  end
data/Gemfile.lock CHANGED
@@ -1,52 +1,49 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Dhalang (0.6.0)
4
+ Dhalang (0.6.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- Ascii85 (1.0.3)
10
- addressable (2.3.8)
9
+ Ascii85 (1.1.0)
11
10
  afm (0.2.2)
12
- diff-lcs (1.3)
13
- fastimage (1.9.0)
14
- addressable (~> 2.3.5)
11
+ diff-lcs (1.5.0)
12
+ fastimage (2.2.6)
15
13
  hashery (2.1.2)
16
- pdf-reader (2.4.0)
17
- Ascii85 (~> 1.0.0)
14
+ pdf-reader (2.9.0)
15
+ Ascii85 (~> 1.0)
18
16
  afm (~> 0.2.1)
19
17
  hashery (~> 2.0)
20
18
  ruby-rc4
21
19
  ttfunk
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)
20
+ rake (13.0.6)
21
+ rspec (3.10.0)
22
+ rspec-core (~> 3.10.0)
23
+ rspec-expectations (~> 3.10.0)
24
+ rspec-mocks (~> 3.10.0)
25
+ rspec-core (3.10.2)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-expectations (3.10.2)
30
28
  diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.9.0)
32
- rspec-mocks (3.9.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-mocks (3.10.3)
33
31
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.9.0)
35
- rspec-support (3.9.2)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-support (3.10.3)
36
34
  ruby-rc4 (0.1.5)
37
- ttfunk (1.6.2.1)
35
+ ttfunk (1.7.0)
38
36
 
39
37
  PLATFORMS
40
- ruby
41
- x64-mingw32
38
+ x86-mingw32
42
39
 
43
40
  DEPENDENCIES
44
41
  Dhalang!
45
- bundler (~> 1.16)
46
- fastimage (~> 1.8)
47
- pdf-reader (~> 2.2)
48
- rake (~> 13.0.1)
42
+ bundler (~> 2.3.6)
43
+ fastimage (~> 2.2.6)
44
+ pdf-reader (~> 2.9.0)
45
+ rake (~> 13.0.6)
49
46
  rspec (~> 3.0)
50
47
 
51
48
  BUNDLED WITH
52
- 1.17.3
49
+ 2.3.6
data/README.md CHANGED
@@ -27,18 +27,25 @@ Install puppeteer in your application's root directory:
27
27
  <sub>NodeJS v10.18.1 or greater is required</sub>
28
28
  ## Usage
29
29
  __Get a PDF of a website url__
30
- `Dhalang::PDF.get_from_url("https://www.google.com")`
30
+ ```ruby
31
+ Dhalang::PDF.get_from_url("https://www.google.com")
32
+ ```
31
33
  It is important to pass the complete url, leaving out https://, http:// or www. will result in an error.
32
-
34
+
33
35
  __Get a PDF of a HTML string__
34
- `Dhalang::PDF.get_from_html("<html><head></head><body><h1>examplestring</h1></body></html>")`
36
+ ```ruby
37
+ Dhalang::PDF.get_from_html("<html><head></head><body><h1>examplestring</h1></body></html>")
38
+ ```
35
39
 
36
40
  __Get a PNG screenshot of a website__
37
- `Dhalang::Screenshot.get_from_url_as_png("https://www.google.com")`
41
+ ```ruby
42
+ Dhalang::Screenshot.get_from_url_as_png("https://www.google.com")
43
+ ```
38
44
 
39
45
  __Get a JPEG screenshot of a website__
40
- `Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com")`
41
-
46
+ ```ruby
47
+ Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com")
48
+ ```
42
49
  All methods return a string containing the PDF or JPEG/PNG in binary.
43
50
 
44
51
 
@@ -47,26 +54,34 @@ All methods return a string containing the PDF or JPEG/PNG in binary.
47
54
  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
55
 
49
56
  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
- `
57
+ ```ruby
58
+ Dhalang::PDF.get_from_url("https://www.google.com", {margin: { top: 100, right: 100, bottom: 100, left: 100}})
59
+ ```
53
60
 
54
61
  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
- `
62
+ ```ruby
63
+ Dhalang::Screenshot.get_from_url_as_png("https://www.google.com", {fullPage: false})
64
+ ```
57
65
 
58
66
  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
67
 
60
68
  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
69
 
62
-
70
+ > The default Puppeteer options contain the options `headerTemplate` and `footerTemplate`. Puppeteer expects these to be HTML strings. By default, the Dhalang
71
+ > gem passes all options as arguments in a `node ...` shell command. In case the HTML strings are too long they might surpass the maximum
72
+ > argument length of the host. For example, on Linux the `MAX_ARG_LEN` is 128kB. Therefore, you can also pass the headers and footers as file path using the
73
+ > options `headerTemplateFile` and `footerTemplateFile`. These non-Puppeteer-options will be used to populate the Puppeteer-options `headerTemplate` and `footerTemplate`.
74
+ >
75
+ > For example: `Dhalang::PDF.get_from_url("https://www.google.com", {headerTemplateFile: '/tmp/header.html', footerTemplateFile: '/tmp/footer.html'})`
63
76
 
64
77
 
65
78
  ## Custom user options
66
79
  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
80
 
68
81
  For example to set a custom navigation timeout:
69
- `Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com", {navigationTimeout: 20000})`
82
+ ```ruby
83
+ Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com", {navigationTimeout: 20000})
84
+ ```
70
85
 
71
86
  Below table lists all possible configuration parameters that can be set:
72
87
  | Key | Description | Default |
@@ -79,7 +94,7 @@ Below table lists all possible configuration parameters that can be set:
79
94
  | isAutoHeight | When set to true the height of generated PDFs will be based on the scrollHeight property of the document body | false |
80
95
  | viewPort | Custom viewport to use for the request | Default Puppeteer one |
81
96
  | httpAuthenticationCredentials | Custom HTTP authentication credentials to use for the request | None |
82
-
97
+ | chromeOptions | A array of [options](https://peter.sh/experiments/chromium-command-line-switches/) that can be passed to puppeteer in addition to the mandatory `['--no-sandbox', '--disable-setuid-sandbox']` | [] |
83
98
 
84
99
 
85
100
  ## Examples of using Dhalang
@@ -13,7 +13,8 @@ module Dhalang
13
13
  isHeadless: true,
14
14
  viewPort: '',
15
15
  httpAuthenticationCredentials: '',
16
- isAutoHeight: false
16
+ isAutoHeight: false,
17
+ chromeOptions: []
17
18
  }
18
19
  private_constant :USER_OPTIONS
19
20
 
@@ -22,6 +23,8 @@ module Dhalang
22
23
  displayHeaderFooter: false,
23
24
  headerTemplate: '',
24
25
  footerTemplate: '',
26
+ headerTemplateFile: '',
27
+ footerTemplateFile: '',
25
28
  printBackground: true,
26
29
  landscape: false,
27
30
  pageRanges: '',
@@ -1,3 +1,3 @@
1
1
  module Dhalang
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
data/lib/js/dhalang.js CHANGED
@@ -1,3 +1,5 @@
1
+ const fs = require('fs')
2
+
1
3
  /**
2
4
  * @typedef {Object} Configuration
3
5
  * @property {string} webPageUrl - The url of the webpage to visit.
@@ -52,7 +54,7 @@ exports.getConfiguration = function () {
52
54
  exports.launchPuppeteer = async function (configuration) {
53
55
  module.paths.push(configuration.puppeteerPath);
54
56
  const puppeteer = require('puppeteer');
55
- const launchArgs = ['--no-sandbox', '--disable-setuid-sandbox'];
57
+ const launchArgs = ['--no-sandbox', '--disable-setuid-sandbox'].concat(configuration.userOptions.chromeOptions).filter((item, index, self) => self.indexOf(item) === index);
56
58
  return await puppeteer.launch({
57
59
  args: launchArgs,
58
60
  headless: configuration.userOptions.isHeadless
@@ -107,6 +109,21 @@ exports.navigate = async function (page, configuration) {
107
109
  exports.getConfiguredPdfOptions = async function (page, configuration) {
108
110
  const pdfOptions = configuration.pdfOptions
109
111
 
112
+ if (pdfOptions['headerTemplateFile'] !== '') {
113
+ try {
114
+ pdfOptions['headerTemplate'] = fs.readFileSync(pdfOptions['headerTemplateFile'], 'utf8')
115
+ } catch(err) {
116
+ // ignoring file related errors
117
+ }
118
+ }
119
+ if (pdfOptions['footerTemplateFile'] !== '') {
120
+ try {
121
+ pdfOptions['footerTemplate'] = fs.readFileSync(pdfOptions['footerTemplateFile'], 'utf8')
122
+ } catch(err) {
123
+ // ignoring file related errors
124
+ }
125
+ }
126
+
110
127
  if (configuration.userOptions.isAutoHeight === true) {
111
128
  const pageHeight = await page.evaluate(() => {
112
129
  return Math.max(document.body.scrollHeight, document.body.offsetHeight);
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dhalang",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Dhalang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niels Steensma
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-25 00:00:00.000000000 Z
11
+ date: 2022-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: 2.3.6
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: 2.3.6
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: fastimage
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 13.0.1
33
+ version: 2.2.6
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 13.0.1
40
+ version: 2.2.6
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: pdf-reader
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: 2.9.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: 2.9.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: pdf-reader
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.2'
61
+ version: 13.0.6
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.2'
68
+ version: 13.0.6
69
69
  - !ruby/object:Gem::Dependency
70
- name: fastimage
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.8'
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.8'
82
+ version: '3.0'
83
83
  description:
84
84
  email:
85
85
  - nielssteensma@yahoo.nl
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  requirements: []
130
- rubygems_version: 3.0.3
130
+ rubygems_version: 3.0.8
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Ruby wrapper for Puppeteer. Generate screenshots and PDF's from HTML!