Class: Markover::Wkhtmltopdf
- Inherits:
-
Object
- Object
- Markover::Wkhtmltopdf
- Defined in:
- lib/markover/wkhtmltopdf.rb
Overview
The class that communicates with wkhtmltopdf
Instance Method Summary collapse
-
#bin ⇒ String
Find the wkhtmltopdf binary.
-
#command(filename) ⇒ Array
Assemble the command to run.
-
#initialize(parameters = nil) ⇒ Wkhtmltopdf
constructor
Set up options for wkhtmltopdf.
-
#output_pdf(html, filename) ⇒ Object
Convert the html to pdf and write it to file.
Constructor Details
#initialize(parameters = nil) ⇒ Wkhtmltopdf
Set up options for wkhtmltopdf
8 9 10 |
# File 'lib/markover/wkhtmltopdf.rb', line 8 def initialize(parameters = nil) @parameters = parameters end |
Instance Method Details
#bin ⇒ String
Find the wkhtmltopdf binary
35 36 37 |
# File 'lib/markover/wkhtmltopdf.rb', line 35 def bin @bin ||= "\"#{(`which wkhtmltopdf`).chomp}\"" end |
#command(filename) ⇒ Array
Assemble the command to run
29 30 31 |
# File 'lib/markover/wkhtmltopdf.rb', line 29 def command(filename) [bin, @parameters, '--quiet', '-', "\"#{filename}\""].compact end |
#output_pdf(html, filename) ⇒ Object
Convert the html to pdf and write it to file
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/markover/wkhtmltopdf.rb', line 15 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 |