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.



5
6
7
8
# File 'lib/wisepdf/writer.rb', line 5

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

Instance Method Details

#optionsObject



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

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

#options=(value) ⇒ Object



41
42
43
# File 'lib/wisepdf/writer.rb', line 41

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

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wisepdf/writer.rb', line 10

def to_pdf(string, options={})
  invoke = self.command(options).join(' ')   
  self.log(invoke) if Wisepdf::Configuration.development? || Wisepdf::Configuration.test?

  result, err = Open3.popen3(invoke) do |stdin, stdout, stderr|
    stdin.binmode
    stdin.write(string)
    stdin.close
    [stdout.read, stderr.read]
  end

  raise Wisepdf::WriteError if result.to_s.strip.empty?

  return result
end

#wkhtmltopdfObject



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

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

#wkhtmltopdf=(value) ⇒ Object



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

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