Module: Icanhazpdf::Controller::Renderer
- Defined in:
- lib/icanhazpdf/controller.rb
Overview
include in a controller and use to render pdfs or authenticate requests are from icanhazpf
Instance Method Summary collapse
-
#render_pdf_from(url, options = {}) ⇒ Object
generate and render a pdf from a url.
-
#render_response_for(pdf_response, options = {}) ⇒ Object
send the pdf to the user if its a valid file optionally pass the filename in the options hash raises an exception if something went wrong.
Instance Method Details
#render_pdf_from(url, options = {}) ⇒ Object
generate and render a pdf from a url
12 13 14 15 |
# File 'lib/icanhazpdf/controller.rb', line 12 def render_pdf_from(url, = {}) .slice!(:filename, :use_wkhtmltopdf, :margin, :landscape) render_response_for Icanhazpdf::Client.new.pdf_from_url(url, ), end |
#render_response_for(pdf_response, options = {}) ⇒ Object
send the pdf to the user if its a valid file optionally pass the filename in the options hash raises an exception if something went wrong
20 21 22 23 24 25 |
# File 'lib/icanhazpdf/controller.rb', line 20 def render_response_for(pdf_response, = {}) raise "Failed to generate pdf:\nCode: #{pdf_response.code}\nBody:\n#{pdf_response.body}" unless pdf_response.code == 200 filename = .has_key?(:filename) ? [:filename] : "#{DateTime.now.to_formatted_s(:number)}-icanhaz.pdf" send_data pdf_response, :filename => filename, :type => :pdf end |