Skip to content

Commit

Permalink
replaced Open3 with IO.popen
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-alexandrov committed Feb 20, 2013
1 parent 7feafd9 commit 109537d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/wisepdf/configuration.rb
Expand Up @@ -39,6 +39,11 @@ def test?
(defined?(RAILS_ENV) && RAILS_ENV == 'test')
end

def production?
(defined?(::Rails) && ::Rails.env == 'production') ||
(defined?(RAILS_ENV) && RAILS_ENV == 'production')
end

def windows?
RbConfig::CONFIG['target_os'] == 'mingw32'
end
Expand Down
11 changes: 5 additions & 6 deletions lib/wisepdf/writer.rb
Expand Up @@ -9,13 +9,12 @@ def initialize(wkhtmltopdf = nil, options = {})

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

result, err = Open3.popen3(invoke) do |stdin, stdout, stderr|
stdin.binmode
stdin.write(string)
stdin.close
[stdout.read, stderr.read]
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?
Expand Down

0 comments on commit 109537d

Please sign in to comment.