Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added custom plural for controllers, fixed debug message syntax

  • Loading branch information...
commit d241386fef54723981e8b9102d45afdb58efd327 1 parent 86a3447
@moul authored
Showing with 17 additions and 8 deletions.
  1. +12 −4 lib/app.js
  2. +5 −4 src/app.coffee
View
16 lib/app.js
@@ -70,6 +70,7 @@
this.obj = require("" + this.config.sub.path);
this.config.sub.name = this.obj.name || name;
this.config.sub.prefix = this.obj.prefix || '';
+ this.config.sub.plural = this.obj.plural || ("" + this.config.sub.name + "s");
this.config.locals.config = this.config;
this.config.locals.sub = this.config.sub;
this.app = express();
@@ -107,7 +108,7 @@
utils.deepExtend(this.config.locals, this.obj.locals);
}
for (key in this.obj) {
- if (~['open', 'name', 'prefix', 'engine', 'before', 'locals', 'custom', 'before_all', 'before_any_child'].indexOf(key)) {
+ if (~['open', 'name', 'plural', 'prefix', 'engine', 'before', 'locals', 'custom', 'before_all', 'before_any_child'].indexOf(key)) {
continue;
}
method = 'get';
@@ -119,10 +120,10 @@
pathname = "/" + this.config.sub.name + "/:" + this.config.sub.name + "_id";
break;
case "list":
- pathname = "/" + this.config.sub.name + "s";
+ pathname = "/" + this.config.sub.plural;
break;
case "list_json":
- pathname = "/" + this.config.sub.name + "s/json";
+ pathname = "/" + this.config.sub.plural + "/json";
break;
case 'edit':
pathname = "/" + this.config.sub.name + "/:" + this.config.sub.name + "_id/edit";
@@ -131,6 +132,10 @@
method = 'put';
pathname = "/" + this.config.sub.name + "/:" + this.config.sub.name + "_id";
break;
+ case 'delete':
+ method = 'delete';
+ pathname = "/" + this.config.sub.name + "/:" + this.config.sub.name + "_id";
+ break;
case 'create':
method = 'post';
pathname = "/" + this.config.sub.name;
@@ -155,7 +160,7 @@
callback: null
};
entry = _.defaults(entry, default_values);
- this.logger.log('info', "" + this.config.sub.path + ": custom handler " + entry.method + "(" + entry.path + " -> " + (typeof entry.callback) + ")");
+ this.logger.log('info', "" + this.config.sub.path + ": custom " + entry.method + "(" + entry.path + ") -> " + (typeof entry.callback));
this.app[entry.method](entry.path, entry.callback);
}
}
@@ -457,6 +462,9 @@
for (_j = 0, _len1 = hoganTemplateRenderers.length; _j < _len1; _j++) {
htr = hoganTemplateRenderers[_j];
_this.logger.log('info', htr);
+ if (_this.config.debug) {
+ htr.read();
+ }
res.send(htr.getSharedTemplates());
return;
}
View
9 src/app.coffee
@@ -39,6 +39,7 @@ class ksSubApp
@obj = require "#{@config.sub.path}"
@config.sub.name = @obj.name || name
@config.sub.prefix = @obj.prefix || ''
+ @config.sub.plural = @obj.plural || "#{@config.sub.name}s"
@config.locals.config = @config
@config.locals.sub = @config.sub
@app = do express
@@ -62,7 +63,7 @@ class ksSubApp
utils.deepExtend @config.locals, @obj.locals
for key of @obj
- if ~['open', 'name', 'prefix', 'engine', 'before', 'locals', 'custom', 'before_all', 'before_any_child'].indexOf key
+ if ~['open', 'name', 'plural', 'prefix', 'engine', 'before', 'locals', 'custom', 'before_all', 'before_any_child'].indexOf key
continue
method = 'get'
switch key
@@ -71,9 +72,9 @@ class ksSubApp
when "show"
pathname = "/#{@config.sub.name}/:#{@config.sub.name}_id"
when "list"
- pathname = "/#{@config.sub.name}s"
+ pathname = "/#{@config.sub.plural}"
when "list_json"
- pathname = "/#{@config.sub.name}s/json"
+ pathname = "/#{@config.sub.plural}/json"
when 'edit'
pathname = "/#{@config.sub.name}/:#{@config.sub.name}_id/edit"
when 'update'
@@ -100,7 +101,7 @@ class ksSubApp
path: null
callback: null
entry = _.defaults entry, default_values
- @logger.log 'info', "#{@config.sub.path}: custom handler #{entry.method}(#{entry.path} -> #{typeof(entry.callback)})"
+ @logger.log 'info', "#{@config.sub.path}: custom #{entry.method}(#{entry.path}) -> #{typeof(entry.callback)}"
@app[entry.method] entry.path, entry.callback
@app.locals = @config.locals
#@app.use express.compiler { src: "#{@config.sub.path}/public", enable: ["coffeescript"] }
Please sign in to comment.
Something went wrong with that request. Please try again.