CanJS generator for Yeoman.
- Make sure you have yo installed:
npm install -g yo
- Install the generator:
npm install -g generator-canjs
- Run:
yo canjs
$ yo canjs
This will create basic application scaffold. It will allow you to choose if you're using
RequireJS as a dependency management. This setting will
affect the canjs:model
and the canjs:control
generators.
$ yo canjs:model path/to/model
This will create the model file. If you call this generator as yo canjs:model models/user
it will create user.js
file in the models
folder.
$ yo canjs:control path/to/control/folder
This generator is different than canjs:model
as it doesn't create just one file. Instead,
it creates a folder which contains all files needed to run this control in isolation.
If you run it like:
$ yo canjs:control controls/users
it will create following structure:
controls/
users/
users.js // control file
users.html // demo page
init.mustache // example mustache view
init.ejs // example ejs view
This generator installs https://github.com/retro/require-can-renderers which allow loading of
mustache
and ejs
files via RequireJS. It allows you to have code that looks like:
define('mustache!./init', function(initView){
// initView is a renderer function and can be called as:
initView()
})
This generator comes with the Gruntfile.js which provides the build
task. It will compile JavaScript
and view files to the production.js
file.
It is a default task so it can be called as:
$ grunt
Or as:
$ grunt build