Class: Wisepdf::Writer
Instance Method Summary collapse
-
#initialize(wkhtmltopdf = nil, options = {}) ⇒ Writer
constructor
A new instance of Writer.
- #options ⇒ Object
- #options=(value) ⇒ Object
- #to_pdf(string, options = {}) ⇒ Object
- #wkhtmltopdf ⇒ Object
- #wkhtmltopdf=(value) ⇒ Object
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, = {}) self.wkhtmltopdf = wkhtmltopdf unless wkhtmltopdf.nil? self. = end |
Instance Method Details
#options ⇒ Object
32 33 34 35 |
# File 'lib/wisepdf/writer.rb', line 32 def @options ||= Wisepdf::Parser.parse(Wisepdf::Configuration..dup) @options end |
#options=(value) ⇒ Object
37 38 39 |
# File 'lib/wisepdf/writer.rb', line 37 def (value) self..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, ={}) invoke = self.command().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 ⇒ Object
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 |