Class: PhantomPDF::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/phantompdf/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output = nil, options = {}) ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
14
15
# File 'lib/phantompdf/generator.rb', line 10

def initialize(input, output=nil, options={})
  @input = Source.new(input)
  @output = dump_output(output, !output.nil?)
  @options = Config.new(options).default_options
  @exception = nil
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/phantompdf/generator.rb', line 7

def config
  @config
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



8
9
10
# File 'lib/phantompdf/generator.rb', line 8

def cookies
  @cookies
end

#exceptionObject (readonly)

Returns the value of attribute exception.



8
9
10
# File 'lib/phantompdf/generator.rb', line 8

def exception
  @exception
end

#inputObject

Returns the value of attribute input.



7
8
9
# File 'lib/phantompdf/generator.rb', line 7

def input
  @input
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/phantompdf/generator.rb', line 8

def options
  @options
end

#outputObject

Returns the value of attribute output.



7
8
9
# File 'lib/phantompdf/generator.rb', line 7

def output
  @output
end

Instance Method Details

#generate(path = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/phantompdf/generator.rb', line 17

def generate(path=nil)
  @output = dump_output(path, true) unless path.nil?

  result = run
  unless $?.exitstatus == 0
    @exception = result.split(/\n/)

    return nil
  end

  result.split("\n").compact.pop
end

#generate!(path = nil) ⇒ Object

Raises:



30
31
32
33
34
35
# File 'lib/phantompdf/generator.rb', line 30

def generate!(path=nil)
  result = generate(path)
  raise RenderingError.new(@exception.join("\n")) if result.nil?

  result
end

#to_stringObject



37
38
39
40
41
42
# File 'lib/phantompdf/generator.rb', line 37

def to_string
  result = generate(nil)
  return '' if result.nil?

  File.open(result, 'rb').read
end