public
Description: Rouge is a JavaScript implementation of important parts of the Ruby core library.
Homepage: http://njonsson.github.com/rouge
Clone URL: git://github.com/njonsson/rouge.git
Click here to lend your support to: rouge and make a donation at www.pledgie.com !
rouge /
name age message
file .gitignore Mon Apr 20 17:24:07 -0700 2009 Ignore Mac OS filesystem metadata [njonsson]
file .gitmodules Wed Feb 04 18:57:57 -0800 2009 Conform filenames to URL conventions instead of... [njonsson]
file .jsdoc_config Wed Feb 04 21:07:06 -0800 2009 Add JSDoc documentation and switch to explicit ... [njonsson]
file MIT-LICENSE Wed Feb 04 05:40:47 -0800 2009 Import project, together with Screw.Unit [njonsson]
file README.textile Loading commit data...
directory src/
README.textile

Welcome to Rouge

His code not “functional” or “elegant.”
What do Code Monkey think?
— Jonathan Coulton, “Code Monkey”

Do Ruby’s stylish core and standard libraries make your JavaScript green with envy? Tart up that dowdy JavaScript — put on some Rouge.

Rouge is a JavaScript implementation of important parts of the Ruby core library.

Usage

Rouge makes your JavaScript look and feel more like Ruby while preserving sound JavaScript style.

JavaScript Rouge Ruby
var array = [],
    i     = 0;
for (; i < 10; i++) {
  array[i] = 'foo';
}
console.debug(array);
var array = Array.new(10, 'foo');
console.debug(array);
array = Array.new(10, 'foo')
puts array.inspect
var array = ['foo', 'bar'],
    i     = 0;
for (; i < array.length; i++) {
  console.debug(array[i]);
}
var array = ['foo', 'bar'];
array.each(function (s) {
  console.debug(s);
});
array = %w(foo bar)
array.each do
  puts s.inspect
end
var array     = ['foo', 'bar'],
    collected = [],
    i         = 0;
for (; i < array.length; i++) {
  collected[collected.length] = array[i];
}
console.debug(collected);
var array     = ['foo', 'bar'],
    collected = array.collect(function (s) {
      return 'item: ' + s;
    });
console.debug(collected);
array = %w(foo bar)
collected = array.collect do
  "item: #{s}"
end
puts collected.inspect

You should have a look at the documentation.

Test coverage

Rouge has around 500 executable specifications authored using the Screw.Unit framework. Run the specs by opening src/spec/suite.html. (Firefox works best for this.)

Credits

Rouge’s author is Nils Jonsson. Released under the MIT License.