Module: WickedPdf::PdfHelper

Defined in:
lib/wicked_pdf/pdf_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

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
    if respond_to?(:after_action)
      after_action :clean_temp_files
    else
      after_filter :clean_temp_files
    end
  end
end

.prepended(base) ⇒ Object



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

def self.prepended(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
    after_action :clean_temp_files
  end
end

Instance Method Details

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



29
30
31
# File 'lib/wicked_pdf/pdf_helper.rb', line 29

def render(options = nil, *args, &block)
  render_with_wicked_pdf(options, *args, &block)
end

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



33
34
35
# File 'lib/wicked_pdf/pdf_helper.rb', line 33

def render_to_string(options = nil, *args, &block)
  render_to_string_with_wicked_pdf(options, *args, &block)
end

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



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/wicked_pdf/pdf_helper.rb', line 50

def render_to_string_with_wicked_pdf(options = nil, *args, &block)
  if options.is_a?(Hash) && options.key?(:pdf)
    options[:basic_auth] = set_basic_auth(options)
    options.delete :pdf
    make_pdf((WickedPdf.config || {}).merge(options))
  elsif respond_to?(:render_to_string_without_wicked_pdf)
    # support alias_method_chain (module included)
    render_to_string_without_wicked_pdf(options, *args, &block)
  else
    # support inheritance (module prepended)
    method(:render_to_string).super_method.call(options, *args, &block)
  end
end

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



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wicked_pdf/pdf_helper.rb', line 37

def render_with_wicked_pdf(options = nil, *args, &block)
  if options.is_a?(Hash) && options.key?(:pdf)
    options[:basic_auth] = set_basic_auth(options)
    make_and_send_pdf(options.delete(:pdf), (WickedPdf.config || {}).merge(options))
  elsif respond_to?(:render_without_wicked_pdf)
    # support alias_method_chain (module included)
    render_without_wicked_pdf(options, *args, &block)
  else
    # support inheritance (module prepended)
    method(:render).super_method.call(options, *args, &block)
  end
end