Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for controller to be generated #101

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var CgangularGenerator = module.exports = function CgangularGenerator(args, opti
this.on('end', function () {
this.config.set('partialDirectory','partial/');
this.config.set('modalDirectory','partial/');
this.config.set('controllerDirectory', 'controller/');
this.config.set('directiveDirectory','directive/');
this.config.set('filterDirectory','filter/');
this.config.set('serviceDirectory','service/');
Expand Down
43 changes: 43 additions & 0 deletions controller/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';
var util = require('util');
var yeoman = require('yeoman-generator');
var path = require('path');
var cgUtils = require('../utils.js');
var chalk = require('chalk');
var _ = require('underscore');
var fs = require('fs');

_.str = require('underscore.string');
_.mixin(_.str.exports());

var ControllerGenerator = module.exports = function ControllerGenerator(args, options, config) {

cgUtils.getNameArg(this,args);

yeoman.generators.Base.apply(this, arguments);

};

util.inherits(ControllerGenerator, yeoman.generators.Base);

ControllerGenerator.prototype.askFor = function askFor() {
var cb = this.async();

var prompts = [];

cgUtils.addNamePrompt(this,prompts,'controller');

this.prompt(prompts, function (props) {
if (props.name){
this.name = props.name;
}
cgUtils.askForModuleAndDir('controller',this,false,cb);
}.bind(this));

};

ControllerGenerator.prototype.files = function files() {

cgUtils.processTemplates(this.name,this.dir,'controller',this,null,null,this.module);

};
18 changes: 18 additions & 0 deletions controller/templates/controller-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe('<%= _.camelize(name) %>', function() {

beforeEach(module('<%= appname %>'));

var scope, ctrl;

beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('<%= _.camelize(name) %>', {$scope: scope});
}));

it('should ...', inject(function() {

expect(1).toEqual(1);

}));

});
3 changes: 3 additions & 0 deletions controller/templates/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
angular.module('<%= appname %>').controller('<%= _.camelize(name) %>', function($scope) {

});
2 changes: 1 addition & 1 deletion directive/templates/complex/directive.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div class="<%= name %>">


</div>