Class: PhantomPDF::Generator
- Inherits:
-
Object
- Object
- PhantomPDF::Generator
- Defined in:
- lib/phantompdf/generator.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#input ⇒ Object
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #generate(path = nil) ⇒ Object
- #generate!(path = nil) ⇒ Object
-
#initialize(input, output = nil, options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #to_string ⇒ Object
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, ={}) @input = Source.new(input) @output = dump_output(output, !output.nil?) @options = Config.new(). @exception = nil end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/phantompdf/generator.rb', line 7 def config @config end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
8 9 10 |
# File 'lib/phantompdf/generator.rb', line 8 def @cookies end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
8 9 10 |
# File 'lib/phantompdf/generator.rb', line 8 def exception @exception end |
#input ⇒ Object
Returns the value of attribute input.
7 8 9 |
# File 'lib/phantompdf/generator.rb', line 7 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/phantompdf/generator.rb', line 8 def @options end |
#output ⇒ Object
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
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_string ⇒ Object
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 |