app-router
Advanced tools
Comparing version 0.1.0 to 0.1.1
44
index.js
@@ -5,3 +5,5 @@ var fs=require("fs"), | ||
showRoute = false, | ||
throwError = true; | ||
throwError = true, | ||
handler = null, | ||
useFormat = true; | ||
@@ -71,5 +73,10 @@ var interPolate = function (str, iObj) { | ||
} | ||
actions.unshift(route); | ||
if(methodType=="delete"){methodType="del"} | ||
expressApp[methodType].apply(expressApp, actions); | ||
if(handler){ | ||
handler(methodType , route, actions); | ||
}else{ | ||
if(methodType=="delete"){methodType="del"} | ||
actions.unshift(route); | ||
expressApp[methodType].apply(expressApp, actions); | ||
} | ||
if(showRoute){ | ||
@@ -150,4 +157,14 @@ console.log(methodType, route, controllers); | ||
} | ||
expressApp[resourcing[item].verb](appRoute+".:format", action); | ||
expressApp[resourcing[item].verb](appRoute, action); | ||
if(handler){ | ||
if(useFormat){ | ||
handler(resourcing[item].verb, appRoute + ".:format" , [action]); | ||
} | ||
handler(resourcing[item].verb, appRoute, [action]); | ||
}else{ | ||
if(useFormat){ | ||
expressApp[resourcing[item].verb](appRoute+".:format", action); | ||
} | ||
expressApp[resourcing[item].verb](appRoute, action); | ||
} | ||
if(showRoute){ | ||
@@ -201,3 +218,3 @@ console.log(resourcing[item].verb, appRoute + ".:format", path.join(mainPath,controller) + "#" + item); | ||
}, | ||
this.showRouteInConsole = function(bool){ | ||
this.logRoute = function(bool){ | ||
if(typeof bool == "undefined"){ | ||
@@ -219,2 +236,15 @@ bool =true; | ||
return this; | ||
}, | ||
this.letMeAttach = function(handle){ | ||
if(typeof handle == "function"){ | ||
handler=handle; | ||
} | ||
return this; | ||
}, | ||
this.useFormatInResource = function(bool){ | ||
if(typeof bool == "undefined"){ | ||
bool =true; | ||
} | ||
useFormat = Boolean(bool); | ||
return this; | ||
} | ||
@@ -221,0 +251,0 @@ })(); |
{ | ||
"name": "app-router", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description":"Routing for expressjs", | ||
@@ -5,0 +5,0 @@ "keywords":["express router", "application router", "app-router", "yaml-router", "yml-router", "yaml routing", "express", "connect", "router", "routing", "json router", "json-router"], |
@@ -15,3 +15,3 @@ app-router | ||
``` | ||
set current working directory (CWD) relative to all controllers path and route.json | ||
Set current working directory (CWD) relative to all controllers path and route.json | ||
@@ -21,3 +21,3 @@ ```javascript | ||
``` | ||
suppress throwing Error on unresolved action of route | ||
Throwing Error on unresolved action of route (default is true) | ||
@@ -29,10 +29,32 @@ ```javascript | ||
console.log all routing mapped by app-router | ||
console.log all routing mapped by app-router (default is false) | ||
```javascript | ||
showRouteInConsole(true) | ||
logRoute(true) | ||
``` | ||
Attach action manually to route in application (useful for other frameworks) (optional) (not required in express) | ||
```javascript | ||
letMeAttach(function(method, route, actions){ | ||
// method {String} = get, post, delete etc | ||
// route {String} = given by user or created by resource eg /user | ||
// actions {Array} = an array of actions resolved | ||
// routing example in express | ||
method = method.replace("delete","del"); | ||
actions.unshift(route); | ||
app[method].apply(app, actions); | ||
}) | ||
``` | ||
Use .format route in resource routing , by falsing it no route for .format will attach to resource routing. (default is true) | ||
```javascript | ||
useFormatInResource(false) | ||
``` | ||
sample <b> route.json </b> | ||
@@ -47,18 +69,18 @@ | ||
"GET":{ | ||
"/user" : ["{cp}:myMiddleWareFunction" , "{cp}:myMethod"], | ||
"/user/:id" : "{cp}:myClass.myMethod" | ||
}, | ||
"POST":{ | ||
"/hello" : "./controllers/my_controller:createApp" | ||
}, | ||
"PUT":{ | ||
"/hello" : "{other_controller}:helloPut" | ||
}, | ||
"DELETE":{ | ||
"/user" : "./controllers/other_controller.js:destroyApp" | ||
}, | ||
"RESOURCE":{ | ||
"/res" : "{cp}", | ||
"/user" : "./controllers/user_controller.js" | ||
} | ||
"/user" : ["{cp}:myMiddleWareFunction" , "{cp}:myMethod"], | ||
"/user/:id" : "{cp}:myClass.myMethod" | ||
}, | ||
"POST":{ | ||
"/hello" : "./controllers/my_controller:createApp" | ||
}, | ||
"PUT":{ | ||
"/hello" : "{other_controller}:helloPut" | ||
}, | ||
"DELETE":{ | ||
"/user" : "./controllers/other_controller.js:destroyApp" | ||
}, | ||
"RESOURCE":{ | ||
"/res" : "{cp}", | ||
"/user" : "./controllers/user_controller.js" | ||
} | ||
} | ||
@@ -74,3 +96,3 @@ | ||
"RESOURCE":{ | ||
"/user" : "./controllers/user_controller" | ||
"/user" : "./controllers/user_controller" | ||
} | ||
@@ -80,3 +102,3 @@ | ||
GET /user -> index | ||
GET /user -> index | ||
GET /user.:format -> index | ||
@@ -86,5 +108,5 @@ GET /user/new -> new | ||
POST /user -> create | ||
POST /user.:format -> create | ||
GET /user/:id -> show | ||
GET /user/:id.:format -> show | ||
POST /user.:format -> create | ||
GET /user/:id -> show | ||
GET /user/:id.:format -> show | ||
GET /user/:id/edit -> edit | ||
@@ -111,6 +133,6 @@ GET /user/:id/edit.:format -> edit | ||
{"/app_route" : [ | ||
"path_to_controller:middleware_one", | ||
"path_to_controller:middleware_two", | ||
"path_to_controller:method_name" | ||
] | ||
"path_to_controller:middleware_one", | ||
"path_to_controller:middleware_two", | ||
"path_to_controller:method_name" | ||
] | ||
} | ||
@@ -164,19 +186,19 @@ ``` | ||
VARIABLE cp ./controllers/my_controller | ||
VARIABLE cp ./controllers/my_controller | ||
VARIABLE other_controller ./controllers/other_controller.js | ||
VARIABLE other_controller ./controllers/other_controller.js | ||
GET /user_controller {cp}:myMiddleWareFunction {cp}:myMethod | ||
GET /user_controller {cp}:myMiddleWareFunction {cp}:myMethod | ||
GET /user/:id ./controllers/other_controller:myClass.myAction | ||
GET /user/:id ./controllers/other_controller:myClass.myAction | ||
POST /hello ./controllers/my_controller:createApp | ||
POST /hello ./controllers/my_controller:createApp | ||
PUT /hello ./controllers/my_controller:createApp | ||
PUT /hello ./controllers/my_controller:createApp | ||
DELETE /user ./controllers/other_controller.js:destroyApp | ||
DELETE /user ./controllers/other_controller.js:destroyApp | ||
RESOURCE /res {cp} | ||
RESOURCE /res {cp} | ||
RESOURCE /user ./controllers/user_controller.js | ||
RESOURCE /user ./controllers/user_controller.js | ||
@@ -183,0 +205,0 @@ |
14169
295
199