node-rails
v0.1.0
Published
Load js and coffee in assets of Rails3
Downloads
2
Readme
node-rails
Rails js and coffee loader for node.js.
Installation
Just copy rails.js.
Introduction
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: '[email protected]'
};
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: '[email protected]' } }
Useage
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 "[email protected]"': (topic) ->
assert.equal topic.author.email, '[email protected]'
.export module
$ vows --spec test.coffee
♢ Test cases for blog object
blog
✓ name of author is "Yuku Takahashi"
✓ email is "[email protected]"
✓ OK » 2 honored