Class: Shutterbug::Handlers::ConvertHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/shutterbug/handlers/convert_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(_config = Configuration.instance) ⇒ ConvertHandler

Returns a new instance of ConvertHandler.



6
7
8
# File 'lib/shutterbug/handlers/convert_handler.rb', line 6

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

Instance Method Details

#convert(req) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/shutterbug/handlers/convert_handler.rb', line 19

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

#handle(helper, req, env) ⇒ Object



14
15
16
17
# File 'lib/shutterbug/handlers/convert_handler.rb', line 14

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

#regexObject



10
11
12
# File 'lib/shutterbug/handlers/convert_handler.rb', line 10

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