Class: Crayfish::Rails::PDF

Inherits:
Object
  • Object
show all
Defined in:
lib/crayfish/rails/pdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ PDF

Returns a new instance of PDF.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/crayfish/rails/pdf.rb', line 30

def initialize(controller)
  controller_options = controller ? controller.send(:options) || {} : {}
  @options = Crayfish::ActionController.options.merge(Hash[*controller_options.map{ |k,v| [k.to_sym,v] }.flatten])

  if controller
    if options[:html]
      controller.response.content_type ||= Mime::HTML
    else
      controller.response.content_type ||= Mime::PDF
    end
  end

  inline = options[:inline] ? 'inline' : 'attachment'
  filename = options[:filename] ? "filename=#{options[:filename]}" : nil
  controller.headers["Content-Disposition"] = [inline,filename].compact.join(';') if controller
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



28
29
30
# File 'lib/crayfish/rails/pdf.rb', line 28

def options
  @options
end