Class: Grandfather::Wkhtmltopdf

Inherits:
Object
  • Object
show all
Defined in:
lib/grandfather/wkhtmltopdf.rb

Instance Method Summary collapse

Constructor Details

#initialize(parameters = nil) ⇒ Wkhtmltopdf

Returns a new instance of Wkhtmltopdf.



4
5
6
# File 'lib/grandfather/wkhtmltopdf.rb', line 4

def initialize(parameters = nil)
  @parameters = parameters
end

Instance Method Details

#binObject



23
24
25
# File 'lib/grandfather/wkhtmltopdf.rb', line 23

def bin
  @bin ||= "\"#{(`which wkhtmltopdf`).chomp}\""
end

#command(filename) ⇒ Object



19
20
21
# File 'lib/grandfather/wkhtmltopdf.rb', line 19

def command(filename)
  [bin, @parameters, '--quiet', '-', "\"#{filename}\""].compact
end

#output_pdf(html, filename) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/grandfather/wkhtmltopdf.rb', line 8

def output_pdf(html, filename)
  args = command(filename)
  invoke = args.join(' ')

  IO.popen(invoke, "wb+") do |pdf|
    pdf.puts(html)
    pdf.close_write
    pdf.gets(nil)
  end
end