Module: WickedPdf::PdfHelper

Defined in:
lib/wicked_pdf/pdf_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/wicked_pdf/pdf_helper.rb', line 3

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(*args) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/wicked_pdf/pdf_helper.rb', line 13

def render(*args)
  options = args.first
  if options.is_a?(Hash) && options.key?(:pdf)
    render_with_wicked_pdf(options)
  else
    super
  end
end

#render_to_string(*args) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/wicked_pdf/pdf_helper.rb', line 22

def render_to_string(*args)
  options = args.first
  if options.is_a?(Hash) && options.key?(:pdf)
    render_to_string_with_wicked_pdf(options)
  else
    super
  end
end

#render_to_string_with_wicked_pdf(options) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
# File 'lib/wicked_pdf/pdf_helper.rb', line 38

def render_to_string_with_wicked_pdf(options)
  raise ArgumentError, 'missing keyword: pdf' unless options.is_a?(Hash) && options.key?(:pdf)

  options[:basic_auth] = set_basic_auth(options)
  options.delete :pdf
  make_pdf((WickedPdf.config || {}).merge(options))
end

#render_with_wicked_pdf(options) ⇒ Object

Raises:

  • (ArgumentError)


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

def render_with_wicked_pdf(options)
  raise ArgumentError, 'missing keyword: pdf' unless 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))
end