Sha256: db9b634876655424aef1955f0b691d3b8cb0876daa076ea7f09f05a9f7569dcf

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

require 'stringio'
module Shutterbug
  module Handlers
    class ConvertHandler

      def initialize(_config = Configuration.instance)
        @config = _config
      end

      def regex
        /#{@config.path_prefix}\/make_snapshot/
      end

      def handle(helper, req, env)
        response_text = convert(req).image_tag
        helper.good_response(response_text,'text/plain')
      end

      def convert(req)
        html     = req.POST()['content']  ||  ""
        width    = req.POST()['width']    || 1000
        height   = req.POST()['height']   ||  700
        css      = req.POST()['css']      ||  ""
        job = PhantomJob.new(@config.base_url(req), html, css, width, height)
        unless (cache_entry = @config.cache_manager.find(job.cache_key))
          job.rasterize
          html_entry = Shutterbug::CacheManager::CacheEntry.new(job.html_file)
          png_entry  = Shutterbug::CacheManager::CacheEntry.new(job.png_file)
          html_entry.preview_url = png_entry.preview_url
          @config.cache_manager.add_entry(html_entry)
          cache_entry = @config.cache_manager.add_entry(png_entry)
        end
        # return the image tag
        return cache_entry
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shutterbug-0.2.5 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.2.1 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.2.0 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.1.2 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.1.1 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.1.0 lib/shutterbug/handlers/convert_handler.rb