module PuppetPdf::Helpers::Controller
Public Instance Methods
render_pdf(args = {})
click to toggle source
# File lib/puppet_pdf/helpers/controller.rb, line 4 def render_pdf(args = {}) html = render_to_string(render_params(args)) html_path = create_file_and_get_path(html) options = args.slice(:header, :footer, :margins, :loading_delay) file_path = ::PuppetPdf::PdfCreator.new(html_path, options).call send_file(file_path, filename: args.fetch(:filename, "#{action_name}.pdf"), disposition: :inline) end
Private Instance Methods
create_file_and_get_path(content)
click to toggle source
# File lib/puppet_pdf/helpers/controller.rb, line 30 def create_file_and_get_path(content) file = Tempfile.new(Time.now.to_i.to_s) file_path = file.path file.write(content) file.close file_path end
default_template()
click to toggle source
# File lib/puppet_pdf/helpers/controller.rb, line 26 def default_template File.join(controller_path, action_name) end
render_params(params)
click to toggle source
# File lib/puppet_pdf/helpers/controller.rb, line 18 def render_params(params) { template: params.fetch(:template, default_template), layout: params.fetch(:layout, 'application'), locals: params.fetch(:locals, {}) } end