Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
added custom _.classify method
Browse files Browse the repository at this point in the history
_.classify uses _.titleize which lowercase the string so if the user
chooses a proper ClassName it will not rename properly
  • Loading branch information
gilbarbara authored and revathskumar committed Feb 26, 2014
1 parent dba914a commit 11dc3b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var scriptBase = require('../script-base');
var backboneUtils = require('../util.js');

var Generator = module.exports = function Generator(args, options, config) {
yeoman.generators.Base.apply(this, arguments);

this.argument('appname', { type: String, required: false });
this.appname = this.appname || path.basename(process.cwd());
this.appname = backboneUtils.classify(this.appname);

this.env.options.appPath = this.options.appPath || 'app';
this.config.set('appPath', this.env.options.appPath);
Expand Down
2 changes: 2 additions & 0 deletions script-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var Generator = module.exports = function Generator() {
}

this.setupSourceRootAndSuffix();

this._.mixin({ 'classify': backboneUtils.classify });
};

util.inherits(Generator, yeoman.generators.NamedBase);
Expand Down
10 changes: 9 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var fs = require('fs');

module.exports = {
rewrite: rewrite,
rewriteFile: rewriteFile
rewriteFile: rewriteFile,
classify: classify
};

function rewriteFile(args) {
Expand Down Expand Up @@ -58,4 +59,11 @@ function rewrite(args) {
.join('\n'));

return lines.join('\n');
}

// _.classify uses _.titleize which lowercase the string,
// so if the user chooses a proper ClassName it will not rename properly
function classify(string) {
string = string.replace(/[\W_](\w)/g, function (match) { return ' ' + match[1].toUpperCase(); }).replace(/\s/g, '');
return string.charAt(0).toUpperCase() + string.slice(1);
}

0 comments on commit 11dc3b7

Please sign in to comment.