Class: Phantomjs

Inherits:
Object
  • Object
show all
Defined in:
lib/phantomjs.rb,
lib/phantomjs/errors.rb,
lib/phantomjs/version.rb,
lib/phantomjs/configuration.rb

Defined Under Namespace

Modules: Configuration Classes: CommandNotFoundError, NoSuchPathError

Constant Summary collapse

VERSION =
"2.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object



31
32
33
# File 'lib/phantomjs.rb', line 31

def self.configure(&block)
  Configuration.configure(&block)
end

.inline(script, *args, &block) ⇒ Object



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

def self.inline(script, *args, &block)
  Phantomjs.new.inline(script, *args, &block)
end

.run(path, *args, &block) ⇒ Object



8
9
10
# File 'lib/phantomjs.rb', line 8

def self.run(path, *args, &block)
  Phantomjs.new.run(path, *args, &block)
end

Instance Method Details

#inline(script, *args) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/phantomjs.rb', line 23

def inline(script, *args)
  file = Tempfile.new('script.js')
  file.write(script)
  file.close
  block = block_given? ? Proc.new : nil
  execute(file.path, args, block)
end

#run(path, *args) ⇒ Object

Raises:



12
13
14
15
16
17
# File 'lib/phantomjs.rb', line 12

def run(path, *args)
  epath = File.expand_path(path)
  raise NoSuchPathError.new(epath) unless File.exist?(epath)
  block = block_given? ? Proc.new : nil
  execute(epath, args, block)
end