Class: Wisepdf::Writer

Inherits:
Object show all
Defined in:
lib/wisepdf/writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(wkhtmltopdf = nil, options = {}) ⇒ Writer

Returns a new instance of Writer.


3
4
5
6
# File 'lib/wisepdf/writer.rb', line 3

def initialize(wkhtmltopdf = nil, options = {})
  self.wkhtmltopdf = wkhtmltopdf unless wkhtmltopdf.nil?
  self.options = options
end

Instance Method Details

#optionsObject


32
33
34
35
# File 'lib/wisepdf/writer.rb', line 32

def options
  @options ||= Wisepdf::Parser.parse(Wisepdf::Configuration.options.dup)
  @options
end

#options=(value) ⇒ Object


37
38
39
# File 'lib/wisepdf/writer.rb', line 37

def options=(value)
  self.options.merge!(Wisepdf::Parser.parse(value))
end

#to_pdf(string, options = {}) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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

#wkhtmltopdfObject


23
24
25
# File 'lib/wisepdf/writer.rb', line 23

def wkhtmltopdf
  @wkhtmltopdf || self.wkhtmltopdf = Wisepdf::Configuration.wkhtmltopdf
end

#wkhtmltopdf=(value) ⇒ Object


27
28
29
30
# File 'lib/wisepdf/writer.rb', line 27

def wkhtmltopdf=(value)
  raise Wisepdf::NoExecutableError.new(value) if value.blank? || !File.exists?(value)
  @wkhtmltopdf = value
end