adzap-wicked_pdf 2.0.0.beta2 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +0 -2
- data/lib/wicked_pdf/renderer.rb +12 -43
- data/lib/wicked_pdf/version.rb +1 -1
- data/test/test_helper.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9e90952154e4de99f48f07c05cc15650674e368f77471d6f6211952a73e3731
|
4
|
+
data.tar.gz: 6e9d65e47ae12a3dd7eed5daa3feca137579c2821d647ee18695fcb021ebf0f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 455ec689af1b87ac63c04625684a508f998c73e0814127849723f5d0e51e357f88194ecdf12e979ec1aa86deeb115857ec8eadcf0d3cf8d9d12a0f838e6cc21d
|
7
|
+
data.tar.gz: cbf22b211f946ff1b46d25230ec6601a229ddd8985aff353fb9195db72e6acf33a52db0345c1745d92288ee7f371630a14fc1189f72ea40c25fe734508b7297a
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/wicked_pdf/renderer.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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)
|
data/lib/wicked_pdf/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
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.
|
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-
|
13
|
+
date: 2019-04-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|