Skip to content

Commit 1edb3b8

Browse files
committed
Merge branch 'code/old-code' of https://github.com/fsateler/wicked_pdf into fsateler-code/old-code
2 parents 878302f + 6d46c0b commit 1edb3b8

File tree

2 files changed

+24
-47
lines changed

2 files changed

+24
-47
lines changed

lib/wicked_pdf/pdf_helper.rb

+23-41
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
class WickedPdf
22
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-
193
def self.prepended(base)
204
# Protect from trying to augment modules that appear
215
# as the result of adding other gems.
@@ -26,41 +10,39 @@ def self.prepended(base)
2610
end
2711
end
2812

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
3815
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)
4417
else
45-
# support inheritance (module prepended)
46-
method(:render).super_method.call(options, *args, &block)
18+
super
4719
end
4820
end
4921

50-
def render_to_string_with_wicked_pdf(options = nil, *args, &block)
22+
def render_to_string(*args)
23+
options = args.first
5124
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)
5826
else
59-
# support inheritance (module prepended)
60-
method(:render_to_string).super_method.call(options, *args, &block)
27+
super
6128
end
6229
end
6330

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+
6446
private
6547

6648
def set_basic_auth(options = {})

lib/wicked_pdf/railtie.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ class WickedPdf
77
class WickedRailtie < Rails::Railtie
88
initializer 'wicked_pdf.register', :after => 'remotipart.controller_helper' do |_app|
99
ActiveSupport.on_load(:action_controller) do
10-
if ActionController::Base.respond_to?(:prepend) &&
11-
Object.method(:new).respond_to?(:super_method)
12-
ActionController::Base.send :prepend, PdfHelper
13-
else
14-
ActionController::Base.send :include, PdfHelper
15-
end
10+
ActionController::Base.send :prepend, PdfHelper
1611
ActionView::Base.send :include, WickedPdfHelper::Assets
1712
end
1813
end

0 commit comments

Comments
 (0)