Class: Shutterbug::Handlers::ConvertHandler

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject



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

def self.config
  Configuration.instance
end

.regexObject



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

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

Instance Method Details

#convert(req) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/shutterbug/handlers/convert_handler.rb', line 31

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

#get_options(req) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/shutterbug/handlers/convert_handler.rb', line 20

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

#handle(helper, req, env) ⇒ Object



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

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