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.
5 6 7 8 |
# File 'lib/wisepdf/writer.rb', line 5 def initialize(wkhtmltopdf = nil, = {}) self.wkhtmltopdf = wkhtmltopdf unless wkhtmltopdf.nil? self. = end |
Instance Method Details
#options ⇒ Object
36 37 38 39 |
# File 'lib/wisepdf/writer.rb', line 36 def @options ||= Wisepdf::Parser.parse(Wisepdf::Configuration..dup) @options end |
#options=(value) ⇒ Object
41 42 43 |
# File 'lib/wisepdf/writer.rb', line 41 def (value) self..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, ={}) invoke = self.command().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 |
#wkhtmltopdf ⇒ Object
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 |