Module: PdfHelper

Defined in:
lib/wicked_pdf/pdf_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/wicked_pdf/pdf_helper.rb', line 5

def self.included(base)
  # Protect from trying to augment modules that appear
  # as the result of adding other gems.
  return if base != ActionController::Base

  base.class_eval do
    alias_method_chain :render, :wicked_pdf
    alias_method_chain :render_to_string, :wicked_pdf
    after_filter :clean_temp_files
  end
end

Instance Method Details

#render_to_string_with_wicked_pdf(options = nil, *args, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/wicked_pdf/pdf_helper.rb', line 27

def render_to_string_with_wicked_pdf(options = nil, *args, &block)
  if options.is_a?(Hash) && options.key?(:pdf)
    log_pdf_creation
    options[:basic_auth] = set_basic_auth(options)
    options.delete :pdf
    make_pdf((WickedPdf.config || {}).merge(options))
  else
    render_to_string_without_wicked_pdf(options, *args, &block)
  end
end

#render_with_wicked_pdf(options = nil, *args, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/wicked_pdf/pdf_helper.rb', line 17

def render_with_wicked_pdf(options = nil, *args, &block)
  if options.is_a?(Hash) && options.key?(:pdf)
    log_pdf_creation
    options[:basic_auth] = set_basic_auth(options)
    make_and_send_pdf(options.delete(:pdf), (WickedPdf.config || {}).merge(options))
  else
    render_without_wicked_pdf(options, *args, &block)
  end
end