postdoc 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 16293d8bee567155f1875abf1407092a8528c246
4
- data.tar.gz: 8b451eb22ed1b26896bc8c9bfefb2dd97ef7fb9a
3
+ metadata.gz: 944ae31b2755ea2d043d1e746cfdf894d1737114
4
+ data.tar.gz: d2e0b560a5135a8b48e835ef9ec8e9a8697b17d5
5
5
  SHA512:
6
- metadata.gz: 5c945742d407ce5098497ab36b9757babd34f990f568586b8422ef6f8081c5e9f6308309f9ee4bbec302f56dc4d72217f749ab0862886cefe9b90c34165aac36
7
- data.tar.gz: 713d0f5d7e7a3df12eced0450c4de9e7c5f70a8deaf1a0ce7c04f3a3f0360f26a7fcc310365201afb7aaf4163dc9b311eca5b2cc5aeead611c8405389ff9be1c
6
+ metadata.gz: 163b9b4afb2a3cad61dae197040d1e4b99b8d7e82e0fc5f488e13254e9049b4da3b5db47ac64e37ceb08be2255815cc3c9fc8387c8c1a56a1a3ae1c29a96706a
7
+ data.tar.gz: 30ca29c3e20ad3d0ca550f4292c936ded744da1fbab399b1678cc75ba95af015e8177347e4cd5440995f41c566c6ed6537b57650ae7f256632dce2ec4fd1c9ae
@@ -0,0 +1,4 @@
1
+ @page{
2
+ margin: 0; /* disable default header/footer texts */
3
+ size: 'A4'; /* override default US letter size */
4
+ }
@@ -0,0 +1,22 @@
1
+ module PostdocViewHelper
2
+ # outputs style tag with default styling such as A4 paper format
3
+ def postdoc_default_stylesheet_link_tag
4
+ content_tag :style,
5
+ File.read(postdoc_gem_asset('stylesheets', 'default.css')).html_safe,
6
+ type: 'text/css'
7
+ end
8
+
9
+ def postdoc_stylesheet_link_tag(*path)
10
+ content_tag :style, File.read(
11
+ Rails.root.join('app', 'assets', 'stylesheets', *path)
12
+ ).html_safe,
13
+ type: 'text/css'
14
+ end
15
+
16
+ protected
17
+
18
+ # include an assets from the gem app/assets folder
19
+ def postdoc_gem_asset(*path)
20
+ File.join(File.dirname(__FILE__), '..', '..', 'app', 'assets', *path)
21
+ end
22
+ end
data/lib/postdoc.rb CHANGED
@@ -1,3 +1,34 @@
1
+ require 'postdoc/postdoc_view_helper'
2
+
1
3
  module Postdoc
2
- # Your code goes here...
4
+
5
+ class PostdocRailtie < Rails::Railtie
6
+ initializer 'postdoc.register' do |_app|
7
+ ActionView::Base.send :include, PostdocViewHelper
8
+ end
9
+ end
10
+
11
+ ActionController::Renderers.add :pdf do |filename, options|
12
+ pdffile = Tempfile.new(['output', '.pdf'])
13
+ htmlfile = Tempfile.new(['input', '.html'])
14
+
15
+ htmlfile.write(render_to_string(options))
16
+ htmlfile.flush
17
+
18
+ if options[:debug]
19
+ `chrome file://#{htmlfile.path}`
20
+ end
21
+
22
+ `chrome --headless --disable-gpu --print-to-pdf=#{pdffile.path} file://#{htmlfile.path}`
23
+
24
+ htmlfile.close
25
+ htmlfile.unlink
26
+
27
+ result = pdffile.read
28
+
29
+ pdffile.unlink
30
+ pdffile.close
31
+
32
+ result
33
+ end
3
34
  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.1.1
4
+ version: 0.1.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: 2017-11-17 00:00:00.000000000 Z
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,8 +39,9 @@ extra_rdoc_files: []
39
39
  files:
40
40
  - LICENSE
41
41
  - Rakefile
42
+ - app/assets/stylesheets/default.css
42
43
  - lib/postdoc.rb
43
- - lib/tasks/postdoc_tasks.rake
44
+ - lib/postdoc/postdoc_view_helper.rb
44
45
  homepage: https://github.com/ivaldi/postdoc
45
46
  licenses:
46
47
  - BSD-2-Clause
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :postdoc do
3
- # # Task goes here
4
- # end