lib/boojs.rb in boojs-0.0.11 vs lib/boojs.rb in boojs-0.0.12

- old
+ new

@@ -26,12 +26,13 @@ tmp.close system("phantomjs #{tmp.path} 2>&1") or raise "Verifying failed" end - #Optionally, accept code to inject - def self.pipe(str=nil) + #Optionally, accept code to inject and a command to run + #If the command is nil, this is not executed as a oneshot + def self.pipe(str=nil, cmd=nil) js = %{ var system = require('system'); function __spec_ping(str) { system.stdout.writeLine("pong"+str) } @@ -51,10 +52,15 @@ #Any code the user wanted js += "\n#{str}" if str #Repl - js += "\nwhile (true) { var line = system.stdin.readLine(); eval(line); }" + if cmd + js += "\n#{cmd}" + js += "\nphantom.exit(1)" + else + js += "\nwhile (true) { var line = system.stdin.readLine(); eval(line); }" + end phantom = Phantomjs.path tmp = Tempfile.new(SecureRandom.hex) tmp.puts js tmp.close