postdoc 0.2.1 → 0.3.1

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: 66b2bf15842d2bb088526c1d00aa1680e299aa37b0431825d60d71ce84d77b6c
4
- data.tar.gz: acc941b19fbbbddb2e0f6c84ddad1fe7576852b09eabed787063afe6b428b74c
3
+ metadata.gz: 347fc91d568be3659d11cbd1c350ab6777a480d38efafbda841cdcf18a897a40
4
+ data.tar.gz: 7ef1235281009ae11450ca7b7dab86ad4245d5428a1d605891de21c3ef006843
5
5
  SHA512:
6
- metadata.gz: a3cc2d4563b3c660122817b3abd73897842baf84fa7cbecf4b054dc3758826fef359d68613fc10a60a5eecfcbc7a2841a3d6e89e45ee98bf050f2acd24f10783
7
- data.tar.gz: 55d531eaffa08bb24545fa3e1103d4e6377bc10f63514b3baaea8254aad04a2319a90bd0dbda66b7d56027082245d23cf3fc7e3041afd2baa7ebe67687b34b68
6
+ metadata.gz: c9e5086f120958a770f3662579b3a9f67ea51ab44625e7d49067af8748762f184dfc56aaff652b9f2d907e839e6336ca4e0b520a2b0d581a227c77b2a64ed2e3
7
+ data.tar.gz: 053424d30b3ae859235c24f784f20a194ea40a33e306ae4e7f8129f14199afbd47b59d94a1a90542e6777ba73287c7e738d45a9e5355eb070aa4ff772daaf93e
@@ -1,32 +1,41 @@
1
- require 'postdoc/postdoc_view_helper'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'chrome_remote'
3
4
 
4
5
  module Postdoc
5
-
6
- class PostdocRailtie < Rails::Railtie
7
- initializer 'postdoc.register' do |_app|
8
- ActionView::Base.send :include, PostdocViewHelper
9
- end
6
+ ActionController::Renderers.add :pdf do |_filename, options|
7
+ Postdoc.render_from_string render_to_string(options), options
10
8
  end
11
9
 
12
- ActionController::Renderers.add :pdf do |filename, options|
13
- htmlfile = Tempfile.new ['input', '.html']
10
+ def self.render_from_string(string, options)
11
+ htmlfile = Tempfile.new ['input', '.html'], Rails.root.join('tmp')
14
12
 
15
- htmlfile.write render_to_string(options)
13
+ htmlfile.write string
16
14
  htmlfile.flush
17
15
 
18
- # random port at 1025 or higher
19
- random_port = 1024 + Random.rand(65535 - 1024)
20
-
21
- pid = Process.spawn "chrome --remote-debugging-port=#{random_port} --headless"
22
-
23
- # FIXME
24
- sleep 1
16
+ if options[:client].nil?
17
+ # random port at 1025 or higher
18
+ random_port = 1024 + Random.rand(65_535 - 1024)
19
+ pid = Process.spawn "chrome --remote-debugging-port=#{random_port} --headless"
20
+ end
21
+
22
+ success = false
23
+ 10.times do
24
+ begin
25
+ TCPSocket.new('localhost', random_port)
26
+ success = true
27
+ break
28
+ rescue
29
+ end
30
+ sleep 1
31
+ end
32
+
33
+ return unless success
25
34
 
26
35
  begin
27
- chrome = ChromeRemote.client port: random_port
28
- chrome.send_cmd 'Page.enable'
36
+ chrome = options[:client].nil? ? ChromeRemote.client(port: random_port) : options[:client]
29
37
 
38
+ chrome.send_cmd 'Page.enable'
30
39
  chrome.send_cmd 'Page.navigate', url: "file://#{htmlfile.path}"
31
40
  chrome.wait_for 'Page.loadEventFired'
32
41
 
@@ -42,13 +51,17 @@ module Postdoc
42
51
  marginTop: options[:margin_top] || 1,
43
52
  marginBottom: options[:margin_bottom] || 1,
44
53
  displayHeaderFooter: displayHeaderFooter,
45
- headerTemplate: options[:header_template],
46
- footerTemplate: options[:footer_template]
54
+ headerTemplate: options[:header_template] || '',
55
+ footerTemplate: options[:footer_template] || ''
47
56
  }
48
57
  result = Base64.decode64 response['data']
49
58
  ensure
50
- Process.kill 'KILL', pid
51
- Process.wait pid
59
+ if options[:client].nil?
60
+ Process.kill 'KILL', pid
61
+ Process.wait pid
62
+ else
63
+ chrome.send_cmd 'Page.close'
64
+ end
52
65
 
53
66
  htmlfile.close
54
67
  htmlfile.unlink
metadata CHANGED
@@ -1,49 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Groeneveld
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-06 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: chrome_remote
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '6.1'
19
+ version: 0.2.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 4.0.0
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '6.1'
26
+ version: 0.2.0
33
27
  - !ruby/object:Gem::Dependency
34
- name: chrome_remote
28
+ name: rails
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - ">="
38
32
  - !ruby/object:Gem::Version
39
- version: 0.2.0
33
+ version: 4.0.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '6.1'
40
37
  type: :runtime
41
38
  prerelease: false
42
39
  version_requirements: !ruby/object:Gem::Requirement
43
40
  requirements:
44
41
  - - ">="
45
42
  - !ruby/object:Gem::Version
46
- version: 0.2.0
43
+ version: 4.0.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '6.1'
47
47
  description: Description of Postdoc.
48
48
  email:
49
49
  - frank@ivaldi.nl
@@ -54,12 +54,11 @@ files:
54
54
  - LICENSE
55
55
  - Rakefile
56
56
  - lib/postdoc.rb
57
- - lib/postdoc/postdoc_view_helper.rb
58
57
  homepage: https://github.com/ivaldi/postdoc
59
58
  licenses:
60
59
  - BSD-2-Clause
61
60
  metadata: {}
62
- post_install_message:
61
+ post_install_message:
63
62
  rdoc_options: []
64
63
  require_paths:
65
64
  - lib
@@ -74,8 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
73
  - !ruby/object:Gem::Version
75
74
  version: '0'
76
75
  requirements: []
77
- rubygems_version: 3.0.3
78
- signing_key:
76
+ rubygems_version: 3.1.4
77
+ signing_key:
79
78
  specification_version: 4
80
79
  summary: Summary of Postdoc.
81
80
  test_files: []
@@ -1,23 +0,0 @@
1
- module PostdocViewHelper
2
- def postdoc_stylesheet_link_tag(path)
3
- content_tag :style, read_asset(path), type: 'text/css'
4
- end
5
-
6
- def postdoc_javascript_include_tag(path)
7
- content_tag :script, read_asset(path), type: 'text/javascript'
8
- end
9
-
10
- def postdoc_image_tag(path, options = {})
11
- image_tag asset_path(path), options
12
- end
13
-
14
- protected
15
-
16
- def read_asset(path)
17
- Rails.application.assets.find_asset(path).to_s.html_safe
18
- end
19
-
20
- def asset_path(path)
21
- Rails.application.assets.find_asset(path).filename
22
- end
23
- end