Module: GTK::ControllersHelper

Defined in:
lib/gtk_webkit_pdf/gtk_controllers_helper_pdf.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/gtk_webkit_pdf/gtk_controllers_helper_pdf.rb', line 3

def self.included(base)
  return if base != ActionController::Base

  base.class_eval do
    alias_method_chain :render, :gtk_webkit_pdf
  end
end

Instance Method Details

#make_and_send_pdf(pdf_name = nil, options = {}) ⇒ Object



19
20
21
22
23
# File 'lib/gtk_webkit_pdf/gtk_controllers_helper_pdf.rb', line 19

def make_and_send_pdf(pdf_name = nil, options = {})
  html_string = render_to_string(options)
  gtk_printer = GTK::Webkit.new(html_string, 0).gtk_printer
  send_data(gtk_printer.pdf_content, :file_name => pdf_name+'.pdf', :type => 'application/pdf', :disposition => options[:disposition])
end

#render_with_gtk_webkit_pdf(options = {}, *args, &block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/gtk_webkit_pdf/gtk_controllers_helper_pdf.rb', line 11

def render_with_gtk_webkit_pdf(options = {}, *args, &block)
  if options.is_a?(Hash) && options.has_key?(:pdf)
    make_and_send_pdf(options.delete(:pdf), render_options(options))
  else
    render_without_gtk_webkit_pdf(options, *args, &block)
  end
end