Skip to content

Commit

Permalink
make calls to controller explicit in renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
adzap committed Apr 2, 2019
1 parent 78197e8 commit ab86fb9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/wicked_pdf/pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def self.prepended(base)
base.send :prepend, Prependable
end
end
end
end
2 changes: 1 addition & 1 deletion lib/wicked_pdf/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ class WickedRailtie < Rails::Railtie
end

end
end
end
12 changes: 5 additions & 7 deletions lib/wicked_pdf/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ class WickedPdf
class Renderer
attr_reader :controller

delegate :request, :send_data, :controller_path, :action_name, :to => :controller

def initialize(controller)
@controller = controller
@hf_tempfiles = []
Expand All @@ -24,8 +22,8 @@ def render_to_string(options)

def set_basic_auth(options = {})
options[:basic_auth] ||= WickedPdf.config.fetch(:basic_auth) { false }
return unless options[:basic_auth] && request.env['HTTP_AUTHORIZATION']
request.env['HTTP_AUTHORIZATION'].split(' ').last
return unless options[:basic_auth] && controller.request.env['HTTP_AUTHORIZATION']
controller.request.env['HTTP_AUTHORIZATION'].split(' ').last
end

def make_pdf(options = {})
Expand All @@ -51,7 +49,7 @@ def make_pdf(options = {})
def make_and_send_pdf(pdf_name, options = {})
options[:wkhtmltopdf] ||= nil
options[:layout] ||= false
options[:template] ||= File.join(controller_path, action_name)
options[:template] ||= File.join(controller.controller_path, controller.action_name)
options[:disposition] ||= 'inline'
if options[:show_as_html]
render_opts = {
Expand All @@ -66,11 +64,11 @@ def make_and_send_pdf(pdf_name, options = {})
render_opts[:inline] = options[:inline] if options[:inline]
render_opts[:locals] = options[:locals] if options[:locals]
render_opts[:file] = options[:file] if options[:file]
render(render_opts)
controller.render(render_opts)
else
pdf_content = make_pdf(options)
File.open(options[:save_to_file], 'wb') { |file| file << pdf_content } if options[:save_to_file]
send_data(pdf_content, :filename => pdf_name + '.pdf', :type => 'application/pdf', :disposition => options[:disposition]) unless options[:save_only]
controller.send_data(pdf_content, :filename => pdf_name + '.pdf', :type => 'application/pdf', :disposition => options[:disposition]) unless options[:save_only]
end
end

Expand Down

0 comments on commit ab86fb9

Please sign in to comment.