Signed-off-by: Simon Bailey <simon@newtriks.com>
This commit is contained in:
Simon Bailey 2014-05-15 23:52:14 +01:00
parent defeaedb71
commit abdb2adb02
4 changed files with 28 additions and 11 deletions

3
.gitignore vendored
View File

@ -28,5 +28,4 @@ $RECYCLE.BIN/
# App specific # App specific
node_modules/ node_modules/
/test/temp-test/ /test/*
/test/temp/

View File

@ -9,13 +9,16 @@ var Generator = module.exports = function Generator() {
// Add capitalize mixin // Add capitalize mixin
this._.mixin({ 'capitalize': generalUtils.capitalize }); this._.mixin({ 'capitalize': generalUtils.capitalize });
this._.mixin({ 'capitalizeFile': generalUtils.capitalizeFile });
this._.mixin({ 'capitalizeClass': generalUtils.capitalizeClass });
this._.mixin({ 'lowercase': generalUtils.lowercase }); this._.mixin({ 'lowercase': generalUtils.lowercase });
this.appname = path.basename(process.cwd()); this.appname = path.basename(process.cwd());
this.appname = this._.slugify(this._.humanize(this.appname)); this.appname = this._.slugify(this._.humanize(this.appname));
this.scriptAppName = this._.camelize(this._.capitalize(this.appname)) + generalUtils.appName(this); this.scriptAppName = this._.camelize(this._.capitalize(this.appname)) + generalUtils.appName(this);
this.classedName = this._.capitalize(this.name); this.classedFileName = this._.capitalizeFile(this.name);
this.classedName = this._.capitalizeClass(this.name);
if (typeof this.env.options.appPath === 'undefined') { if (typeof this.env.options.appPath === 'undefined') {
this.env.options.appPath = this.env.options.appPath || 'src'; this.env.options.appPath = this.env.options.appPath || 'src';
@ -71,7 +74,7 @@ Generator.prototype.htmlTemplate = function (src, dest) {
}; };
Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, stylesTemplate, targetDirectory) { Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, stylesTemplate, targetDirectory) {
this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this._.capitalize(this.name))); this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this._.capitalizeFile(this.name)));
this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalize(this.name))); this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalizeFile(this.name)));
this.stylesTemplate(stylesTemplate, path.join(this._.capitalize(this.name))); this.stylesTemplate(stylesTemplate, path.join(this._.capitalizeFile(this.name)));
}; };

View File

@ -4,7 +4,7 @@ describe('<%= classedName %>', function () {
var <%= classedName %>, component; var <%= classedName %>, component;
beforeEach(function () { beforeEach(function () {
<%= classedName %> = require('../../../src/scripts/components/<%= classedName %>.jsx'); <%= classedName %> = require('../../../src/scripts/components/<%= classedFileName %>.jsx');
component = <%= classedName %>(); component = <%= classedName %>();
}); });

21
util.js
View File

@ -7,7 +7,9 @@ module.exports = {
rewrite: rewrite, rewrite: rewrite,
rewriteFile: rewriteFile, rewriteFile: rewriteFile,
appName: appName, appName: appName,
capitalize: capitalize capitalize: capitalize,
capitalizeClass: capitalizeClass,
capitalizeFile: capitalizeFile
}; };
function rewriteFile (args) { function rewriteFile (args) {
@ -60,8 +62,21 @@ function rewrite (args) {
return lines.join('\n'); return lines.join('\n');
} }
function capitalize(string) { function capitalize(str) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); str = String(str);
return str[0].toUpperCase() + str.substr(1, str.length);
}
function capitalizeClass(string) {
var words = string.split('/');
words.push(capitalize(words.pop()));
return words.pop();
}
function capitalizeFile(string) {
var words = string.split('/');
words.push(capitalize(words.pop()));
return words.join('/');
} }
function appName(self) { function appName(self) {