postdoc 0.3.8 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/postdoc/client.rb +7 -4
- data/lib/postdoc/print_settings.rb +6 -1
- data/lib/postdoc.rb +7 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 258788efb416de9075412d16b3444250cc796859f4d7043c0fdd56be957dc775
|
4
|
+
data.tar.gz: c212194f3bf126eb4fa5ae4bf7122e71b3a0ba3fcaa2bf4c3871db209e4c17c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d3f4d1d0b0330a210c454d16be13db6cc2cc14311e3e382310dd75f2050d80d6f1b3815b83029400463acf9bb8447f3e083bca90ef263a6e7c3e8afb29c33d1
|
7
|
+
data.tar.gz: 4751105e4e348dd41598d9cb224f9aaf467c0773a726dd456abdfb5caeb73488d6bc097118d2904dcc14a5dd1a91a48ebc58b0387a4473640f7655f41717f3e7
|
data/lib/postdoc/client.rb
CHANGED
@@ -22,9 +22,10 @@ module Postdoc
|
|
22
22
|
client.send_cmd 'Page.navigate', url: "file://#{file_path}"
|
23
23
|
client.wait_for 'Page.loadEventFired'
|
24
24
|
|
25
|
+
# prevent race condition
|
26
|
+
sleep 0.1 if settings.slow_pc
|
27
|
+
|
25
28
|
response = client.send_cmd 'Page.printToPDF', settings.to_cmd
|
26
|
-
|
27
|
-
client.send_cmd 'Browser.close'
|
28
29
|
|
29
30
|
Base64.decode64 response['data']
|
30
31
|
end
|
@@ -33,9 +34,11 @@ module Postdoc
|
|
33
34
|
client.send_cmd 'Page.enable'
|
34
35
|
client.send_cmd 'Page.navigate', url: "file://#{file_path}"
|
35
36
|
client.wait_for 'Page.loadEventFired'
|
36
|
-
response = client.send_cmd 'Page.printToPDF', settings.to_cmd
|
37
37
|
|
38
|
-
|
38
|
+
# prevent race condition
|
39
|
+
sleep 0.1 if settings.slow_pc
|
40
|
+
|
41
|
+
response = client.send_cmd 'Page.printToPDF', settings.to_cmd
|
39
42
|
|
40
43
|
Base64.decode64 response['data']
|
41
44
|
end
|
@@ -2,6 +2,9 @@ module Postdoc
|
|
2
2
|
# Different prints require different settings. This class is used instead of
|
3
3
|
# passing options arguments throughout all of the code.
|
4
4
|
class PrintSettings
|
5
|
+
|
6
|
+
attr_accessor :slow_pc
|
7
|
+
|
5
8
|
def initialize(
|
6
9
|
header_template: '',
|
7
10
|
footer_template: '',
|
@@ -10,7 +13,8 @@ module Postdoc
|
|
10
13
|
margin_top: 1,
|
11
14
|
margin_bottom: 1,
|
12
15
|
margin_left: 1,
|
13
|
-
margin_right: 1
|
16
|
+
margin_right: 1,
|
17
|
+
slow_pc: false
|
14
18
|
)
|
15
19
|
@header_template = header_template
|
16
20
|
@footer_template = footer_template
|
@@ -20,6 +24,7 @@ module Postdoc
|
|
20
24
|
@margin_bottom = margin_bottom
|
21
25
|
@margin_left = margin_left
|
22
26
|
@margin_right = margin_right
|
27
|
+
@slow_pc = slow_pc
|
23
28
|
end
|
24
29
|
|
25
30
|
def to_cmd
|
data/lib/postdoc.rb
CHANGED
@@ -9,7 +9,7 @@ require 'postdoc/batch'
|
|
9
9
|
|
10
10
|
module Postdoc
|
11
11
|
ActionController::Renderers.add :pdf do |_filename, options|
|
12
|
-
Postdoc.render_from_string render_to_string(options), options
|
12
|
+
Postdoc.render_from_string render_to_string(options), &options
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.render_from_string(content, **options)
|
@@ -20,6 +20,9 @@ module Postdoc
|
|
20
20
|
.print_pdf_from_html(html_file.path,
|
21
21
|
settings: print_settings)
|
22
22
|
ensure
|
23
|
+
if server.client.client.present?
|
24
|
+
server.client.client.send_cmd 'Browser.close'
|
25
|
+
end
|
23
26
|
server.kill
|
24
27
|
html_file.cleanup
|
25
28
|
end
|
@@ -41,6 +44,9 @@ module Postdoc
|
|
41
44
|
server = ChromeProcess.new
|
42
45
|
batch.result(server.client)
|
43
46
|
ensure
|
47
|
+
if server.client.client.present?
|
48
|
+
server.client.client.send_cmd 'Browser.close'
|
49
|
+
end
|
44
50
|
server.kill
|
45
51
|
batch.cleanup
|
46
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postdoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Groeneveld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chrome_remote
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 4.0.0
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '7.0'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 4.0.0
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '7.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|