Skip to content
/ include_js Public
forked from walski/include_js

Load CommonJS Modules into Ruby (via therubyracer). hybridtheory.

License

Notifications You must be signed in to change notification settings

ahx/include_js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IncludeJS

Load CommonJS Modules into Ruby.

Currently it supports the CommonJS Modules 1.0 spec.

It uses therubyracer.

Synopsis

Writing a CommonJS Module in JavaScript

Inside 'helpers.js':

var a = 42;
exports.foo = function() {
  return 42;
}

Loading a CommonJS Module from Ruby

helpers = IncludeJS.require('helpers') # This returns a V8::Object
helpers.foo # => 42

Loading a CommonJS Module as a Ruby Module

class App
  include IncludeJS.module('helpers')
end
App.new.foo # => 42

You can set one root path from where to load .js files

IncludeJS.root_path = 'my/app/javascripts'

Have fun.

Running the specs

git submodule update --init
bundle install
bundle rspec spec    

Speed

Simple benchmarks are showing a noticeable gain of speed when using JS methods instead of native Ruby ones. While the Google V8 seems to be 10x faster than Ruby 1.8.7 it is still 4x as fast as Ruby 1.9.2

About

Load CommonJS Modules into Ruby (via therubyracer). hybridtheory.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 94.7%
  • JavaScript 5.3%