app-router
Advanced tools
Comparing version 0.1.1 to 0.1.2
46
index.js
@@ -9,3 +9,3 @@ var fs=require("fs"), | ||
var interPolate = function (str, iObj) { | ||
var interPolateStr = function (str, iObj) { | ||
return str.replace(/{([^{}]+)}/g, | ||
@@ -24,13 +24,33 @@ function (a, b) { | ||
var interPolateArray = function(arry, obj){ | ||
var interPolateStrArray = function(arry, obj){ | ||
return arry.map(function(item){ | ||
return interPolate(item, obj); | ||
return interPolateStr(item, obj); | ||
}); | ||
} | ||
var interPolateObj = function (str, iObj) { | ||
iObj = iObj || GLOBAL ; | ||
return str.replace(/<([^<>]+)>/, | ||
function (a, b) { | ||
var interObject=iObj; | ||
b.split(".").forEach(function(item){ | ||
if(typeof interObject[item] != 'undefined'){ | ||
interObject=interObject[item]; | ||
} | ||
}); | ||
return (typeof interObject == "function" ? interObject : a) ; | ||
} | ||
); | ||
}; | ||
var interPolateObjArray = function(arry, obj){ | ||
return arry.map(function(item){ | ||
return interPolateObj(item, obj); | ||
}); | ||
} | ||
var startRouting= function(routes, expressApp, mainPath){ | ||
var _VARIABLE= routes.VARIABLE || routes.variable || {}; | ||
Object.keys(_VARIABLE).forEach(function(item){ | ||
_VARIABLE[item]= interPolate(_VARIABLE[item], _VARIABLE); | ||
}); | ||
var _VARIABLE= inrePolateVar(routes); | ||
Object.keys(routes).forEach(function(item){ | ||
@@ -43,2 +63,10 @@ if(item.match(/get|post|put|delete|options|resource/i)){ | ||
var inrePolateVar = function(routes){ | ||
var _VARIABLE= routes.VARIABLE || routes.variable || {}; | ||
Object.keys(_VARIABLE).forEach(function(item){ | ||
_VARIABLE[item]= interPolateStr(_VARIABLE[item], _VARIABLE); | ||
}); | ||
return _VARIABLE; | ||
} | ||
var routeMethod = function(routes, methodType, _VARIABLE, expressApp, mainPath){ | ||
@@ -56,4 +84,4 @@ if(util.isArray(routes)){ | ||
var controller =util.isArray(routes[item])? | ||
interPolateArray(routes[item], _VARIABLE): | ||
interPolate(routes[item], _VARIABLE); | ||
interPolateStrArray(routes[item], _VARIABLE): | ||
interPolateStr(routes[item], _VARIABLE); | ||
routeThis(item, methodType, controller, expressApp, _VARIABLE, mainPath); | ||
@@ -60,0 +88,0 @@ }); |
{ | ||
"name": "app-router", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"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"], |
@@ -0,1 +1,5 @@ | ||
[![NPM](https://nodei.co/npm/app-router.svg?downloads=true&downloadRank=true)](https://nodei.co/npm/app-router/) | ||
[![Build Status](https://travis-ci.org/pradeep-mishra/app-router.svg?branch=master)](https://travis-ci.org/pradeep-mishra/app-router) | ||
app-router | ||
@@ -61,8 +65,8 @@ ============== | ||
{ | ||
"VARIABLE":{ | ||
"cp":"./controllers/my_controller", | ||
"other_controller":"./controllers/other_controller.js" | ||
}, | ||
"GET":{ | ||
"/user" : ["{cp}:myMiddleWareFunction" , "{cp}:myMethod"], | ||
"VARIABLE":{ | ||
"cp":"./controllers/my_controller", | ||
"other_controller":"./controllers/other_controller.js" | ||
}, | ||
"GET":{ | ||
"/user" : ["{cp}:myMiddleWareFunction" , "{cp}:myMethod"], | ||
"/user/:id" : "{cp}:myClass.myMethod" | ||
@@ -98,3 +102,3 @@ }, | ||
GET /user -> index | ||
GET /user -> index | ||
GET /user.:format -> index | ||
@@ -104,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 | ||
@@ -181,19 +185,19 @@ GET /user/:id/edit.:format -> edit | ||
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 | ||
@@ -200,0 +204,0 @@ |
@@ -5,3 +5,4 @@ | ||
"cp":"./controllers/my_controller", | ||
"other_controller":"./controllers/other_controller.js" | ||
"other_controller":"./controllers/other_controller.js", | ||
"App":"<App>" | ||
}, | ||
@@ -8,0 +9,0 @@ "GET":{ |
15216
6
319
203