Class: Shutterbug::Service

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

Instance Method Summary collapse

Constructor Details

#initialize(_config = Configuration.instance) ⇒ Service

Returns a new instance of Service.



5
6
7
8
9
# File 'lib/shutterbug/service.rb', line 5

def initialize(_config = Configuration.instance)
  @file_cache = {}
  @config = _config
  @js_file = JsFile.new()
end

Instance Method Details

#convert(base_url, html, css = "", width = 1000, height = 700) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/shutterbug/service.rb', line 11

def convert(base_url, html, css="", width=1000, height=700)
  job = PhantomJob.new(base_url, html, css, width, height)
  key = job.cache_key
  unless (@file_cache[key])
    job.rasterize
    @file_cache[key] = {'html' => job.html_file, 'png' => job.png_file }
  end
  return key
end

#get_html_file(sha) ⇒ Object



27
28
29
30
31
# File 'lib/shutterbug/service.rb', line 27

def get_html_file(sha)
  file = @file_cache[sha]['html']
  file.open
  return file
end

#get_png_file(sha) ⇒ Object



21
22
23
24
25
# File 'lib/shutterbug/service.rb', line 21

def get_png_file(sha)
  file = @file_cache[sha]['png']
  file.open
  return file
end

#get_shutterbug_fileObject



33
34
35
36
37
# File 'lib/shutterbug/service.rb', line 33

def get_shutterbug_file
  file = @js_file
  file.open
  return file
end