Module: Phantomrb

Defined in:
lib/phantomrb.rb,
lib/phantomrb/errors.rb,
lib/phantomrb/runner.rb,
lib/phantomrb/version.rb,
lib/phantomrb/configuration.rb

Defined Under Namespace

Classes: Configuration, ExecutableLoadError, Runner, ScriptLoadError

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.configurationObject

Returns the global configuration.

Returns:

  • (Object)

    configuration



10
11
12
# File 'lib/phantomrb.rb', line 10

def configuration
  @configuration ||= Configuration.new
end

.configure { ... } ⇒ Object

Yields the global configuration to a block.

Examples:

Phantomrb.configure do
  parameter 'ignore-ssl-errors', true
end

Yields:

  • global configuration



21
22
23
# File 'lib/phantomrb.rb', line 21

def configure(&block)
  configuration.instance_eval(&block) if block_given?
end

.run(script, *args) {|line| ... } ⇒ OpenStruct

Runs JavaScript file.

Examples:

Simple output

puts Phantomrb.run('echo.js', 'test').output #=> "test"

Each line separate output

Phantomrb.run('echo.js', 'test') do |line|
  puts line #=> "test"
end

Parameters:

  • script (String)

    path for a script

  • args (String)

    script arguments

Yield Parameters:

  • line (String)

    line from stdout

Returns:

  • (OpenStruct)

    data

    • output (String) — full stdout from PhantomJS

    • exit_status (Integer) — exit status code

    • command_line (String) — full command line



41
42
43
44
# File 'lib/phantomrb.rb', line 41

def run(script, *args, &block)
  @runner ||= Runner.new
  @runner.run(script, args, &block)
end