diff --git a/.gitignore b/.gitignore index 5a2ac84..40ab9fb 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,4 @@ $RECYCLE.BIN/ # App specific node_modules/ -/test/temp-test/ -/test/temp/ +/test/* diff --git a/script-base.js b/script-base.js index 8b4029d..101e710 100644 --- a/script-base.js +++ b/script-base.js @@ -8,14 +8,17 @@ var Generator = module.exports = function Generator() { yeoman.generators.NamedBase.apply(this, arguments); // 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.appname = path.basename(process.cwd()); this.appname = this._.slugify(this._.humanize(this.appname)); 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') { 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) { - this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this._.capitalize(this.name))); - this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalize(this.name))); - this.stylesTemplate(stylesTemplate, path.join(this._.capitalize(this.name))); + this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this._.capitalizeFile(this.name))); + this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalizeFile(this.name))); + this.stylesTemplate(stylesTemplate, path.join(this._.capitalizeFile(this.name))); }; diff --git a/templates/spec/Component.js b/templates/spec/Component.js index 93e72b2..9ae1e14 100644 --- a/templates/spec/Component.js +++ b/templates/spec/Component.js @@ -4,7 +4,7 @@ describe('<%= classedName %>', function () { var <%= classedName %>, component; beforeEach(function () { - <%= classedName %> = require('../../../src/scripts/components/<%= classedName %>.jsx'); + <%= classedName %> = require('../../../src/scripts/components/<%= classedFileName %>.jsx'); component = <%= classedName %>(); }); diff --git a/util.js b/util.js index 887503e..c11c140 100644 --- a/util.js +++ b/util.js @@ -7,7 +7,9 @@ module.exports = { rewrite: rewrite, rewriteFile: rewriteFile, appName: appName, - capitalize: capitalize + capitalize: capitalize, + capitalizeClass: capitalizeClass, + capitalizeFile: capitalizeFile }; function rewriteFile (args) { @@ -60,8 +62,21 @@ function rewrite (args) { return lines.join('\n'); } -function capitalize(string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); +function capitalize(str) { + 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) {