commit 6ba90fc0fa52ab86ceac3852aac3d30999c12634 Author: Sam Stephenson Date: Sun Feb 6 14:22:40 2011 -0600 Initial commit diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..b023c15 --- /dev/null +++ b/Rakefile @@ -0,0 +1,7 @@ +require "rake/testtask" + +task :default => :test + +Rake::TestTask.new do |t| + t.warning = true +end diff --git a/lib/execjs.rb b/lib/execjs.rb new file mode 100644 index 0000000..6793c7b --- /dev/null +++ b/lib/execjs.rb @@ -0,0 +1,3 @@ +module ExecJS + autoload :Runtimes, "execjs/runtimes" +end diff --git a/lib/execjs/runtimes.rb b/lib/execjs/runtimes.rb new file mode 100644 index 0000000..aaa1ecc --- /dev/null +++ b/lib/execjs/runtimes.rb @@ -0,0 +1,5 @@ +module ExecJS + module Runtimes + autoload :Node, "execjs/runtimes/node" + end +end diff --git a/lib/execjs/runtimes/node.rb b/lib/execjs/runtimes/node.rb new file mode 100644 index 0000000..ae3e6be --- /dev/null +++ b/lib/execjs/runtimes/node.rb @@ -0,0 +1,26 @@ +module ExecJS + module Runtimes + class Node + + end + end +end + +__END__ +(function(program, execJS) { execJS(program) })(function() { #{source} +}, function(program) { + var result, output; + try { + result = program(); + try { + output = JSON.stringify(result); + sys.print('ok '); + sys.print(output); + } catch (err) { + sys.print('err'); + } + } catch (err) { + sys.print('err '); + sys.print(err); + } +}); diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..109d37d --- /dev/null +++ b/readme.md @@ -0,0 +1,23 @@ +ExecJS +====== + +ExecJS lets you run JavaScript code from Ruby. It automatically picks +the best runtime available to evaluate your JavaScript program, then +returns the result to you as a Ruby object. + +ExecJS supports these runtimes: + +* [therubyracer](https://github.com/cowboyd/therubyracer) - Google V8 + embedded within Ruby for exceptional performance +* [Node.js](http://nodejs.org/) +* [Google V8](http://code.google.com/p/v8/) +* Apple JavaScriptCore +* [Mozilla Spidermonkey](http://www.mozilla.org/js/spidermonkey/) +* [Mozilla Rhino](http://www.mozilla.org/rhino/) +* [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript) + +A short example: + + require "execjs" + ExecJS.exec "'red yellow blue'.split('')" + # => ["red", "yellow", "blue"] diff --git a/test/test_node_runtime.rb b/test/test_node_runtime.rb new file mode 100644 index 0000000..e69de29