Class: Screencap::Phantom

Inherits:
Object
  • Object
show all
Defined in:
lib/screencap/phantom.rb

Constant Summary collapse

RASTERIZE =
SCREENCAP_ROOT.join('screencap', 'raster.js')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.rasterize(url, path, args = {}) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/screencap/phantom.rb', line 5

def self.rasterize(url, path, args = {}) 
  params = {
    url: CGI::escape(url),
    output: path
  }.merge(args).collect {|k,v| "#{k}=#{v}"}
  #puts RASTERIZE.to_s, params
  cookies = Rails.root.join("tmp", "cookies.txt")
  params.push "--cookies-file=#{cookies.to_s}"
  params.push "--ssl-protocol=any"
  result = Phantomjs.run(RASTERIZE.to_s, *params)
  # puts result
  raise Screencap::Error, "Could not load URL #{url}" if result.match /Unable to load/
end

Instance Method Details

#quoted_arg(arg) ⇒ Object



23
24
25
26
27
28
# File 'lib/screencap/phantom.rb', line 23

def quoted_arg(arg)
  return arg if arg.starts_with?("'") && arg.ends_with?("'")
  arg = "'" + arg unless arg.starts_with?("'")
  arg = arg + "'" unless arg.ends_with?("'")
  arg
end

#quoted_args(args) ⇒ Object



19
20
21
# File 'lib/screencap/phantom.rb', line 19

def quoted_args(args)
  args.map{|x| quoted_arg(x)}
end