mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Initial commit
This commit is contained in:
commit
6ba90fc0fa
6 changed files with 64 additions and 0 deletions
7
Rakefile
Normal file
7
Rakefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "rake/testtask"
|
||||
|
||||
task :default => :test
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.warning = true
|
||||
end
|
3
lib/execjs.rb
Normal file
3
lib/execjs.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
module ExecJS
|
||||
autoload :Runtimes, "execjs/runtimes"
|
||||
end
|
5
lib/execjs/runtimes.rb
Normal file
5
lib/execjs/runtimes.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module ExecJS
|
||||
module Runtimes
|
||||
autoload :Node, "execjs/runtimes/node"
|
||||
end
|
||||
end
|
26
lib/execjs/runtimes/node.rb
Normal file
26
lib/execjs/runtimes/node.rb
Normal file
|
@ -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);
|
||||
}
|
||||
});
|
23
readme.md
Normal file
23
readme.md
Normal file
|
@ -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"]
|
0
test/test_node_runtime.rb
Normal file
0
test/test_node_runtime.rb
Normal file
Loading…
Reference in a new issue