Sha256: 65689726aa275033acd110f5b113f8e6d45352b5988de544cd973a0f8a4d282a

Contents?: true

Size: 717 Bytes

Versions: 1

Compression:

Stored size: 717 Bytes

Contents

class Pixelpress::WeasyPrintRenderer
  def render(html)

    command = "#{executable_path} --encoding UTF-8 - -"

    error = nil
    result = nil
    process = nil
    Open3.popen3(command) do |stdin, stdout, stderr, thread|
      stdin.puts html
      stdin.close_write
      result = stdout.read
      error = stderr.read
      process = thread.value
    end
    raise "command failed (exitstatus=#{result.exitstatus}): #{command}\n #{error}" unless process.success?
    return result
  end
  
  def version
    `#{executable_path} --version`.chomp.scan(/(\d+\.\d+)/).flatten.first
  end

  private

  def executable_path
    `which weasyprint`.chomp || raise(StandardError, "could not find weasyprint")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pixelpress-0.2.4 lib/pixelpress/renderers/weasyprint_renderer.rb