1
1
class WickedPdf
2
2
module PdfHelper
3
- def self . included ( base )
4
- # Protect from trying to augment modules that appear
5
- # as the result of adding other gems.
6
- return if base != ActionController ::Base
7
-
8
- base . class_eval do
9
- alias_method_chain :render , :wicked_pdf
10
- alias_method_chain :render_to_string , :wicked_pdf
11
- if respond_to? ( :after_action )
12
- after_action :clean_temp_files
13
- else
14
- after_filter :clean_temp_files
15
- end
16
- end
17
- end
18
-
19
3
def self . prepended ( base )
20
4
# Protect from trying to augment modules that appear
21
5
# as the result of adding other gems.
@@ -26,41 +10,39 @@ def self.prepended(base)
26
10
end
27
11
end
28
12
29
- def render ( options = nil , *args , &block )
30
- render_with_wicked_pdf ( options , *args , &block )
31
- end
32
-
33
- def render_to_string ( options = nil , *args , &block )
34
- render_to_string_with_wicked_pdf ( options , *args , &block )
35
- end
36
-
37
- def render_with_wicked_pdf ( options = nil , *args , &block )
13
+ def render ( *args )
14
+ options = args . first
38
15
if options . is_a? ( Hash ) && options . key? ( :pdf )
39
- options [ :basic_auth ] = set_basic_auth ( options )
40
- make_and_send_pdf ( options . delete ( :pdf ) , ( WickedPdf . config || { } ) . merge ( options ) )
41
- elsif respond_to? ( :render_without_wicked_pdf )
42
- # support alias_method_chain (module included)
43
- render_without_wicked_pdf ( options , *args , &block )
16
+ render_with_wicked_pdf ( options )
44
17
else
45
- # support inheritance (module prepended)
46
- method ( :render ) . super_method . call ( options , *args , &block )
18
+ super
47
19
end
48
20
end
49
21
50
- def render_to_string_with_wicked_pdf ( options = nil , *args , &block )
22
+ def render_to_string ( *args )
23
+ options = args . first
51
24
if options . is_a? ( Hash ) && options . key? ( :pdf )
52
- options [ :basic_auth ] = set_basic_auth ( options )
53
- options . delete :pdf
54
- make_pdf ( ( WickedPdf . config || { } ) . merge ( options ) )
55
- elsif respond_to? ( :render_to_string_without_wicked_pdf )
56
- # support alias_method_chain (module included)
57
- render_to_string_without_wicked_pdf ( options , *args , &block )
25
+ render_to_string_with_wicked_pdf ( options , *args , &block )
58
26
else
59
- # support inheritance (module prepended)
60
- method ( :render_to_string ) . super_method . call ( options , *args , &block )
27
+ super
61
28
end
62
29
end
63
30
31
+ def render_with_wicked_pdf ( options )
32
+ raise ArgumentError , 'missing keyword: pdf' unless options . is_a? ( Hash ) && options . key? ( :pdf )
33
+
34
+ options [ :basic_auth ] = set_basic_auth ( options )
35
+ make_and_send_pdf ( options . delete ( :pdf ) , ( WickedPdf . config || { } ) . merge ( options ) )
36
+ end
37
+
38
+ def render_to_string_with_wicked_pdf ( options )
39
+ raise ArgumentError , 'missing keyword: pdf' unless options . is_a? ( Hash ) && options . key? ( :pdf )
40
+
41
+ options [ :basic_auth ] = set_basic_auth ( options )
42
+ options . delete :pdf
43
+ make_pdf ( ( WickedPdf . config || { } ) . merge ( options ) )
44
+ end
45
+
64
46
private
65
47
66
48
def set_basic_auth ( options = { } )
0 commit comments