Class: Shutterbug::PhantomJob
- Inherits:
-
Object
- Object
- Shutterbug::PhantomJob
- Defined in:
- lib/shutterbug/phantom_job.rb
Instance Attribute Summary collapse
-
#html_file ⇒ Object
Returns the value of attribute html_file.
-
#image_file ⇒ Object
Returns the value of attribute image_file.
Instance Method Summary collapse
- #cache_key ⇒ Object
- #document ⇒ Object
- #html_file_name ⇒ Object
- #image_file_name ⇒ Object
-
#initialize(base_url, html, css = "", width = 1000, height = 700, format = "png", quality = 10) ⇒ PhantomJob
constructor
A new instance of PhantomJob.
- #input_path ⇒ Object
- #output_path ⇒ Object
- #program ⇒ Object
- #rasterize ⇒ Object
- #rasterize_cl ⇒ Object
- #rasterize_js ⇒ Object
Constructor Details
#initialize(base_url, html, css = "", width = 1000, height = 700, format = "png", quality = 10) ⇒ PhantomJob
Returns a new instance of PhantomJob.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shutterbug/phantom_job.rb', line 14 def initialize(base_url, html, css="", width=1000, height=700, format="png", quality=10) @base_url = base_url @html = html @css = css @width = width @height = height @format = format @quality = quality @config = Configuration.instance end |
Instance Attribute Details
#html_file ⇒ Object
Returns the value of attribute html_file.
4 5 6 |
# File 'lib/shutterbug/phantom_job.rb', line 4 def html_file @html_file end |
#image_file ⇒ Object
Returns the value of attribute image_file.
3 4 5 |
# File 'lib/shutterbug/phantom_job.rb', line 3 def image_file @image_file end |
Instance Method Details
#cache_key ⇒ Object
25 26 27 |
# File 'lib/shutterbug/phantom_job.rb', line 25 def cache_key @cache_key ||= Digest::SHA1.hexdigest("#{@html}#{@css}#{@base_url}#{@format}#{@quality}")[0..10] end |
#document ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/shutterbug/phantom_job.rb', line 29 def document date = Time.now.strftime("%Y-%m-%d (%I:%M%p)") """ <!DOCTYPE html> <html> <head> <base href='#{@base_url}'> <meta content='text/html;charset=utf-8' http-equiv='Content-Type'> <title>content from #{@base_url} #{date}</title> #{@css} </head> <body> #{@html} </body> </html> """ end |
#html_file_name ⇒ Object
47 48 49 |
# File 'lib/shutterbug/phantom_job.rb', line 47 def html_file_name "#{cache_key}.html" end |
#image_file_name ⇒ Object
51 52 53 |
# File 'lib/shutterbug/phantom_job.rb', line 51 def image_file_name "#{cache_key}.#{@format}" end |
#input_path ⇒ Object
55 56 57 |
# File 'lib/shutterbug/phantom_job.rb', line 55 def input_path @config.fs_path_for(html_file_name) end |
#output_path ⇒ Object
59 60 61 |
# File 'lib/shutterbug/phantom_job.rb', line 59 def output_path @config.fs_path_for(image_file_name) end |
#program ⇒ Object
6 7 8 |
# File 'lib/shutterbug/phantom_job.rb', line 6 def program @config.phantom_bin_path end |
#rasterize ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/shutterbug/phantom_job.rb', line 67 def rasterize File.open(input_path, 'w') do |f| f.write(document) end rasterize_cl() self.image_file = @config.storage.new(image_file_name) self.html_file = @config.storage.new(html_file_name) end |
#rasterize_cl ⇒ Object
63 64 65 |
# File 'lib/shutterbug/phantom_job.rb', line 63 def rasterize_cl %x[#{self.program} --ignore-ssl-errors=true --ssl-protocol=any #{self.rasterize_js} #{self.input_path} #{self.output_path} #{@width}*#{@height} #{@quality}] end |
#rasterize_js ⇒ Object
10 11 12 |
# File 'lib/shutterbug/phantom_job.rb', line 10 def rasterize_js File.join(File.dirname(__FILE__),'rasterize.js') end |