class Wisepdf::Writer
Public Class Methods
new(wkhtmltopdf = nil, options = {})
click to toggle source
# File lib/wisepdf/writer.rb, line 3 def initialize(wkhtmltopdf = nil, options = {}) self.wkhtmltopdf = wkhtmltopdf unless wkhtmltopdf.nil? self.options = options end
Public Instance Methods
options()
click to toggle source
# File lib/wisepdf/writer.rb, line 32 def options @options ||= Wisepdf::Parser.parse(Wisepdf::Configuration.options.dup) @options end
options=(value)
click to toggle source
# File lib/wisepdf/writer.rb, line 37 def options=(value) self.options.merge!(Wisepdf::Parser.parse(value)) end
to_pdf(string, options={})
click to toggle source
# File lib/wisepdf/writer.rb, line 8 def to_pdf(string, options={}) invoke = self.command(options).join(' ') self.log(invoke) unless Wisepdf::Configuration.production? result = IO.popen(invoke, "wb+") do |pdf| pdf.puts(string) pdf.close_write pdf.gets(nil) end raise Wisepdf::WriteError if result.to_s.strip.empty? return result end
wkhtmltopdf()
click to toggle source
# File lib/wisepdf/writer.rb, line 23 def wkhtmltopdf @wkhtmltopdf || self.wkhtmltopdf = Wisepdf::Configuration.wkhtmltopdf end
wkhtmltopdf=(value)
click to toggle source
# File lib/wisepdf/writer.rb, line 27 def wkhtmltopdf=(value) raise Wisepdf::NoExecutableError.new(value) if value.blank? || !File.exists?(value) @wkhtmltopdf = value end
Protected Instance Methods
command(options = {})
click to toggle source
# File lib/wisepdf/writer.rb, line 43 def command(options = {}) options = Wisepdf::Parser.parse(options) args = [self.wkhtmltopdf] args += self.options.merge(options).to_a.flatten.compact args << '--quiet' args << '-' args << '-' args.map {|arg| %Q{"#{arg.gsub('"', '\"')}"}} end
log(command)
click to toggle source
# File lib/wisepdf/writer.rb, line 56 def log(command) puts "*"*15 puts command puts "*"*15 end