Permalink
Browse files

syntax tuning

  • Loading branch information...
1 parent 3bff4d6 commit 1f387cf5b8c08805d58560c719f5fb972753b47e @ben-lin ben-lin committed Jun 28, 2012
View
@@ -51,14 +51,13 @@ module.exports = function ( app, callback ){
// check if the dir exist, if it does remove it
flow.series( function ( args, next ){
- if( path.existsSync( tmp_dir )){
- rmdir( tmp_dir, function ( err, dirs, files ){
- if( err ) throw err;
- next();
- });
- }else{
+ if( !path.existsSync( tmp_dir )) return next();
+
+ rmdir( tmp_dir, function ( err, dirs, files ){
+ if( err ) throw err;
+
next();
- }
+ });
}).
// create assets dir
@@ -102,4 +101,4 @@ module.exports = function ( app, callback ){
lib.helpers( app ,css, js, callback );
}
-};
+};
View
@@ -29,27 +29,27 @@ module.exports = {
packer( arg );
}, {
- input : input,
+ input : input,
output : tmp_dir + group + '.' + type,
- type : type
+ type : type
});
});
},
compare_and_replace : function ( fs, config, assets, type, tmp_dir, compare ){
Object.keys( assets ).forEach( function ( group ){
- if( compare ){
- var tmp = fs.readFileSync( tmp_dir + group + '.' + type, 'utf8' );
-
- fs.writeFileSync( PUB_DIR + config.path.output + '/' + group +
- '-' + assets[ group ] + '.' + type, tmp );
- }else{
+ if( !compare ){
// ex. assets[ group ] = version.css.common -> 32 rand str
- fs.renameSync(
+ return fs.renameSync(
tmp_dir + group + '.' + type,
PUB_DIR + config.path.output + '/' + group + '-' + assets[ group ] + '.' + type
);
}
+
+ var tmp = fs.readFileSync( tmp_dir + group + '.' + type, 'utf8' );
+
+ fs.writeFileSync( PUB_DIR + config.path.output + '/' + group +
+ '-' + assets[ group ] + '.' + type, tmp );
});
},
@@ -162,7 +162,7 @@ module.exports = {
helpers : function ( app ,css, js, callback ){
app.helpers({
css : css,
- js : js
+ js : js
});
app.dynamicHelpers({
@@ -15,21 +15,18 @@ module.exports = {
var action = args.shift();
if( typeof action == 'undefined' || action == null ){
- console.log(
+ return console.log(
utils.$alert( 'error' ) + ' \'' +
'Generator not specified, available generators: ', self.list()
);
- }else{
- if( self.exists( action )){
- self.execute( action, args );
- }else{
- console.log(
- utils.$alert( 'error' ) + ' \'' +
- 'Generator "' + action + '" not found, available generators: ', self.list()
- );
-
- }
}
+
+ if( self.exists( action )) return self.execute( action, args );
+
+ console.log(
+ utils.$alert( 'error' ) + ' \'' +
+ 'Generator "' + action + '" not found, available generators: ', self.list()
+ );
});
},
View
@@ -32,16 +32,14 @@ _ = {
},
valid_name : function ( name, regex ){
- if( regex.test( name )){
- console.log(
- utils.$alert( 'error' ) + ' \'' +
- name + '\' contains invalid characters.'
- );
+ if( !regex.test( name )) return name;
- return process.exit( 0 );
- }
+ console.log(
+ utils.$alert( 'error' ) + ' \'' +
+ name + '\' contains invalid characters.'
+ );
- return name;
+ process.exit( 0 );
}
};
@@ -84,7 +82,7 @@ out = {
);
console.log( 'Usage example: coke g ' + msg );
- return process.exit( 0 );
+ process.exit( 0 );
}
},
@@ -98,18 +96,18 @@ out = {
}else if( len === 2 ){
// has namespace
return {
- namespace : tmp[ 0 ],
+ namespace : tmp[ 0 ],
controller : tmp[ 1 ]
};
- }else{
- // too many slash
- console.log(
- utils.$alert( 'error' ) +
- ' coke geneartor only supports 1 level deep namespace'
- );
-
- return process.exit( 0 );
}
+
+ // too many slash
+ console.log(
+ utils.$alert( 'error' ) +
+ ' coke geneartor only supports 1 level deep namespace'
+ );
+
+ process.exit( 0 );
},
path : function ( path, template ){
@@ -190,13 +188,13 @@ out = {
});
}
- return this.create_file( path, content );
+ this.create_file( path, content );
},
create_binary_file : function ( path, template ){
var content = fs.readFileSync( __dirname + '/templates/' + template );
- return this.create_file( path, content );
+ this.create_file( path, content );
},
format : function ( name ){
@@ -228,6 +226,6 @@ out = {
}
};
-
+out.valid_project_name = out.valid_action_name;
module.exports = out;
@@ -42,9 +42,7 @@ module.exports = {
}
// routes
- if( namespace ){
- code.push( ' });' );
- }
+ if( namespace ) code.push( ' });' );
code = code.join( '\n' );
code = src.replace(
@@ -5,17 +5,9 @@ var Application = require( CONTROLLER_DIR + 'application' );
module.exports = Application.extend({
init : function ( before, after ){
- after( this.validation, {
- only : [ 'create', 'update' ]
- });
-
- after( this.unique, {
- only : [ 'create', 'update' ]
- });
-
- after( this.record_not_found, {
- except : [ 'new', 'create', 'index' ]
- });
+ after( this.validation, { only : [ 'create', 'update' ]});
+ after( this.unique, { only : [ 'create', 'update' ]});
+ after( this.record_not_found, { except : [ 'new', 'create', 'index' ]});
},
'new' : function ( req, res, next ){
@@ -25,10 +17,7 @@ module.exports = Application.extend({
create : function ( req, res, next ){
CAPITAL.create_or_update( new CAPITAL(), req.body.SINGULAR,
function ( err, SINGULAR ){
- if( err ){
- next( err );
- return;
- }
+ if( err ) return next( err );
req.flash( 'flash-info', 'CAPITAL created' );
res.redirect( '/VIEW_PATH/' + SINGULAR._id );
@@ -37,10 +26,7 @@ module.exports = Application.extend({
index : function ( req, res, next ){
CAPITAL.find( function ( err, PLURAL ){
- if( err ){
- next( err );
- return;
- }
+ if( err ) return next( err );
res.render( 'VIEW_PATH/index', {
PLURAL : PLURAL
@@ -51,11 +37,9 @@ module.exports = Application.extend({
show : function ( req, res, next ){
CAPITAL.findById( req.params.id , function ( err, SINGULAR ){
if( SINGULAR ){
- res.render( 'VIEW_PATH/show', {
+ return res.render( 'VIEW_PATH/show', {
SINGULAR : SINGULAR
});
-
- return;
}
req.msg = 'User';
@@ -66,11 +50,9 @@ module.exports = Application.extend({
edit : function ( req, res, next ){
CAPITAL.findById( req.params.id , function ( err, SINGULAR ){
if( SINGULAR ){
- res.render( 'VIEW_PATH/edit', {
+ return res.render( 'VIEW_PATH/edit', {
SINGULAR : SINGULAR
});
-
- return;
}
req.msg = 'User';
@@ -81,18 +63,13 @@ module.exports = Application.extend({
update : function ( req, res, next ){
CAPITAL.findById( req.params.id , function ( err, SINGULAR ){
if( SINGULAR ){
- CAPITAL.create_or_update( SINGULAR, req.body.SINGULAR,
+ return CAPITAL.create_or_update( SINGULAR, req.body.SINGULAR,
function ( err, SINGULAR ){
- if( err ){
- next( err );
- return;
- }
+ if( err ) return next( err );
req.flash( 'flash-info', 'CAPITAL updated' );
res.redirect( '/VIEW_PATH/' + SINGULAR._id );
});
-
- return;
}
req.msg = 'User';
@@ -103,17 +80,12 @@ module.exports = Application.extend({
destroy : function ( req, res, next ){
CAPITAL.findById( req.params.id , function ( err, SINGULAR ){
if( SINGULAR ){
- SINGULAR.remove( function ( err, SINGULAR ){
- if( err ){
- next( err );
- return;
- }
+ return SINGULAR.remove( function ( err, SINGULAR ){
+ if( err ) return next( err );
req.flash( 'flash-info', 'CAPITAL deleted' );
res.redirect( '/VIEW_PATH' );
});
-
- return;
}
req.msg = 'User';
View
@@ -9,19 +9,13 @@ var files = fs.readdirSync( path );
var middleware = {};
-
-
files.forEach( function ( file ){
- var name;
-
if( UTILS.regex.is_js_file.test( file )){
- name = file.replace( '.js', '' );
+ var name = file.replace( '.js', '' );
middleware[ name ] = require( path + file );
LOG.sys( 'Building middleware: ' + name );
}
});
-
-
-module.exports = middleware;
+module.exports = middleware;
View
@@ -10,7 +10,6 @@ var path = BASE_DIR + 'app/models/';
module.exports = function ( callback ){
var files = fs.readdirSync( path );
- var url;
files.forEach( function ( file ){
if( UTILS.regex.is_js_file.test( file )){
@@ -23,7 +22,7 @@ module.exports = function ( callback ){
throw new Error( 'Database name contains illegal characters' );
}
- url = 'mongodb://';
+ var url = 'mongodb://';
if( config.username && config.username.length > 0 ){
url += config.username + ':' + config.password + '@';
@@ -32,19 +31,18 @@ module.exports = function ( callback ){
url += ( config.host || 'localhost' ) + ':' + ( config.port || 27017 );
url += '/' + config.db;
- if( config.db ){
- mongoose.connect( url, function ( err ){
- if( err ){
- LOG.error( 500, '[model][mongoose] Connection error', err );
- return;
- }
-
- LOG.sys( 'All models loaded' );
- LOG.sys( 'Database connected at: ' + url );
- callback();
- });
- }else{
+ if( !config.db ){
LOG.sys( 'Database not specified' );
- callback();
+ return callback();
}
+
+ mongoose.connect( url, function ( err ){
+ if( err ){
+ return LOG.error( 500, '[model][mongoose] Connection error', err );
+ }
+
+ LOG.sys( 'All models loaded' );
+ LOG.sys( 'Database connected at: ' + url );
+ callback();
+ });
};
Oops, something went wrong.

0 comments on commit 1f387cf

Please sign in to comment.