Sha256: f42a74b4ff43d35ab14b4aa2194d43f65cdacc2c4a99a931a338d5b1e94a6094

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

require 'stringio'

module Shutterbug
  module Handlers
    class ConvertHandler

      def self.config
        Configuration.instance
      end

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

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

      def get_options(req)
        opts = {}
        opts[:html]    = req.POST()['content']
        opts[:width]   = req.POST()['width']
        opts[:height]  = req.POST()['height']
        opts[:css]     = req.POST()['css']
        opts[:format]  = req.POST()['format']
        opts[:quality] = req.POST()['quality']
        return opts
      end

      def convert(req)
        config = self.class.config
        job = PhantomJob.new(config.base_url(req), get_options(req))
        unless (cache_entry = config.cache_manager.find(job.cache_key))
          job.rasterize
          html_entry = Shutterbug::CacheManager::CacheEntry.new(job.html_file)
          image_entry = Shutterbug::CacheManager::CacheEntry.new(job.image_file)
          html_entry.preview_url = image_entry.preview_url
          config.cache_manager.add_entry(html_entry)
          cache_entry = config.cache_manager.add_entry(image_entry)
        end
        # return the image tag
        return cache_entry
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shutterbug-0.5.9 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.8 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.7 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.6 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.5 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.4 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.3 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.2 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.1 lib/shutterbug/handlers/convert_handler.rb
shutterbug-0.5.0 lib/shutterbug/handlers/convert_handler.rb