Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix old Fleegix lib code for template adapters

Created new command `scaffold` that generates a complete scaffold

Model, Resource and Scaffold now have a new set of options that are model properties

ex: geddy model user name admin:boolean
The example above generates a user model with the given properties.
Generated models have a default ID property with a 'string' type and if a custom ID property is given
it overrides the default.
If no type is given then it defaults to 'string'

Note: This commit is mainly just to fix the fleegix errors found. Closes #124
  • Loading branch information...
commit 1282075da54790419edb5599b76b2cd83eef530e 1 parent 8b9cf57
@larzconwell larzconwell authored
View
60 bin/cli.js
@@ -17,6 +17,8 @@ var cwd = process.cwd()
, opts
, usage
, cmd
+ , engineCmd
+ , modelCmd
, filepath
, die
, start;
@@ -46,7 +48,9 @@ usage = [
, 'Commands:'
, ' app [name] Create a new Geddy application'
, ' resource [name] Create a new resource. A resource includes'
- , ' the views, model, controller and a route'
+ , ' a model, controller and route'
+ , ' scaffold [name] Create a new scaffolding. Scaffolding includes'
+ , ' the views, a model, controller and route'
, ' secret Generate a new application secret in'
, ' `congig/environment`'
, ' controller [name] Generate a new controller including views'
@@ -59,8 +63,10 @@ usage = [
, ' this usage dialog'
, ' geddy -p 3000 Start Geddy on port 3000'
, ' geddy -e production Start Geddy in production mode'
- , ' geddy resource users Generate a users resource using EJS templates'
- , ' geddy -j resource users Generate a users resource using Jade templates'
+ , ' geddy -j scaffold user Generate a users scaffolding using Jade templates'
+ , ' geddy resource user name admin:boolean'
+ , ' Generate a users resource with the model properties'
+ , ' name as a string and admin as a boolean'
, ''
].join('\n');
@@ -107,6 +113,7 @@ if(opts.version) die(geddy.version);
// `geddy app foo` or `geddy resource bar` etc. -- run generators
if(cmds.length) {
+ // Get templates Jake file
filepath = path.normalize(path.join(__dirname, '..', 'templates', 'Jakefile'));
// Wrap quotes in case path has spaces
@@ -118,40 +125,41 @@ if(cmds.length) {
throw new Error(cmds[0] + ' command requires another argument.');
}
+ // Add engines to command
+ if(opts.jade) {
+ engineCmd = ',' + 'jade';
+ } else if(opts.handle) {
+ engineCmd = ',' + 'handlebars';
+ } else if(opts.mustache) {
+ engineCmd = ',' + 'mustache';
+ } else engineCmd = '';
+
+ // Get the model properties
+ if(cmds.slice(2).length > 0) {
+ modelCmd = ',' + cmds.slice(2).join(' ');
+ } else modelCmd = '';
+
+ // Add Jake argument based on commands
switch(cmds[0]) {
case 'app':
// Generating application
- cmd += 'gen:app[' + cmds[1];
-
- if(opts.jade) cmd += ',' + 'jade';
- if(opts.handle) cmd += ',' + 'handlebars';
- if(opts.mustache) cmd += ',' + 'mustache';
-
- cmd += ']';
+ cmd += '"gen:app[' + cmds[1] + engineCmd + ']"';
break;
case 'resource':
- // Generating resources
- cmd += 'gen:resource[' + cmds[1];
-
- if(opts.jade) cmd += ',' + 'jade';
- if(opts.handle) cmd += ',' + 'handlebars';
- if(opts.mustache) cmd += ',' + 'mustache';
-
- cmd += ']';
+ // Generating resource
+ cmd += '"gen:resource[' + cmds[1] + modelCmd + ']"';
+ break;
+ case 'scaffold':
+ // Generating application
+ cmd += '"gen:scaffold[' + cmds[1] + engineCmd + modelCmd + ']"';
break;
case 'controller':
// Generating controller
- cmd += 'gen:bareController[' + cmds[1];
-
- if(opts.jade) cmd += ',' + 'jade';
- if(opts.handle) cmd += ',' + 'handlebars';
- if(opts.mustache) cmd += ',' + 'mustache';
-
- cmd += ']';
+ cmd += '"gen:bareController[' + cmds[1] + engineCmd + ']"';
break;
case 'model':
// Generating model
- cmd += 'gen:model[' + cmds[1] + ']';
+ cmd += '"gen:model[' + cmds[1] + modelCmd + ']"';
break;
case 'secret':
// Generating new app secret
View
79 lib/template/adapters/ejs.js
@@ -30,88 +30,11 @@ ejs.Template = function(params) {
this.afterLoaded = params.afterLoaded;
this.source = '';
this.markup = undefined;
- // Note: If you don't want to use Fleegix.js,
- // override getTemplateTextFromNode to use
- // textarea node value for template text
- this.templateText = params.text || this.getTemplateTextFromNode(params.node);
-
- // Try to get from URL if no template text
- if(typeof this.templateText == 'undefined') {
- // If you don't want to use Fleegix.js,
- // override getTemplateTextFromUrl to use
- // files for template text
- this.getTemplateTextFromUrl(params);
- }
+ this.templateText = params.text;
};
ejs.Template.prototype = new function() {
- this.getTemplateTextFromNode = function(node) {
- // Requires the fleegix.xhr module
- if(typeof fleegix.string == 'undefined') throw 'Requires fleegix.string module.';
- var ret;
-
- if(node) {
- ret = node.value;
- ret = fleegix.string.unescapeXML(ret);
- ret = fleegix.string.trim(ret);
- }
- return ret;
- };
-
- this.getTemplateTextFromUrl = function(params) {
- // Requires the fleegix.xhr module
- if (typeof fleegix.xhr == 'undefined') throw 'Requires fleegix.xhr module.';
- var self = this
- , url = params.url
- , noCache = params.preventCache || false;
-
- // If cache is found and caching is on
- if (text && !noCache) {
- this.templateText = text;
- }
- // Otherwise get the text
- else {
- var opts;
- var callback = function(s) {
- // Callback for setting templateText and caching
- // - used for both sync and async loading
- self.templateText = s;
- ejs.templateTextCache[url] = s;
-
- // Use afterLoaded hook if set
- if (typeof self.afterLoaded == 'function') {
- self.afterLoaded();
- }
- };
-
- if(params.async) {
- opts = {
- url: url
- , method: 'GET'
- , preventCache: noCache
- , async: true
- , handleSuccess: callback
- };
- // Get template text asynchronously, wait for
- // loading to exec the callback
- fleegix.xhr.send(opts);
- }
- else {
- opts = {
- url: url
- , method: 'GET'
- , preventCache: noCache
- , async: false
- };
- // Get the template text inline and pass directly to
- // the callback
- text = fleegix.xhr.send(opts);
- callback(text);
- }
- }
- };
-
this.process = function(params) {
params = params || {}
var domNode = params.node
View
79 lib/template/adapters/handlebars.js
@@ -37,88 +37,11 @@ jade.Template = function(params) {
this.afterLoaded = params.afterLoaded;
this.source = '';
this.markup = undefined;
- // Note: If you don't want to use Fleegix.js,
- // override getTemplateTextFromNode to use
- // textarea node value for template text
- this.templateText = params.text || this.getTemplateTextFromNode(params.node);
-
- // Try to get from URL if no template text
- if(typeof this.templateText == 'undefined') {
- // If you don't want to use Fleegix.js,
- // override getTemplateTextFromUrl to use
- // files for template text
- this.getTemplateTextFromUrl(params);
- }
+ this.templateText = params.text;
};
jade.Template.prototype = new function() {
- this.getTemplateTextFromNode = function(node) {
- // Requires the fleegix.xhr module
- if(typeof fleegix.string == 'undefined') throw 'Requires fleegix.string module.';
- var ret;
-
- if(node) {
- ret = node.value;
- ret = fleegix.string.unescapeXML(ret);
- ret = fleegix.string.trim(ret);
- }
- return ret;
- };
-
- this.getTemplateTextFromUrl = function(params) {
- // Requires the fleegix.xhr module
- if (typeof fleegix.xhr == 'undefined') throw 'Requires fleegix.xhr module.';
- var self = this
- , url = params.url
- , noCache = params.preventCache || false;
-
- // If cache is found and caching is on
- if (text && !noCache) {
- this.templateText = text;
- }
- // Otherwise get the text
- else {
- var opts;
- var callback = function(s) {
- // Callback for setting templateText and caching
- // - used for both sync and async loading
- self.templateText = s;
- ejs.templateTextCache[url] = s;
-
- // Use afterLoaded hook if set
- if (typeof self.afterLoaded == 'function') {
- self.afterLoaded();
- }
- };
-
- if(params.async) {
- opts = {
- url: url
- , method: 'GET'
- , preventCache: noCache
- , async: true
- , handleSuccess: callback
- };
- // Get template text asynchronously, wait for
- // loading to exec the callback
- fleegix.xhr.send(opts);
- }
- else {
- opts = {
- url: url
- , method: 'GET'
- , preventCache: noCache
- , async: false
- };
- // Get the template text inline and pass directly to
- // the callback
- text = fleegix.xhr.send(opts);
- callback(text);
- }
- }
- };
-
this.process = function(params) {
params = params || {}
var domNode = params.node
View
79 lib/template/adapters/jade.js
@@ -37,88 +37,11 @@ jade.Template = function(params) {
this.afterLoaded = params.afterLoaded;
this.source = '';
this.markup = undefined;
- // Note: If you don't want to use Fleegix.js,
- // override getTemplateTextFromNode to use
- // textarea node value for template text
- this.templateText = params.text || this.getTemplateTextFromNode(params.node);
-
- // Try to get from URL if no template text
- if(typeof this.templateText == 'undefined') {
- // If you don't want to use Fleegix.js,
- // override getTemplateTextFromUrl to use
- // files for template text
- this.getTemplateTextFromUrl(params);
- }
+ this.templateText = params.text;
};
jade.Template.prototype = new function() {
- this.getTemplateTextFromNode = function(node) {
- // Requires the fleegix.xhr module
- if(typeof fleegix.string == 'undefined') throw 'Requires fleegix.string module.';
- var ret;
-
- if(node) {
- ret = node.value;
- ret = fleegix.string.unescapeXML(ret);
- ret = fleegix.string.trim(ret);
- }
- return ret;
- };
-
- this.getTemplateTextFromUrl = function(params) {
- // Requires the fleegix.xhr module
- if (typeof fleegix.xhr == 'undefined') throw 'Requires fleegix.xhr module.';
- var self = this
- , url = params.url
- , noCache = params.preventCache || false;
-
- // If cache is found and caching is on
- if (text && !noCache) {
- this.templateText = text;
- }
- // Otherwise get the text
- else {
- var opts;
- var callback = function(s) {
- // Callback for setting templateText and caching
- // - used for both sync and async loading
- self.templateText = s;
- ejs.templateTextCache[url] = s;
-
- // Use afterLoaded hook if set
- if (typeof self.afterLoaded == 'function') {
- self.afterLoaded();
- }
- };
-
- if(params.async) {
- opts = {
- url: url
- , method: 'GET'
- , preventCache: noCache
- , async: true
- , handleSuccess: callback
- };
- // Get template text asynchronously, wait for
- // loading to exec the callback
- fleegix.xhr.send(opts);
- }
- else {
- opts = {
- url: url
- , method: 'GET'
- , preventCache: noCache
- , async: false
- };
- // Get the template text inline and pass directly to
- // the callback
- text = fleegix.xhr.send(opts);
- callback(text);
- }
- }
- };
-
this.process = function(params) {
params = params || {}
var domNode = params.node
View
79 lib/template/adapters/mustache.js
@@ -37,88 +37,11 @@ jade.Template = function(params) {
this.afterLoaded = params.afterLoaded;
this.source = '';
this.markup = undefined;
- // Note: If you don't want to use Fleegix.js,
- // override getTemplateTextFromNode to use
- // textarea node value for template text
- this.templateText = params.text || this.getTemplateTextFromNode(params.node);
-
- // Try to get from URL if no template text
- if(typeof this.templateText == 'undefined') {
- // If you don't want to use Fleegix.js,
- // override getTemplateTextFromUrl to use
- // files for template text
- this.getTemplateTextFromUrl(params);
- }
+ this.templateText = params.text;
};
jade.Template.prototype = new function() {
- this.getTemplateTextFromNode = function(node) {
- // Requires the fleegix.xhr module
- if(typeof fleegix.string == 'undefined') throw 'Requires fleegix.string module.';
- var ret;
-
- if(node) {
- ret = node.value;
- ret = fleegix.string.unescapeXML(ret);
- ret = fleegix.string.trim(ret);
- }
- return ret;
- };
-
- this.getTemplateTextFromUrl = function(params) {
- // Requires the fleegix.xhr module
- if (typeof fleegix.xhr == 'undefined') throw 'Requires fleegix.xhr module.';
- var self = this
- , url = params.url
- , noCache = params.preventCache || false;
-
- // If cache is found and caching is on
- if (text && !noCache) {
- this.templateText = text;
- }
- // Otherwise get the text
- else {
- var opts;
- var callback = function(s) {
- // Callback for setting templateText and caching
- // - used for both sync and async loading
- self.templateText = s;
- ejs.templateTextCache[url] = s;
-
- // Use afterLoaded hook if set
- if (typeof self.afterLoaded == 'function') {
- self.afterLoaded();
- }
- };
-
- if(params.async) {
- opts = {
- url: url
- , method: 'GET'
- , preventCache: noCache
- , async: true
- , handleSuccess: callback
- };
- // Get template text asynchronously, wait for
- // loading to exec the callback
- fleegix.xhr.send(opts);
- }
- else {
- opts = {
- url: url
- , method: 'GET'
- , preventCache: noCache
- , async: false
- };
- // Get the template text inline and pass directly to
- // the callback
- text = fleegix.xhr.send(opts);
- callback(text);
- }
- }
- };
-
this.process = function(params) {
params = params || {}
var domNode = params.node
View
7 lib/utils/object.js
@@ -30,8 +30,11 @@ var object = new (function () {
key = i, value = otherObject[key];
try {
- // Update value of object to the one from otherObject
- object[key] = typeof value === 'object' ? merge(object[key], value) : value;
+ // If value is an object
+ if(typeof value === 'object' && !value instanceof Array) {
+ // Update value of object to the one from otherObject
+ object[key] = merge(object[key], value);
+ } else object[key] = value;
} catch(err) {
// Object isn't set so set it
object[key] = value;
View
240 templates/Jakefile
@@ -24,7 +24,7 @@ namespace('gen', function () {
// Render with the right model name
templ = new adapter({ data: {ext: '.ejs'}, text: text, templato: templato });
- templ.process({names: names, bare: bare});
+ templ.process({names: names, bare: bare, properties: options.properties});
// Write file
filePath = path.join('app', dirname, names.filename[options.inflection] + '.js');
@@ -53,6 +53,38 @@ namespace('gen', function () {
};
};
+ var _formatModelProperties = function(properties) {
+ if(!properties) return { 'id': 'string' };
+
+ var itemsArr = properties.split(' ')
+ , properties = {}
+ , name
+ , type
+ , customId
+ , i
+ , value;
+
+ // Go over each item and parse it's name and type and add to `arr`
+ for(i in itemsArr) {
+ value = itemsArr[i];
+ name = value.replace(/:.*/g, '');
+ type = value.replace(/[a-zA-Z]*:?/, '');
+
+ // Set defaults and alias's
+ if(!type) type = 'string';
+ if(type === 'integer') type = 'number';
+
+ properties[name] = type;
+ }
+
+ // Check to see if a `id` property exists if not, add it
+ // Note: reverseMerge moves the default(or changed default) objects to the beginning
+ // of the object. Which is useful for our forEach hack in the model template
+ properties = utils.object.reverseMerge(properties, { 'id': 'string' });
+
+ return properties;
+ };
+
// Creates a new Geddy app scaffold
task('app', [], function(name, engine) {
if(!name) throw new Error('No app-name specified.');
@@ -90,20 +122,96 @@ namespace('gen', function () {
console.log('Created app ' + name + '.');
});
- // Creates a resource(Model, Controller, Views and resource route)
- task('resource', function(name, engine) {
- jake.Task['gen:model'].invoke(name);
+ // Creates a resource with a model, controller and a resource route
+ task('resource', function(name, modelProperties) {
+ jake.Task['gen:model'].invoke(name, modelProperties);
jake.Task['gen:controller'].invoke(name);
jake.Task['gen:route'].invoke(name);
- jake.Task['gen:views'].invoke(name, { engine: engine });
+
+ // Create views folder but not actions
+ var names = _getInflections(name)
+ jake.mkdirP(path.join('app', 'views', names.filename.plural));
+ console.log('Created ' + names.filename.plural + ' view folder.');
+ });
+
+ // Creates a full scaffold with views, a model, controller and a resource route
+ task('scaffold', function(name, engine, modelProperties) {
+ var jsEnvironment = path.normalize('config/environment.js')
+ , coffeeEnvironment = path.normalize('config/environment.coffee')
+ , environmentPath
+ , environmentArr
+ , text
+ , splitText
+ , dbContent = '';
+
+ // Check if the environment file exists
+ if(existsSync(jsEnvironment)) {
+ environmentPath = jsEnvironment;
+ } else if(existsSync(coffeeEnvironment)) {
+ environmentPath = coffeeEnvironment;
+ }
+
+ jake.Task['gen:modelScaffold'].invoke(name, modelProperties);
+ jake.Task['gen:controllerScaffold'].invoke(name);
+ jake.Task['gen:route'].invoke(name);
+ jake.Task['gen:views'].invoke(name, {engine: engine });
+
+ // Add the following line to `config/environment.js/.coffee`
+ if(environmentPath) {
+ text = fs.readFileSync(environmentPath, 'utf8').toString();
+
+ // Create text to add to environment
+ if(environmentPath.match('.coffee')) {
+ dbContent = [
+ ' db:'
+ , ' mongo:'
+ , ' db: \'' + name + '\''
+ ].join('\n');
+ splitText = 'config = ';
+ } else if(environmentPath.match('.js')) {
+ dbContent = [
+ ' db: {'
+ , ' mongo: {'
+ , ' db: \'' + name + '\''
+ , ' }'
+ , ' }'
+ ].join('\n');
+ splitText = 'var config = {';
+ }
+
+ // Don't add the db config over and over
+ if(text.indexOf(dbContent) == -1) {
+ environmentArr = text.split(splitText);
+ environmentArr[0] += splitText + '\n' + dbContent + '\n';
+
+ text = environmentArr.join('');
+ fs.writeFileSync(environmentPath, text, 'utf8');
+
+ console.log('Database configuration added to ' + environmentPath);
+ } else console.log('(Database configuration already set in ' + environmentPath + ')');
+ }
});
- task('model', [], function(name) {
- _writeTemplate(name, 'resource_model', 'models', { inflection: 'singular' });
+ task('model', [], function(name, properties) {
+ _writeTemplate(name, 'resource/model', 'models', {
+ inflection: 'singular'
+ , properties: _formatModelProperties(properties)
+ });
+ });
+
+ task('modelScaffold', [], function(name, properties) {
+ _writeTemplate(name, 'scaffold/model', 'models', {
+ inflection: 'singular'
+ , properties: _formatModelProperties(properties)
+ });
});
task('controller', [], function(name) {
- _writeTemplate(name, 'resource_controller', 'controllers', { inflection: 'plural', bare: false });
+ _writeTemplate(name, 'resource/controller', 'controllers', { inflection: 'plural', bare: false });
+ });
+
+ task('controllerScaffold', [], function(name) {
+ _writeTemplate(name, 'scaffold/controller', 'controllers', { inflection: 'plural', bare: false });
});
task('route', [], function(name, options) {
@@ -111,33 +219,56 @@ namespace('gen', function () {
var names = _getInflections(name)
, routeType = options.bare ? 'Bare' : 'Resource'
- , filePath = path.normalize('config/router.js')
- , text = fs.readFileSync(filePath, 'utf8').toString()
- , newRoute
- , routeArr;
-
- if (options.bare) {
- newRoute = 'router.match(\'/' + names.filename.plural +
- '\').to({controller: \'' + names.constructor.plural +
- '\', action: \'index\'});';
- } else newRoute = 'router.resource(\'' + names.filename.plural + '\');'
-
- // Don't add the same route over and over
- if(text.indexOf(newRoute) == -1) {
- // Add the new resource route just above the export
- routerArr = text.split('exports.router');
- routerArr[0] += newRoute + '\n';
-
- text = routerArr.join('exports.router');
- fs.writeFileSync(filePath, text, 'utf8');
-
- console.log(routeType + ' ' + names.filename.plural +
- ' route added to ' + filePath);
- }
- else {
- console.log('(' + routeType + ' ' + names.filename.plural +
- ' route already defined in ' + filePath + ')');
+ , jsRouter = path.normalize('config/router.js')
+ , coffeeRouter = path.normalize('config/router.coffee')
+ , routerPath
+ , routerArr
+ , text
+ , splitText
+ , newRoute;
+
+ // Check if the router file exists
+ if(existsSync(jsRouter)) {
+ routerPath = jsRouter;
+ } else if(existsSync(coffeeRouter)) {
+ routerPath = coffeeRouter;
}
+
+ if(routerPath) {
+ text = fs.readFileSync(routerPath, 'utf8');
+
+ if(routerPath.match('.coffee')) {
+ if(options.bare) {
+ newRoute = 'router.match(\'/' + names.filename.plural +
+ '\').to controller: \'' + names.constructor.plural +
+ '\', action: \'index\'';
+ } else newRoute = 'router.resource \'' + names.filename.plural + '\''
+ } else if(routerPath.match('.js')) {
+ if(options.bare) {
+ newRoute = 'router.match(\'/' + names.filename.plural +
+ '\').to({controller: \'' + names.constructor.plural +
+ '\', action: \'index\'});';
+ } else newRoute = 'router.resource(\'' + names.filename.plural + '\');';
+ }
+
+ // Don't add the same route over and over
+ if(text.indexOf(newRoute) == -1) {
+ // Add the new resource route just above the export
+ routerArr = text.split('exports.router');
+ routerArr[0] += newRoute + '\n';
+
+ text = routerArr.join('exports.router');
+ fs.writeFileSync(routerPath, text, 'utf8');
+
+ console.log(routeType + ' ' + names.filename.plural +
+ ' route added to ' + routerPath);
+ }
+ else {
+ console.log('(' + routeType + ' ' + names.filename.plural +
+ ' route already defined in ' + routerPath + ')');
+ }
+
+ } else console.log('There is no router file to add routes too.');
});
task('views', [], function(name, options) {
@@ -192,7 +323,7 @@ namespace('gen', function () {
});
task('bareController', [], function(name, engine) {
- _writeTemplate(name, 'resource_controller', 'controllers', { inflection: 'plural', bare: true });
+ _writeTemplate(name, 'resource/controller', 'controllers', { inflection: 'plural', bare: true });
jake.Task['gen:route'].invoke(name, { bare: true });
jake.Task['gen:views'].invoke(name, { bare: true, engine: engine });
@@ -200,20 +331,39 @@ namespace('gen', function () {
// Generate a new application secret in environment.js
task('secret', [], function(name) {
- var filename = path.join(process.cwd(), 'config/environment.js')
- , conf = fs.readFileSync(filename).toString()
+ var jsEnvironment = path.normalize('config/environment.js')
+ , coffeeEnvironment = path.normalize('config/environment.coffee')
, secret = utils.string.uuid(128)
- , confArr;
+ , environmentPath
+ , environmentArr
+ , text
+ , splitText;
+
+ // Check if the environment file exists
+ if(existsSync(jsEnvironment)) {
+ environmentPath = jsEnvironment;
+ } else if(existsSync(coffeeEnvironment)) {
+ environmentPath = coffeeEnvironment;
+ }
+
+ if(environmentPath) {
+ text = fs.readFileSync(environmentPath, 'utf8').toString();
+
+ // Remove any old secret
+ text = text.replace(/\nconfig.secret.+\n/, '');
+
+ splitText = 'module.exports = config';
+ if(environmentPath.match('.js')) splitText += ';';
- // Remove any old secret
- conf = conf.replace(/\nconfig.secret.+;\n/, '');
+ environmentArr = text.split(splitText);
+ environmentArr[0] += "config.secret = '" + secret + "'";
+ environmentArr[0] += environmentPath.match('.js') ? ';\n\n' : '\n\n';
- confArr = conf.split('module.exports = config;');
- conf = confArr[0] + "config.secret = '" + secret + "';\n\n" +
- 'module.exports = config;' + confArr[1];
- fs.writeFileSync(filename, conf);
+ text = environmentArr.join(splitText);
+ fs.writeFileSync(environmentPath, text, 'utf8');
- console.log('app-secret added to environment.js config.');
+ console.log('app-secret added to ' + environmentPath + '.');
+ } else console.log('There is no environment config to add the secret too.');
});
});
View
2  templates/base/environment.js
@@ -7,5 +7,3 @@ var config = {
};
module.exports = config;
-
-
View
5 templates/resource_controller.ejs → templates/resource/controller.ejs
@@ -1,11 +1,10 @@
-
var <%= names.constructor.plural %> = function () {
this.respondsWith = ['html', 'json', 'xml', 'js', 'txt'];
this.index = function (req, resp, params) {
this.respond({params: params});
};
-<% if(!bare) { %>
+<% if(!bare) { -%>
this.add = function (req, resp, params) {
this.respond({params: params});
};
@@ -31,7 +30,7 @@ var <%= names.constructor.plural %> = function () {
this.remove = function (req, resp, params) {
this.respond({params: params});
};
-<% } %>
+<% } -%>
};
exports.<%= names.constructor.plural %> = <%= names.constructor.plural %>;
View
14 templates/resource_model.ejs → templates/resource/model.ejs
@@ -1,5 +1,17 @@
-
var <%= names.constructor.singular %> = function () {
+
+ this.defineProperties({
+<% for(var i in properties) { -%>
+<%# Hack: ID property will always be first so we will manually take care of not inserting -%>
+<%# A leading comma -%>
+<% if(i === 'id') { -%>
+ <%= i %>: {type: '<%= properties[i] %>'}
+<% } else { -%>
+ , <%= i %>: {type: '<%= properties[i] %>'}
+<% } -%>
+<% } -%>
+ });
+
/*
this.property('login', 'string', {required: true});
this.property('password', 'string', {required: true});
View
37 templates/scaffold/controller.ejs
@@ -0,0 +1,37 @@
+var <%= names.constructor.plural %> = function () {
+ this.respondsWith = ['html', 'json', 'xml', 'js', 'txt'];
+
+ this.index = function (req, resp, params) {
+ this.respond({params: params});
+ };
+<% if(!bare) { -%>
+ this.add = function (req, resp, params) {
+ this.respond({params: params});
+ };
+
+ this.create = function (req, resp, params) {
+ // Save the resource, then display index page
+ this.redirect({controller: this.name});
+ };
+
+ this.show = function (req, resp, params) {
+ this.respond({params: params});
+ };
+
+ this.edit = function (req, resp, params) {
+ this.respond({params: params});
+ };
+
+ this.update = function (req, resp, params) {
+ // Save the resource, then display the item page
+ this.redirect({controller: this.name, id: params.id});
+ };
+
+ this.remove = function (req, resp, params) {
+ this.respond({params: params});
+ };
+<% } -%>
+};
+
+exports.<%= names.constructor.plural %> = <%= names.constructor.plural %>;
+
View
54 templates/scaffold/model.ejs
@@ -0,0 +1,54 @@
+var <%= names.constructor.singular %> = function () {
+
+ this.defineProperties({
+<% for(var i in properties) { -%>
+<%# Hack: ID property will always be first so we will manually take care of not inserting -%>
+<%# A leading comma -%>
+<% if(i === 'id') { -%>
+ <%= i %>: {type: '<%= properties[i] %>'}
+<% } else { -%>
+ , <%= i %>: {type: '<%= properties[i] %>'}
+<% } -%>
+<% } -%>
+ });
+
+ this.adapter = "Mongo";
+
+ /*
+ this.property('login', 'string', {required: true});
+ this.property('password', 'string', {required: true});
+ this.property('lastName', 'string');
+ this.property('firstName', 'string');
+
+ this.validatesPresent('login');
+ this.validatesFormat('login', /[a-z]+/, {message: 'Subdivisions!'});
+ this.validatesLength('login', {min: 3});
+ // Use with the name of the other parameter to compare with
+ this.validatesConfirmed('password', 'confirmPassword');
+ // Use with any function that returns a Boolean
+ this.validatesWithFunction('password', function (s) {
+ return s.length > 0;
+ });
+
+ // Can define methods for instances like this
+ this.someMethod = function () {
+ // Do some stuff
+ };
+ */
+
+};
+
+/*
+// Can also define them on the prototype
+<%= names.constructor.singular %>.prototype.someOtherMethod = function () {
+ // Do some other stuff
+};
+// Can also define static methods and properties
+<%= names.constructor.singular %>.someStaticMethod = function () {
+ // Do some other stuff
+};
+<%= names.constructor.singular %>.someStaticProperty = 'YYZ';
+*/
+
+<%= names.constructor.singular %> = geddy.model.register('<%= names.constructor.singular %>', <%= names.constructor.singular %>);
+
View
19 templates/resource_controller_scaffold.ejs → templates/scaffold/old_controller.ejs
@@ -1,13 +1,12 @@
-
var <%= names.constructor.plural %> = function () {
- var _this = this;
+ var self = this;
this.respondsWith = ['html', 'json', 'js', 'txt'];
this.index = function (params) {
<%= names.constructor.singular %>.all(function (err, items) {
if (err) throw err;
params.items = items;
- _this.respond({params: params});
+ self.respond({params: params});
});
};
@@ -20,10 +19,10 @@ var <%= names.constructor.plural %> = function () {
item.save(function (err, res) {
if (err) {
params.errors = err;
- _this.transfer('add');
+ self.transfer('add');
}
else {
- _this.redirect({controller: _this.name});
+ self.redirect({controller: self.name});
}
});
};
@@ -32,7 +31,7 @@ var <%= names.constructor.plural %> = function () {
<%= names.constructor.singular %>.find(params.id, function (err, items) {
if (err) throw err;
params.item = items[0];
- _this.respond({params: params});
+ self.respond({params: params});
});
};
@@ -40,7 +39,7 @@ var <%= names.constructor.plural %> = function () {
<%= names.constructor.singular %>.find(params.id, function (err, items) {
if (err) throw err;
geddy.util.meta.mixin(params, items[0]);
- _this.respond({params: params});
+ self.respond({params: params});
});
};
@@ -48,10 +47,10 @@ var <%= names.constructor.plural %> = function () {
<%= names.constructor.singular %>.update(params.id, params, function (err, res) {
if (err) {
params.errors = err;
- _this.transfer('edit');
+ self.transfer('edit');
}
else {
- _this.redirect({controller: _this.name});
+ self.redirect({controller: self.name});
}
});
};
@@ -59,7 +58,7 @@ var <%= names.constructor.plural %> = function () {
this.remove = function (params) {
<%= names.constructor.singular %>.remove(params.id, function (err, items) {
if (err) throw err;
- _this.redirect({controller: _this.name});
+ self.redirect({controller: self.name});
});
};
View
7 test/ejs.js
@@ -16,7 +16,12 @@ var Templato = require('../deps/templato')
tests = {
- 'test rendering a single variable': function () {
+ 'test empty template render': function() {
+ var actual = render('');
+ assert.equal('', actual);
+ }
+
+, 'test rendering a single variable': function () {
var str = "<% var foo = 'FOO'; %><%= foo; %>"
, actual = render(str);
assert.equal('FOO', actual);

1 comment on commit 1282075

@larzconwell

Oh I forgot. I fixed a bug where the secret and route commands would only edit JS versions, so I added CoffeeScript support for them.

Please sign in to comment.
Something went wrong with that request. Please try again.