generator-baffled
Version:
Bootstrap + Angular + Firebase + Flat-UI
42 lines (33 loc) • 1.29 kB
JavaScript
'use strict';
var path = require('path');
var fs = require('fs');
var util = require('util');
var ScriptBase = require('../script-base.js');
var angularUtils = require('../util.js');
module.exports = Generator;
function Generator() {
ScriptBase.apply(this, arguments);
// if the controller name is suffixed with ctrl, remove the suffix
// if the controller name is just "ctrl," don't append/remove "ctrl"
if (this.name && this.name.toLowerCase() !== 'ctrl' && this.name.substr(-4).toLowerCase() === 'ctrl') {
this.name = this.name.slice(0, -4);
}
}
util.inherits(Generator, ScriptBase);
Generator.prototype.createControllerFiles = function createControllerFiles() {
var file = path.join(this.env.options.appPath, 'scripts', 'controllers', this._.slugify(this.name)) + '.js';
var exists = fs.existsSync(file);
var classed = this._.classify(this.arguments.join('-'));
if (!exists) {
this.appTemplate('controller', path.join('scripts', 'controllers', this._.slugify(this.name)));
this.addScriptToIndex('controllers/' + this.name);
} else {
angularUtils.rewriteFile({
file: file,
needle: ';/* yeoman generator hook */',
splicable: [
' .controller(\'' + classed + 'Ctrl\', function($scope) {\n })\n',
]
});
}
};