Skip to content

Commit

Permalink
Merge pull request #104 from CleverStack/1.2.0
Browse files Browse the repository at this point in the history
Moving logic into clever-orm and clever-odm modules
  • Loading branch information
pilsy committed Jan 26, 2015
2 parents e2bd7ab + 115c926 commit 7b0eefa
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 355 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
322 changes: 15 additions & 307 deletions lib/classes/Model.js

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions lib/utils/bootstrapEnv.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
var injector = require( 'injector' )
, env = null;
var injector = require( 'injector' )
, env = null;

module.exports = function() {
module.exports = function() {
if ( env === null ) {
var path = require( 'path' )
, appRoot = path.resolve( __dirname + '/../..')
, config = require( appRoot + '/config' )
var path = require( 'path' )
, appRoot = path.resolve( __dirname + '/../..')
, config = require( appRoot + '/config' )
, packageJson = require( appRoot + '/package.json' )
, express = require( 'express' )
, app = express()
, express = require( 'express' )
, app = express()
, moduleLdr;

injector.instance( 'appRoot', appRoot );
injector.instance( 'express', express );
injector.instance( 'app', app );
injector.instance( 'config', config );
injector.instance( 'packageJson', packageJson );
injector.instance( 'Promise', require( 'bluebird') );
injector.instance( 'Exceptions', require( 'exceptions' ) );
injector.instance( 'async', require( 'async' ) );
injector.instance( '_', require( 'underscore' ) );
injector.instance( 'appRoot', appRoot );
injector.instance( 'express', express );
injector.instance( 'app', app );
injector.instance( 'config', config );
injector.instance( 'packageJson', packageJson );
injector.instance( 'Promise', require( 'bluebird') );
injector.instance( 'Exceptions', require( 'exceptions' ) );
injector.instance( 'async', require( 'async' ) );
injector.instance( '_', require( 'underscore' ) );

moduleLdr = require( './moduleLoader' ).getInstance( env );
moduleLdr = require( './moduleLoader' ).getInstance( env );

// Add our moduleLoader to the injector
injector.instance( 'moduleLoader', moduleLdr );

env = {
config: config,
express: express,
app: app,
moduleLoader: moduleLdr,
webPort: process.env.NODE_WWW_PORT || config.webPort || 8080,
packageJson: packageJson
app : app,
config : config,
express : express,
webPort : process.env.NODE_WWW_PORT || config.webPort || 8080,
packageJson : packageJson,
moduleLoader: moduleLdr
};

injector.instance( 'env', env );

// Define all core classes on the injector
var classes = require( 'classes' );
var classes = require( 'classes' );

injector.instance( 'Class', classes.Class );
injector.instance( 'Model', classes.Model );
injector.instance( 'Service', classes.Service );
injector.instance( 'Controller', classes.Controller );
injector.instance( 'Module', classes.Module );
injector.instance( 'Class', classes.Class );
injector.instance( 'Model', classes.Model );
injector.instance( 'Service', classes.Service );
injector.instance( 'Controller', classes.Controller );
injector.instance( 'Module', classes.Module );
}

return env;
Expand Down
12 changes: 6 additions & 6 deletions lib/utils/ejsRenderer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var Promise = require( 'bluebird' )
, path = require( 'path' )
, ejs = require( 'ejs' )
, appRoot = require( 'injector' ).getInstance( 'appRoot' );
var Promise = require( 'bluebird' )
, path = require( 'path' )
, ejs = require( 'ejs' )
, appRoot = require( 'injector' ).getInstance( 'appRoot' );

module.exports = function( template, data ) {
module.exports = function( template, data ) {
return new Promise( function( resolve, reject ) {
ejs.renderFile( appRoot + path.sep + template, data, function( err, html ){
if ( err ) {
reject( err );
return;
}

resolve(html);
resolve( html );
});
});
};
14 changes: 7 additions & 7 deletions lib/utils/getModulePaths.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var fs = require( 'fs' )
, path = require( 'path' )
, appRoot = path.resolve( [ __dirname, '..', '..' ].join( path.sep ) )
, packageJson = require( appRoot + '/package.json' );
var fs = require( 'fs' )
, path = require( 'path' )
, appRoot = path.resolve( path.join( __dirname, '..', '..' ) )
, packageJson = require( path.join( appRoot, 'package.json' ) );

// Use this function to get module paths
module.exports = function() {
var paths = []
, args = [].slice.call(arguments);
module.exports = function() {
var paths = []
, args = [].slice.call(arguments);

packageJson.bundledDependencies.forEach( function( name ) {
var modulePath = [ 'modules', name ].concat( args ).join( path.sep );
Expand Down
75 changes: 75 additions & 0 deletions lib/utils/modelTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var types = {
ENUM: function() {
return {
type : this.ENUM,
values : [].slice.call( arguments ),
toString: function() {
return this.type;
}
}
},
TINYINT: function( length ) {
return {
type: this.TINYINT,
length: length,
toString: function() {
return this.type;
}
}
},
BIGINT: function( length ) {
return {
type: this.BIGINT,
length: length,
toString: function() {
return this.type;
}
}
},
FLOAT: function( length, decimals ) {
var field = {
type: this.FLOAT,
length: length,
toString: function() {
return this.type;
}
}

if ( decimals !== undefined ) {
field.decimals = decimals;
}

return field;
},
DECIMAL: function( precision, scale ) {
var field = {
type: this.DECIMAL,
precision: precision,
toString: function() {
return this.type;
}
}

if ( scale !== undefined ) {
field.scale = scale;
}

return field;
},
TEXT: function() {
return {
type: this.TEXT,
toString: function() {
return this.type;
}
}
}
};

Object.keys( types ).forEach( function( type ) {
types[ type ].toString = function() {
return '' + type;
}
});

module.exports = types;
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@
"license": "BSD-2-Clause",
"dependencies": {
"async": "~0.9.0",
"bluebird": "~2.3.11",
"bluebird": "~2.9.2",
"chalk": "~0.5.1",
"clever-controller": "~1.1.6",
"clever-injector": "~1.0.2",
"cors": "~2.5.2",
"debug": "~2.1.0",
"deepmerge": "~0.2.7",
"ejs": "~1.0.0",
"ejs": "~2.2.3",
"express": "~3.4.7",
"i": "~0.3.2",
"matchdep": "~0.3.0",
"nconf": "~0.6.9",
"sendgrid": "~1.3.0",
"sendgrid": "~1.5.0",
"uberclass": "~1.0.1",
"underscore": "~1.7.0",
"validator": "~3.22.1"
"validator": "~3.28.0"
},
"devDependencies": {
"grunt-contrib-clean": "~0.5.0",
Expand Down Expand Up @@ -79,4 +79,4 @@
"bundledDependencies": [

]
}
}

0 comments on commit 7b0eefa

Please sign in to comment.