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.
-
#png_file ⇒ Object
Returns the value of attribute png_file.
Instance Method Summary collapse
- #base_path ⇒ Object
- #cache_key ⇒ Object
- #document ⇒ Object
- #infilename ⇒ Object
-
#initialize(base_url, html, css = "", width = 1000, height = 700) ⇒ PhantomJob
constructor
A new instance of PhantomJob.
- #outfilename ⇒ Object
- #program ⇒ Object
- #rasterize ⇒ Object
- #rasterize_cl ⇒ Object
- #rasterize_js ⇒ Object
Constructor Details
#initialize(base_url, html, css = "", width = 1000, height = 700) ⇒ PhantomJob
15 16 17 18 19 20 21 |
# File 'lib/shutterbug/phantom_job.rb', line 15 def initialize(base_url, html, css="", width=1000, height=700) @base_url = base_url @html = html @css = css @width = width @height = height end |
Instance Attribute Details
#html_file ⇒ Object
Returns the value of attribute html_file.
5 6 7 |
# File 'lib/shutterbug/phantom_job.rb', line 5 def html_file @html_file end |
#png_file ⇒ Object
Returns the value of attribute png_file.
4 5 6 |
# File 'lib/shutterbug/phantom_job.rb', line 4 def png_file @png_file end |
Instance Method Details
#base_path ⇒ Object
45 46 47 |
# File 'lib/shutterbug/phantom_job.rb', line 45 def base_path Configuration.instance.resource_dir end |
#cache_key ⇒ Object
23 24 25 |
# File 'lib/shutterbug/phantom_job.rb', line 23 def cache_key return @key || @key = Digest::SHA1.hexdigest("#{@html}#{@css}#{@base_url}")[0..10] end |
#document ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/shutterbug/phantom_job.rb', line 27 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 |
#infilename ⇒ Object
49 50 51 |
# File 'lib/shutterbug/phantom_job.rb', line 49 def infilename File.join(base_path,"phantom_#{cache_key}.html") end |
#outfilename ⇒ Object
53 54 55 |
# File 'lib/shutterbug/phantom_job.rb', line 53 def outfilename File.join(base_path,"phantom_#{cache_key}.png") end |
#program ⇒ Object
7 8 9 |
# File 'lib/shutterbug/phantom_job.rb', line 7 def program Configuration.instance.phantom_bin_path end |
#rasterize ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/shutterbug/phantom_job.rb', line 61 def rasterize File.open(infilename, 'w') do |f| f.write(document) end rasterize_cl() self.png_file = PngFile.new(outfilename) self.html_file = HtmlFile.new(infilename) end |
#rasterize_cl ⇒ Object
57 58 59 |
# File 'lib/shutterbug/phantom_job.rb', line 57 def rasterize_cl %x[#{self.program} #{self.rasterize_js} #{self.infilename} #{self.outfilename} #{@width}*#{@height}] end |
#rasterize_js ⇒ Object
11 12 13 |
# File 'lib/shutterbug/phantom_job.rb', line 11 def rasterize_js File.join(File.dirname(__FILE__),'rasterize.js') end |