playwright-runner 1.1.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96731975daab3c59ab001fb663aadfdd3cdc79b79af624f24823fd886624908e
4
- data.tar.gz: 61b9e76b66eab8488d5569988726cee661c0fc9e2ad4549fe8fe3faf49c0c688
3
+ metadata.gz: a399a87fd16e38291470284d5301ac9f90eeece484c6f5f7cc6800885a343ccf
4
+ data.tar.gz: 15b75986e430acf686ac37865c81d2d36380bbdde99d6e7adddc27216c09cdfc
5
5
  SHA512:
6
- metadata.gz: 470deb264f7e15c05ced9c9021e4e0efad66f5b2e36f797f75a69a21f7fc5ff938899e1499aa4bf1709f61ef51ae442835d8d230ec4818d230596021e2e311c2
7
- data.tar.gz: a75b6871098d4954b84579a9059141e92daea649cfaf30ee68fd6bfe47fd1f2707fa583a3ec7162a2fd7b80e52af94afebc980e8d8aa3b0f2efc200c44030514
6
+ metadata.gz: 31d4186bb3dbe50865400a4be597663d4611085d6b0ce395de8dec2ad097ecafd24495fba3b9fe03ebd190ccc3f46c37b6f078a87ac00fd49f71b45e2a4367ea
7
+ data.tar.gz: 928a70639b0d77cbc36b8c59ec6a68a205eb6e70259e8c337cebb68d739d19ac5d8e5b72df06c7a69645bc7f0aa55bfa2dc33fc5b37525d2e04e273407ffabbf
@@ -6,13 +6,12 @@ jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
- - uses: actions/checkout@v2
9
+ - uses: actions/checkout@v5
10
10
  - name: Set up Ruby
11
11
  uses: ruby/setup-ruby@v1
12
12
  with:
13
- ruby-version: 2.7.4
13
+ ruby-version: 3.4
14
14
  - name: Run the default task
15
15
  run: |
16
- gem install bundler -v 2.2.5
17
16
  bundle install
18
17
  bundle exec rake
data/Gemfile CHANGED
@@ -4,8 +4,9 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
+ gem 'base64'
7
8
  gem 'rake', '~> 13.0'
8
- gem 'rubocop', '~> 1.45.1'
9
+ gem 'rubocop', '~> 1.80.1'
9
10
  gem 'rubocop-performance'
10
11
  gem 'rubocop-rake'
11
12
  gem 'simplecov'
data/README.md CHANGED
@@ -27,31 +27,35 @@ Of course PlaywrightRunner needs Playwright npm library.
27
27
 
28
28
  ## Usage
29
29
 
30
- ### Mermaid to PDF or SVG
30
+ ### Mermaid to PNG, PDF or SVG
31
31
 
32
- Let's convert HTML files contain [Mermaid](https://mermaid.js.org/) to PDF/SVG.
33
- You have to install two components also to crop and convert PDF before running:
32
+ Let's convert HTML files contain [Mermaid](https://mermaid.js.org/) to PNG/PDF/SVG.
34
33
 
35
- - [pdfcrop](https://www.ctan.org/pkg/pdfcrop) in TeXLive.
36
- - [pdftocairo](https://gitlab.freedesktop.org/poppler/poppler) in poppler (if you'd like to get SVG).
34
+ - To get marginless PDF, you have to install [pdfcrop](https://www.ctan.org/pkg/pdfcrop) from TeXLive.
35
+ - To make SVG, you have to install [pdftocairo](https://gitlab.freedesktop.org/poppler/poppler) from poppler.
37
36
 
38
37
  On Debian GNU/Linux or its derivatives, ues `apt-get install texlive-extra-utils poppler-utils`.
39
38
 
39
+ #### Syntax
40
40
  ```ruby
41
+ config = { # you can omit them if you don't want to change anything
42
+ playwright_path: './node_modules/.bin/playwright', # playwright binary path
43
+ selfcrop: true, # use chromium's crop logic. if you'd like to use better cropping, set this to false
44
+ pdfcrop_path: 'pdfcrop', # pdfcrop path (will be ignored when selfcrop: true)
45
+ pdftocairo_path: 'pdftocairo' # pdftocairo path
46
+ }
47
+
41
48
  PlaywrightRunner.mermaids_to_images(
42
- {
43
- playwright_path: './node_modules/.bin/playwright', // playwright binary path
44
- pdfcrop_path: 'pdfcrop', // pdfcrop path
45
- pdftocairo_path: 'pdftocairo' // pdftocairo path
46
- },
47
- src: '.', // source folder contains html files
48
- dest: '.', // destination folder to export pdf or svg
49
- type: 'pdf' // 'pdf' or 'svg'
49
+ config, # config hash. if you want to use default values, specify {}
50
+ src: '.', # source folder contains html files
51
+ dest: '.', # destination folder to export pdf or svg
52
+ type: 'pdf' # 'png', 'pdf', or 'svg'
50
53
  )
51
54
  ```
52
55
 
53
- It converts all HTML files in the folder specified by `src` into PDF or SVG files (specified by `type`) using that name and writes them in the folder specified by `dest`.
56
+ It converts all HTML files in the folder specified by `src` into PNG, PDF or SVG files (specified by `type`) using that name and writes them in the folder specified by `dest`.
54
57
 
58
+ #### Example
55
59
  For Example, here is `p1.html` contains Mermaid code.
56
60
 
57
61
  ```html
@@ -81,7 +85,7 @@ require 'playwrightrunner'
81
85
 
82
86
  PlaywrightRunner.mermaids_to_images(
83
87
  {
84
- playwright_path: './node_modules/.bin/playwright' // modify for your env
88
+ playwright_path: './node_modules/.bin/playwright' # modify for your env
85
89
  },
86
90
  src: '.',
87
91
  dest: '.',
@@ -96,7 +100,8 @@ require 'playwrightrunner'
96
100
 
97
101
  PlaywrightRunner.mermaids_to_images(
98
102
  {
99
- playwright_path: './node_modules/.bin/playwright' // modify for your env
103
+ playwright_path: './node_modules/.bin/playwright', # modify for your env
104
+ pdftocairo: 'pdftocairo' # set the path to your pdftocairo
100
105
  },
101
106
  src: '.',
102
107
  dest: '.',
@@ -106,6 +111,42 @@ PlaywrightRunner.mermaids_to_images(
106
111
 
107
112
  ![sample SVG](p1.svg)
108
113
 
114
+ Convert it to PNG. `p1.png` will be created.
115
+
116
+ ```ruby
117
+ require 'playwrightrunner'
118
+
119
+ PlaywrightRunner.mermaids_to_images(
120
+ {
121
+ playwright_path: './node_modules/.bin/playwright' # modify for your env
122
+ },
123
+ src: '.',
124
+ dest: '.',
125
+ type: 'png'
126
+ )
127
+ ```
128
+
129
+ #### about outside margin of images
130
+
131
+ In the default settings, white margins occur around the image. This is chromium's specification. To avoid this, you need to crop the PDF using the external command `pdfcrop`.
132
+
133
+ After installing `pdfcrop`, specify `selfcrop: false` on config.
134
+
135
+ ```ruby
136
+ require 'playwrightrunner'
137
+
138
+ PlaywrightRunner.mermaids_to_images(
139
+ {
140
+ playwright_path: './node_modules/.bin/playwright' # modify for your env
141
+ selfcrop: false,
142
+ pdfcrop_path: 'pdfcrop' # set the path to your pdfcrop
143
+ },
144
+ src: '.',
145
+ dest: '.',
146
+ type: 'pdf'
147
+ )
148
+ ```
149
+
109
150
  ## License
110
151
 
111
152
  ```
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlaywrightRunner
4
- VERSION = '1.1.0'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -9,22 +9,26 @@ require 'open3'
9
9
  require 'fileutils'
10
10
 
11
11
  module PlaywrightRunner
12
- def complement_config(config)
12
+ def default_config(config)
13
13
  config[:playwright_path] ||= './node_modules/.bin/playwright'
14
+
15
+ # for Mermaid
16
+ config[:selfcrop] = true if config[:selfcrop].nil?
14
17
  config[:pdfcrop_path] ||= 'pdfcrop'
15
18
  config[:pdftocairo_path] ||= 'pdftocairo'
16
19
 
17
20
  config
18
21
  end
19
22
 
20
- def mermaids_to_images(config, src: '.', dest: '.', type: 'pdf')
23
+ def mermaids_to_images(passed_config, src: '.', dest: '.', type: 'pdf', timeout: 10_000)
24
+ config = default_config(passed_config)
21
25
  Playwright.create(playwright_cli_executable_path: config[:playwright_path]) do |playwright|
22
- playwright.chromium.launch(headless: true) do |browser|
26
+ playwright.chromium.launch(headless: true, timeout: timeout) do |browser|
23
27
  page = browser.new_page
24
28
  Dir.glob(File.join(src, '*.html')).each do |entry|
25
29
  id = File.basename(entry).sub('.html', '')
26
- page.goto("file:///#{File.absolute_path(entry)}")
27
- page.locator('svg').wait_for(state: 'visible')
30
+ page.goto("file:///#{File.absolute_path(entry)}", timeout: timeout)
31
+ page.locator('svg').wait_for(state: 'visible', timeout: timeout)
28
32
  sleep(1)
29
33
  1.upto(4) do
30
34
  bounds = page.locator('svg').bounding_box
@@ -34,18 +38,40 @@ module PlaywrightRunner
34
38
  next
35
39
  end
36
40
 
37
- page.pdf(path: File.join(dest, '__PLAYWRIGHT_TMP__.pdf'))
41
+ if config[:selfcrop]
42
+ x = bounds['x'].floor
43
+ y = bounds['y'].floor
44
+ width = bounds['width'].ceil
45
+ height = bounds['height'].ceil
46
+ page.set_viewport_size({ width: x + width, height: y + height })
47
+
48
+ if type == 'png'
49
+ page.screenshot(path: File.join(dest, "#{id}.png"), clip: { x: x, y: y, width: width, height: height },
50
+ timeout: timeout)
51
+ break
52
+ end
53
+
54
+ page.pdf(path: File.join(dest, "#{id}.pdf"),
55
+ width: "#{width + (x * 2)}px",
56
+ height: "#{height + (y * 2)}px")
57
+ else
58
+ page.pdf(path: File.join(dest, '__PLAYWRIGHT_TMP__.pdf'))
59
+ Open3.capture2e(config[:pdfcrop_path],
60
+ File.join(dest, '__PLAYWRIGHT_TMP__.pdf'),
61
+ File.join(dest, "#{id}.pdf"))
62
+ end
63
+
38
64
  break
39
65
  end
40
66
 
41
- Open3.capture2e(config[:pdfcrop_path],
42
- File.join(dest, '__PLAYWRIGHT_TMP__.pdf'),
43
- File.join(dest, "#{id}.pdf"))
44
-
45
67
  next unless type == 'svg'
46
68
 
47
69
  Open3.capture2e(config[:pdftocairo_path],
48
70
  '-svg',
71
+ '-f',
72
+ '1',
73
+ '-l',
74
+ '1',
49
75
  File.join(dest, "#{id}.pdf"),
50
76
  File.join(dest, "#{id}.svg"))
51
77
  FileUtils.rm_f(File.join(dest, "#{id}.pdf"))
@@ -56,5 +82,5 @@ module PlaywrightRunner
56
82
  end
57
83
  end
58
84
 
59
- module_function :complement_config, :mermaids_to_images
85
+ module_function :mermaids_to_images, :default_config
60
86
  end
@@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.metadata['rubygems_mfa_required'] = 'true'
18
18
  spec.metadata['homepage_uri'] = spec.homepage
19
- spec.metadata['source_code_uri'] = 'https://github.com/kmuto/playwright-runner'
20
19
  spec.metadata['changelog_uri'] = 'https://github.com/kmuto/playwright-runner/commits/main'
21
20
 
22
21
  # Specify which files should be added to the gem when it is released.
@@ -28,5 +27,5 @@ Gem::Specification.new do |spec|
28
27
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
28
  spec.require_paths = ['lib']
30
29
 
31
- spec.add_dependency 'playwright-ruby-client', '~> 1.0'
30
+ spec.add_dependency 'playwright-ruby-client', '~> 1.28'
32
31
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playwright-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenshi Muto
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-04-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: playwright-ruby-client
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.0'
18
+ version: '1.28'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.0'
25
+ version: '1.28'
27
26
  description: Provide useful methods to run Playwright, intended to be used with Re:VIEW
28
27
  email:
29
28
  - kmuto@kmuto.jp
@@ -50,9 +49,7 @@ licenses:
50
49
  metadata:
51
50
  rubygems_mfa_required: 'true'
52
51
  homepage_uri: https://github.com/kmuto/playwright-runner
53
- source_code_uri: https://github.com/kmuto/playwright-runner
54
52
  changelog_uri: https://github.com/kmuto/playwright-runner/commits/main
55
- post_install_message:
56
53
  rdoc_options: []
57
54
  require_paths:
58
55
  - lib
@@ -67,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
64
  - !ruby/object:Gem::Version
68
65
  version: '0'
69
66
  requirements: []
70
- rubygems_version: 3.2.5
71
- signing_key:
67
+ rubygems_version: 3.6.7
72
68
  specification_version: 4
73
69
  summary: Playwright Runner
74
70
  test_files: []