adzap-wicked_pdf 2.0.0.beta2 → 2.0.0.beta3

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: a4ea1861662d27d078f0687835542b048648b15237258699e266f0ab018fd608
4
- data.tar.gz: 47dc57c0ed8a638a3ab3921ad746248c6c2a72f2ab355b2448f2188ac2718388
3
+ metadata.gz: a9e90952154e4de99f48f07c05cc15650674e368f77471d6f6211952a73e3731
4
+ data.tar.gz: 6e9d65e47ae12a3dd7eed5daa3feca137579c2821d647ee18695fcb021ebf0f4
5
5
  SHA512:
6
- metadata.gz: 2a41b903e2d397afcf0f20fc0b72f5a9fbecf97f3e6f75f974fe0a827fa8f961dd09d9d0a29828c3b5cb3fd30f2c9066016eb9f88c3eb64892c4fa5a4a8606d7
7
- data.tar.gz: 4730471489cd16958963fabacdf9bb25c4509539491c20ec9706ffecb0a678f8b5e8cf34e9aacfafc04ceb2b17ab670039e4558cc3b2639bcca35e2a4f11bbbe
6
+ metadata.gz: 455ec689af1b87ac63c04625684a508f998c73e0814127849723f5d0e51e357f88194ecdf12e979ec1aa86deeb115857ec8eadcf0d3cf8d9d12a0f838e6cc21d
7
+ data.tar.gz: cbf22b211f946ff1b46d25230ec6601a229ddd8985aff353fb9195db72e6acf33a52db0345c1745d92288ee7f371630a14fc1189f72ea40c25fe734508b7297a
data/.gitignore CHANGED
@@ -18,4 +18,4 @@ tmp
18
18
  *.swp
19
19
  gemfiles/*.lock
20
20
  .DS_Store
21
- test/dummy/db/
21
+ test/dummy/db
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'byebug'
4
-
5
3
  gemspec
@@ -2,8 +2,6 @@ module WickedPdf
2
2
  class Renderer
3
3
  attr_reader :controller
4
4
 
5
- delegate :request, :send_data, :controller_path, :action_name, :to => :controller
6
-
7
5
  def initialize(controller)
8
6
  @controller = controller
9
7
  @hf_tempfiles = []
@@ -23,25 +21,13 @@ module WickedPdf
23
21
  private
24
22
 
25
23
  def set_basic_auth(options = {})
26
- options[:basic_auth] ||= WickedPdf.config.fetch(:basic_auth) { false }
27
- return unless options[:basic_auth] && request.env['HTTP_AUTHORIZATION']
28
- request.env['HTTP_AUTHORIZATION'].split(' ').last
24
+ options[:basic_auth] ||= WickedPdf.config.fetch(:basic_auth, false)
25
+ return unless options[:basic_auth] && controller.request.env['HTTP_AUTHORIZATION']
26
+ controller.request.env['HTTP_AUTHORIZATION'].split(' ').last
29
27
  end
30
28
 
31
29
  def make_pdf(options = {})
32
- render_opts = {
33
- :template => options[:template],
34
- :prefixes => options[:prefixes],
35
- :layout => options[:layout],
36
- :formats => options[:formats],
37
- :handlers => options[:handlers],
38
- :assigns => options[:assigns]
39
- }
40
- render_opts[:inline] = options[:inline] if options[:inline]
41
- render_opts[:locals] = options[:locals] if options[:locals]
42
- render_opts[:file] = options[:file] if options[:file]
43
-
44
- html_string = controller.render_to_string(render_opts)
30
+ html_string = controller.render_to_string(render_options(options))
45
31
  options = prerender_header_and_footer(options)
46
32
 
47
33
  document = WickedPdf::Document.new(command(options[:wkhtmltopdf]))
@@ -52,26 +38,14 @@ module WickedPdf
52
38
 
53
39
  def make_and_send_pdf(pdf_name, options = {})
54
40
  options[:layout] ||= false
55
- options[:template] ||= File.join(controller_path, action_name)
41
+ options[:template] ||= File.join(controller.controller_path, controller.action_name)
56
42
  options[:disposition] ||= 'inline'
57
43
  if options[:show_as_html]
58
- render_opts = {
59
- :template => options[:template],
60
- :prefixes => options[:prefixes],
61
- :layout => options[:layout],
62
- :formats => options[:formats],
63
- :handlers => options[:handlers],
64
- :assigns => options[:assigns],
65
- :content_type => 'text/html'
66
- }
67
- render_opts[:inline] = options[:inline] if options[:inline]
68
- render_opts[:locals] = options[:locals] if options[:locals]
69
- render_opts[:file] = options[:file] if options[:file]
70
- render(render_opts)
44
+ controller.render(render_options(options).merge(:content_type => 'text/html'))
71
45
  else
72
46
  pdf_content = make_pdf(options)
73
47
  File.open(options[:save_to_file], 'wb') { |file| file << pdf_content } if options[:save_to_file]
74
- send_data(pdf_content, :filename => pdf_name + '.pdf', :type => 'application/pdf', :disposition => options[:disposition]) unless options[:save_only]
48
+ controller.send_data(pdf_content, :filename => pdf_name + '.pdf', :type => 'application/pdf', :disposition => options[:disposition]) unless options[:save_only]
75
49
  end
76
50
  end
77
51
 
@@ -82,22 +56,17 @@ module WickedPdf
82
56
  next unless options[hf] && options[hf][:html] && options[hf][:html][:template]
83
57
 
84
58
  options[hf][:html][:layout] ||= options[:layout]
85
- render_opts = {
86
- :template => options[hf][:html][:template],
87
- :layout => options[hf][:html][:layout],
88
- :formats => options[hf][:html][:formats],
89
- :handlers => options[hf][:html][:handlers],
90
- :assigns => options[hf][:html][:assigns]
91
- }
92
- render_opts[:locals] = options[hf][:html][:locals] if options[hf][:html][:locals]
93
- render_opts[:file] = options[hf][:html][:file] if options[:file]
94
-
59
+ render_opts = render_options(options[hf][:html])
95
60
  path = render_to_tempfile("wicked_#{hf}_pdf.html", render_opts)
96
61
  options[hf][:html][:url] = "file:///#{path}"
97
62
  end
98
63
  options
99
64
  end
100
65
 
66
+ def render_options(options)
67
+ options.slice(:template, :prefixes, :layout, :formats, :handlers, :assigns, :inline, :locals, :file)
68
+ end
69
+
101
70
  def render_to_tempfile(filename, options)
102
71
  tf = WickedPdf::Tempfile.new(filename)
103
72
  @hf_tempfiles.push(tf)
@@ -1,3 +1,3 @@
1
1
  module WickedPdf
2
- VERSION = '2.0.0.beta2'.freeze
2
+ VERSION = '2.0.0.beta3'.freeze
3
3
  end
@@ -2,7 +2,6 @@
2
2
  ENV['RAILS_ENV'] = 'test'
3
3
 
4
4
  require 'combustion'
5
- require 'byebug'
6
5
 
7
6
  Combustion.path = 'test/dummy'
8
7
  Combustion.initialize!(:all) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adzap-wicked_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta2
4
+ version: 2.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Z. Sterrett
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-03-30 00:00:00.000000000 Z
13
+ date: 2019-04-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport