Skip to content

Commit

Permalink
Merge branch 'code/old-code' of https://github.com/fsateler/wicked_pdf
Browse files Browse the repository at this point in the history
…into fsateler-code/old-code
  • Loading branch information
unixmonkey committed Nov 13, 2020
2 parents 878302f + 6d46c0b commit 1edb3b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 47 deletions.
64 changes: 23 additions & 41 deletions lib/wicked_pdf/pdf_helper.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
class WickedPdf
module PdfHelper
def self.included(base)
# Protect from trying to augment modules that appear
# as the result of adding other gems.
return if base != ActionController::Base

base.class_eval do
alias_method_chain :render, :wicked_pdf
alias_method_chain :render_to_string, :wicked_pdf
if respond_to?(:after_action)
after_action :clean_temp_files
else
after_filter :clean_temp_files
end
end
end

def self.prepended(base)
# Protect from trying to augment modules that appear
# as the result of adding other gems.
Expand All @@ -26,41 +10,39 @@ def self.prepended(base)
end
end

def render(options = nil, *args, &block)
render_with_wicked_pdf(options, *args, &block)
end

def render_to_string(options = nil, *args, &block)
render_to_string_with_wicked_pdf(options, *args, &block)
end

def render_with_wicked_pdf(options = nil, *args, &block)
def render(*args)
options = args.first
if options.is_a?(Hash) && options.key?(:pdf)
options[:basic_auth] = set_basic_auth(options)
make_and_send_pdf(options.delete(:pdf), (WickedPdf.config || {}).merge(options))
elsif respond_to?(:render_without_wicked_pdf)
# support alias_method_chain (module included)
render_without_wicked_pdf(options, *args, &block)
render_with_wicked_pdf(options)
else
# support inheritance (module prepended)
method(:render).super_method.call(options, *args, &block)
super
end
end

def render_to_string_with_wicked_pdf(options = nil, *args, &block)
def render_to_string(*args)
options = args.first
if options.is_a?(Hash) && options.key?(:pdf)
options[:basic_auth] = set_basic_auth(options)
options.delete :pdf
make_pdf((WickedPdf.config || {}).merge(options))
elsif respond_to?(:render_to_string_without_wicked_pdf)
# support alias_method_chain (module included)
render_to_string_without_wicked_pdf(options, *args, &block)
render_to_string_with_wicked_pdf(options, *args, &block)
else
# support inheritance (module prepended)
method(:render_to_string).super_method.call(options, *args, &block)
super
end
end

def render_with_wicked_pdf(options)
raise ArgumentError, 'missing keyword: pdf' unless options.is_a?(Hash) && options.key?(:pdf)

options[:basic_auth] = set_basic_auth(options)
make_and_send_pdf(options.delete(:pdf), (WickedPdf.config || {}).merge(options))
end

def render_to_string_with_wicked_pdf(options)
raise ArgumentError, 'missing keyword: pdf' unless options.is_a?(Hash) && options.key?(:pdf)

options[:basic_auth] = set_basic_auth(options)
options.delete :pdf
make_pdf((WickedPdf.config || {}).merge(options))
end

private

def set_basic_auth(options = {})
Expand Down
7 changes: 1 addition & 6 deletions lib/wicked_pdf/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ class WickedPdf
class WickedRailtie < Rails::Railtie
initializer 'wicked_pdf.register', :after => 'remotipart.controller_helper' do |_app|
ActiveSupport.on_load(:action_controller) do
if ActionController::Base.respond_to?(:prepend) &&
Object.method(:new).respond_to?(:super_method)
ActionController::Base.send :prepend, PdfHelper
else
ActionController::Base.send :include, PdfHelper
end
ActionController::Base.send :prepend, PdfHelper
ActionView::Base.send :include, WickedPdfHelper::Assets
end
end
Expand Down

0 comments on commit 1edb3b8

Please sign in to comment.