Sha256: 64b43c584f0424139491ddd454b01ae21b9a1af6f4564be20454309e9da163e3

Contents?: true

Size: 879 Bytes

Versions: 1

Compression:

Stored size: 879 Bytes

Contents

require 'json'

module DragonflyChromeHeadless
  module Processors
    class Rasterize
      class UnsupportedFormat < RuntimeError; end

      def call(content, format=:pdf, options={})
        raise UnsupportedFormat unless %w(pdf).include?(format.to_s)

        node_command = content.env.fetch(:node_command, 'node')
        options[:host] ||= content.env[:host]
        options[:port] ||= content.env[:port]

        options = options.reject{ |_, v| v.nil? }

        content.shell_update(ext: format) do |old_path, new_path|
          "#{node_command} #{rasterize_script} #{old_path} #{new_path} '#{options.to_json}'"
        end
      end

      def update_url(attrs, format, args='')
        attrs.ext = format.to_s
      end

      private

      def rasterize_script
        File.join(DragonflyChromeHeadless.root, "script", "rasterize.js")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dragonfly_chrome_headless-0.2.0 lib/dragonfly_chrome_headless/processors/rasterize.rb