Class: Opal::CliRunners::Phantomjs

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/cli_runners/phantomjs.rb

Constant Summary

SCRIPT_PATH =
File.expand_path('../phantom.js', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Phantomjs

Returns a new instance of Phantomjs


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

def initialize(options)
  @output = options.fetch(:output, $stdout)
end

Instance Attribute Details

#exit_statusObject (readonly)

Returns the value of attribute exit_status


11
12
13
# File 'opal/lib/opal/cli_runners/phantomjs.rb', line 11

def exit_status
  @exit_status
end

#outputObject (readonly)

Returns the value of attribute output


11
12
13
# File 'opal/lib/opal/cli_runners/phantomjs.rb', line 11

def output
  @output
end

Instance Method Details

#run(code, argv) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'opal/lib/opal/cli_runners/phantomjs.rb', line 13

def run(code, argv)
  command = [
    'phantomjs',
    SCRIPT_PATH.shellescape,
    *argv.map(&:shellescape)
  ].join(' ')

  phantomjs = IO.popen(command, 'w', out: output) do |io|
    io.write(code)
  end

  @exit_status = $?.exitstatus
end