Skip to content

Commit

Permalink
helper generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanflorence committed Apr 13, 2013
1 parent b6a8340 commit 1ccff98
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
npm-debug.log
test-app
.ember

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ from which `ember create` is called. It's used for other `ember` commands.
| `--template, -t post/comments` | n/a | `templates/post/comments.handlebars` |
| `--route, -r taco_cart` | `TacoCartRoute` | `routes/taco_cart.js` |
| `--mixin, -x tacoable` | `Tacoable` | `mixins/tacoable.js` |
| `--helper, -l all_caps` | `allCaps` | `helpers/all_caps.js` |
| `-mvcrt tacos` | `Taco` <br>`TacosView` <br>`TacosController` <br>`TacosRoute` | `models/taco.js` <br>`views/tacos_view` <br>`controllers/tacos_controller.js` <br>`routes/taco_route.js` <br>`templates/tacos.handlebars`|

_Notes:_
Expand All @@ -94,6 +95,7 @@ _Notes:_
- emblem.js templates
- AMD generators/build
- ES6 module generators/build
- Build on top of Yeoman

## License and Copyright

Expand Down
1 change: 1 addition & 0 deletions bin/ember
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ program
generate.apply(null, arguments);
})
.option('-c, --controller [name]', 'generates a controller')
.option('-l, --helper [name]', 'generates a handlebars helper')
.option('-x, --mixin [name]', 'generates a mixin')
.option('-m, --model [name] [fields]', 'generates a model with optional [fields]')
.option('-r, --route [name]', 'generates a route')
Expand Down
17 changes: 11 additions & 6 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ module.exports = function(program) {

function createIndex() {
var modules = [];
var helpers = [];
appDirs.forEach(function(dirName) {
if (dirName == 'templates') return;
var dirPath = rootify(dirName);
var walker = walk(dirPath);
walker.on('file', function(dir, stats, next) {
if (stats.name.charAt(0) !== '.') {
var path = unroot(dir + '/' + stats.name).replace(/\.js$/, '');
var name = inflector.objectify(path.replace(dirName, ''));
modules.push({
objectName: name,
path: path
});
if (dirName == 'helpers') {
helpers.push({path: path});
} else {
var name = inflector.objectify(path.replace(dirName, ''));
modules.push({
objectName: name,
path: path
});
}
}
next();
});
Expand All @@ -38,7 +43,7 @@ function createIndex() {
return template.write(
'build/index.js',
rootify('index.js'),
{modules: modules},
{modules: modules, helpers: helpers},
true
);
}
Expand Down
11 changes: 11 additions & 0 deletions src/generators/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var template = require('../util/template');
var inflector = require('../util/inflector');

module.exports = function(name) {
var fileName = inflector.underscore(name);
var helperName = inflector.camelize(name);
return template.generate('helper', fileName, {
helperName: helperName
}, true);
};

1 change: 1 addition & 0 deletions src/generators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ exports.template = require('./template');
exports.route = require('./route');
exports.scaffold = require('./scaffold');
exports.mixin = require('./mixin');
exports.helper = require('./helper');

2 changes: 2 additions & 0 deletions src/templates/build/index.js.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require('./vendor/handlebars');
require('./vendor/ember');
require('./vendor/ember-data');
require('./templates');
{{#each helpers}}require('./{{path}}');
{{/each}}

var App = window.App = require('./app');

Expand Down
4 changes: 4 additions & 0 deletions src/templates/generate/helper.js.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Ember.Handlebars.registerBoundHelper('{{helperName}}', function() {

});

1 change: 1 addition & 0 deletions src/util/appDirs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = [
'controllers',
'helpers',
'models',
'routes',
'templates',
Expand Down
1 change: 1 addition & 0 deletions test/support/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require('./vendor/ember');
require('./vendor/ember-data');
require('./templates');


var App = window.App = require('./app');

App.Store = require('./store');
Expand Down
1 change: 1 addition & 0 deletions test/support/build/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require('./vendor/ember');
require('./vendor/ember-data');
require('./templates');


var App = window.App = require('./app');

App.Store = require('./store');
Expand Down
1 change: 1 addition & 0 deletions test/support/build/sub_directories.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require('./vendor/ember');
require('./vendor/ember-data');
require('./templates');


var App = window.App = require('./app');

App.Store = require('./store');
Expand Down

0 comments on commit 1ccff98

Please sign in to comment.