Permalink
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...
1 parent 8b9cf57 commit 1282075da54790419edb5599b76b2cd83eef530e @larzconwell larzconwell committed Jul 9, 2012
View
@@ -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
@@ -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
@@ -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
@@ -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
Oops, something went wrong.

1 comment on commit 1282075

@larzconwell
Contributor

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.