Rails js and coffee loader for node.js.
Just copy rails.js.
Suppose that app/assets/javascripts/blog.js
and app/assets/javascripts/author.js
are:
// app/assets/javascripts/blog.js
//= require author
blog = {
author: author
};
// app/assets/javascripts/author.js
author = {
name: 'Yuku Takahashi'
email: 'taka84u9@gmail.com'
};
Then you can load it as follows:
// tmp.js
rails = require('node-rails');
window = rails.load('blog');
console.log(window.blog);
When execute tmp.js
:
$ node tmp.js
{ author: { name: 'Yuku Takahashi', email: 'taka84u9@gmail.com' } }
I developed this module to write JavaScript test cases using vows:
# test.coffee
vows = require 'vows'
assert = require 'assert'
rails = require 'node-rails'
blog = rails.load('blog').blog
vows
.describe('Test cases for blog object')
.addBatch
'blog':
topic: -> blog
'name of author is "Yuku Takahashi"': (topic) ->
assert.equal topic.author.name, 'Yuku Takahashi'
'email is "taka84u9@gmail.com"': (topic) ->
assert.equal topic.author.email, 'taka84u9@gmail.com'
.export module
$ vows --spec test.coffee
♢ Test cases for blog object
blog
✓ name of author is "Yuku Takahashi"
✓ email is "taka84u9@gmail.com"
✓ OK » 2 honored