puppeteer-ruby 0.34.0 → 0.34.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5338fde85118520d164288e9853e88f3edfadd0c0d6be491edcbde0c9d5609c
4
- data.tar.gz: b6ac2dada9f4c7ce72401cf75b39ca452801165d68d5bd6ae537cf3a390e68ff
3
+ metadata.gz: 759579a77012a03fa74915957ff0c3ed656ea4cdcc280b2f24fede885d01f361
4
+ data.tar.gz: 390f5ef626fb791dc9744cfe59a977fcd3a9d45c16d32aec60247a652ef73712
5
5
  SHA512:
6
- metadata.gz: eacd79d2af5cf69228ef6592739d20fd4f1739ec990355d904c32eb226c5dc998f7a37df7364a145df3e8beb763c304eaa8b1e1707c6aa8a237d4d8ec40f3b07
7
- data.tar.gz: f0a725e220a109e0498c34e2f3e0d8e8e979b89d6003124d8cff7bb30c8b3579e72e5d1531a6f80669307d5a81a13f62fe99ee3c811ab9cffcb617bd12969830
6
+ metadata.gz: aa0d6262ed3953a9b15efc2fdad2be48cd6b22cba0f1b89d7c93b0b9cbd52413705f60fe334cbb57b5f6eabffbb599b98db520859bd1239406def453ca314228
7
+ data.tar.gz: 84632098cf49cf5201528e2ac620321b83210bfb4f0a5bd6fae48a86fb5009a8c4e791b666eaf82b110eb4fc55a569723266e850381fe1b7dda49bd9830422d2
data/CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
- ### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.0...master)]
1
+ ### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.1...master)]
2
2
 
3
3
  * xxx
4
4
 
5
+ ### 0.34.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.0...0.34.1)]
6
+
7
+ Bugfix:
8
+
9
+ * Fix `Page#pdf` to work without `path` parameter.
10
+
5
11
  ### 0.34.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.33.0...0.34.0)]
6
12
 
7
13
  New features:
data/docs/api_coverage.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # API coverages
2
2
  - Puppeteer version: v10.0.0
3
- - puppeteer-ruby version: 0.34.0
3
+ - puppeteer-ruby version: 0.34.1
4
4
 
5
5
  ## Puppeteer
6
6
 
@@ -1008,14 +1008,40 @@ class Puppeteer::Page
1008
1008
  end
1009
1009
  end
1010
1010
 
1011
- # @return [String]
1012
- def pdf(options = {})
1011
+ # @return [Enumerable<String>]
1012
+ def create_pdf_stream(options = {})
1013
1013
  pdf_options = PDFOptions.new(options)
1014
1014
  omit_background = options[:omit_background]
1015
1015
  set_transparent_background_color if omit_background
1016
1016
  result = @client.send_message('Page.printToPDF', pdf_options.page_print_args)
1017
1017
  reset_default_background_color if omit_background
1018
- Puppeteer::ProtocolStreamReader.new(client: @client, handle: result['stream'], path: pdf_options.path).read
1018
+
1019
+ Puppeteer::ProtocolStreamReader.new(
1020
+ client: @client,
1021
+ handle: result['stream'],
1022
+ ).read_as_chunks
1023
+ end
1024
+
1025
+ # @return [String]
1026
+ def pdf(options = {})
1027
+ chunks = create_pdf_stream(options)
1028
+
1029
+ StringIO.open do |stringio|
1030
+ if options[:path]
1031
+ File.open(options[:path], 'wb') do |f|
1032
+ chunks.each do |chunk|
1033
+ f.write(chunk)
1034
+ stringio.write(chunk)
1035
+ end
1036
+ end
1037
+ else
1038
+ chunks.each do |chunk|
1039
+ stringio.write(chunk)
1040
+ end
1041
+ end
1042
+
1043
+ stringio.string
1044
+ end
1019
1045
  rescue => err
1020
1046
  if err.message.include?('PrintToPDF is not implemented')
1021
1047
  raise PrintToPdfIsNotImplementedError.new
@@ -15,17 +15,10 @@ class Puppeteer::Page
15
15
  # * @property {string|number=} height
16
16
  # * @property {boolean=} preferCSSPageSize
17
17
  # * @property {!{top?: string|number, bottom?: string|number, left?: string|number, right?: string|number}=} margin
18
- # * @property {string=} path
19
18
  # */
20
19
  class PDFOptions
21
20
  # @params options [Hash]
22
21
  def initialize(options)
23
- unless options[:path]
24
- # Original puppeteer allows path = nil, however nothing to do without path actually.
25
- # Also in most case, users forget to specify path parameter. So let's raise ArgumentError.
26
- raise ArgumentError('"path" parameter must be specified.')
27
- end
28
-
29
22
  @scale = options[:scale]
30
23
  @display_header_footer = options[:display_header_footer]
31
24
  @header_template = options[:header_template]
@@ -38,11 +31,8 @@ class Puppeteer::Page
38
31
  @height = options[:height]
39
32
  @prefer_css_page_size = options[:prefer_css_page_size]
40
33
  @margin = Margin.new(options[:margin] || {})
41
- @path = options[:path]
42
34
  end
43
35
 
44
- attr_reader :path
45
-
46
36
  class PaperSize
47
37
  def initialize(width:, height:)
48
38
  @width = width
@@ -1,25 +1,14 @@
1
1
  class Puppeteer::ProtocolStreamReader
2
- def initialize(client:, handle:, path:)
2
+ def initialize(client:, handle:)
3
3
  @client = client
4
4
  @handle = handle
5
- @path = path
6
5
  end
7
6
 
8
- def read
9
- StringIO.open do |out|
10
- if @path
11
- File.open(@path, 'wb') do |file|
12
- io_read do |data|
13
- out.write(data)
14
- file.write(data)
15
- end
16
- end
17
- else
18
- io_read { |data| out.write(data) }
19
- end
7
+ # @returns [Enumerable<String>]
8
+ def read_as_chunks
9
+ Enumerator.new do |out|
10
+ io_read { |data| out << data }
20
11
  io_close
21
-
22
- out.string
23
12
  end
24
13
  end
25
14
 
@@ -45,6 +45,23 @@ class Puppeteer::Tracing
45
45
  @recording = false
46
46
 
47
47
  stream = await stream_promise
48
- Puppeteer::ProtocolStreamReader.new(client: @client, handle: stream, path: @path).read
48
+ chunks = Puppeteer::ProtocolStreamReader.new(client: @client, handle: stream).read_as_chunks
49
+
50
+ StringIO.open do |stringio|
51
+ if @path
52
+ File.open(@path, 'wb') do |f|
53
+ chunks.each do |chunk|
54
+ f.write(chunk)
55
+ stringio.write(chunk)
56
+ end
57
+ end
58
+ else
59
+ chunks.each do |chunk|
60
+ stringio.write(chunk)
61
+ end
62
+ end
63
+
64
+ stringio.string
65
+ end
49
66
  end
50
67
  end
@@ -1,3 +1,3 @@
1
1
  module Puppeteer
2
- VERSION = '0.34.0'
2
+ VERSION = '0.34.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppeteer-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.34.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby