From ab86fb94ea97303c32246be51bb918de1b8cd53d Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Tue, 2 Apr 2019 16:09:41 +1100 Subject: [PATCH] make calls to controller explicit in renderer --- lib/wicked_pdf/pdf_helper.rb | 2 +- lib/wicked_pdf/railtie.rb | 2 +- lib/wicked_pdf/renderer.rb | 12 +++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/wicked_pdf/pdf_helper.rb b/lib/wicked_pdf/pdf_helper.rb index db2ad57d..12b8f580 100644 --- a/lib/wicked_pdf/pdf_helper.rb +++ b/lib/wicked_pdf/pdf_helper.rb @@ -53,4 +53,4 @@ def self.prepended(base) base.send :prepend, Prependable end end -end \ No newline at end of file +end diff --git a/lib/wicked_pdf/railtie.rb b/lib/wicked_pdf/railtie.rb index 5175ef91..c2f5c2ab 100644 --- a/lib/wicked_pdf/railtie.rb +++ b/lib/wicked_pdf/railtie.rb @@ -47,4 +47,4 @@ class WickedRailtie < Rails::Railtie end end -end \ No newline at end of file +end diff --git a/lib/wicked_pdf/renderer.rb b/lib/wicked_pdf/renderer.rb index 62889661..4a2e86ec 100644 --- a/lib/wicked_pdf/renderer.rb +++ b/lib/wicked_pdf/renderer.rb @@ -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 = [] @@ -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 = {}) @@ -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 = { @@ -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