Class: PdfGeneration

Inherits:
Object
  • Object
show all
Defined in:
app/concerns/pdf_generation.rb

Constant Summary collapse

PDF_POST_URL =
"http://quick-pdf.geminisbs.net/pdfs.json"
PDF_GET_URL =
"http://quick-pdf.geminisbs.net/pdfs/:id.json?api_key=:key"
PDF_DOWNLOAD_URL =
"http://quick-pdf.geminisbs.net/pdfs/:id/download?api_key=:key"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdfable, pdf_api_key = PDF_API_KEY, http_party = HTTParty, sleeper = Kernel) ⇒ PdfGeneration

Returns a new instance of PdfGeneration.



11
12
13
14
15
16
17
# File 'app/concerns/pdf_generation.rb', line 11

def initialize(pdfable, pdf_api_key = PDF_API_KEY, http_party = HTTParty, sleeper = Kernel)
  @pdfable      = pdfable
  @pdf_api_key  = pdf_api_key
  @http_party   = http_party
  @sleeper      = sleeper
  @pdf_options  = {}
end

Instance Attribute Details

#pdf_optionsObject

Returns the value of attribute pdf_options.



9
10
11
# File 'app/concerns/pdf_generation.rb', line 9

def pdf_options
  @pdf_options
end

Instance Method Details

#contentObject



23
24
25
26
27
28
29
30
31
# File 'app/concerns/pdf_generation.rb', line 23

def content
  file_name   = pdfable.class.name.underscore
  file_name   = 'order' if file_name.ends_with?('order')
  template    = File.read("#{ArtfullyOse::Engine.root}/app/views/pdfs/#{file_name}.html.haml")
  haml_engine = Haml::Engine.new(template)
  scope       = Object.new.extend(ArtfullyOseHelper)
  output      = haml_engine.render(scope, {:pdfable => pdfable})
  output.gsub("'","\'") # necessary to escape single '
end

#generateObject



19
20
21
# File 'app/concerns/pdf_generation.rb', line 19

def generate
  Wisepdf::Writer.new.to_pdf(content)
end