module Wisepdf::Render
Public Class Methods
included(base)
click to toggle source
# File lib/wisepdf/render.rb, line 5 def self.included(base) base.class_eval do alias_method_chain :render, :wisepdf alias_method_chain :render_to_string, :wisepdf after_filter :clean_temp_files end end
Public Instance Methods
render_to_string_with_wisepdf(options = nil, *args, &block)
click to toggle source
# File lib/wisepdf/render.rb, line 25 def render_to_string_with_wisepdf(options = nil, *args, &block) if options.is_a?(Hash) && options.has_key?(:pdf) self.log_pdf_creation self.make_pdf(self.default_pdf_render_options.merge(options)) else render_to_string_without_wisepdf(options, *args, &block) end end
render_with_wisepdf(options = nil, *args, &block)
click to toggle source
# File lib/wisepdf/render.rb, line 13 def render_with_wisepdf(options = nil, *args, &block) if options.is_a?(Hash) && options.has_key?(:pdf) options = self.default_pdf_render_options.merge(options) render_without_wisepdf(options.merge(:content_type => "text/html"), *args, &block) and return if options[:show_as_html] self.log_pdf_creation self.make_and_send_pdf(options) else render_without_wisepdf(options, *args, &block) end end
Protected Instance Methods
clean_temp_files()
click to toggle source
# File lib/wisepdf/render.rb, line 40 def clean_temp_files if defined?(@hf_tempfiles) @hf_tempfiles.each { |tf| tf.close! } end end
default_pdf_render_options()
click to toggle source
# File lib/wisepdf/render.rb, line 46 def default_pdf_render_options { :wkhtmltopdf => nil, :layout => false, :template => "#{controller_path}/#{action_name}", :disposition => "inline" }.merge(Wisepdf::Configuration.options) end
log_pdf_creation()
click to toggle source
# File lib/wisepdf/render.rb, line 36 def log_pdf_creation logger.info '*'*15 + 'WISEPDF' + '*'*15 end
make_and_send_pdf(options = {})
click to toggle source
# File lib/wisepdf/render.rb, line 61 def make_and_send_pdf(options = {}) pdf = self.make_pdf(options) File.open(options[:save_to_file], 'wb') {|file| file << pdf } if options[:save_to_file].present? filename = options.delete(:pdf) filename += '.pdf' unless filename =~ /.pdf\z|.PDF\Z/ send_data(pdf, options.merge(:filename => filename, :type => 'application/pdf')) unless options[:save_only] end
make_pdf(options = {})
click to toggle source
# File lib/wisepdf/render.rb, line 55 def make_pdf(options = {}) options = self.prerender_header_and_footer(options) html = render_to_string(:template => options[:template], :layout => options[:layout]) Wisepdf::Writer.new(options[:wkhtmltopdf], options.dup).to_pdf(html) end