Skip to content
Browse files

V2.0.1

  • Loading branch information...
1 parent b9d0b4e commit f9dcb674a35807393a523427b8d6e3f70aff2bca @whoamicz committed
Showing with 17 additions and 19 deletions.
  1. +7 −1 README.md
  2. +9 −16 index.js
  3. +1 −2 package.json
View
8 README.md
@@ -10,7 +10,10 @@ Easy way for using tree routes in Express.js
### Create this
- app.use(treeRouter({
+ var express = require('express'),
+ app = express();
+
+ app.use(treeRouter(express, {
'' : { get: controller },
'products': { get: controller, post: controller, content: {
':product_id': { get: controller, put: controller, del: controller, content: {
@@ -30,6 +33,9 @@ Easy way for using tree routes in Express.js
### From this
+ var express = require('express'),
+ app = express();
+
app.get('/', controller);
app.get('/products', controller);
View
25 index.js
@@ -1,7 +1,6 @@
-var express = require('express'),
- _ = require('underscore');
+var _ = require('underscore');
-var mapRouter = function(routes){
+var mapRouter = function(express, routes){
this.app = express();
this.methods = {
all: 'all',
@@ -11,29 +10,23 @@ var mapRouter = function(routes){
del: 'del',
delete: 'del'
};
- /*
- if (typeof(routes) !== 'object') {
- // Space for error
- return app;
- }
- */
this.parse(routes);
return this.app;
};
mapRouter.prototype.parse = function(routes, originPath){
- var obj = this;
+ var self = this;
_.each(routes, function(route, path){
var targetPath = (originPath || '')+'/'+path;
- _.each(obj.methods, function(method, methodKey){
- if ( typeof(route[(methodKey)]) !== 'undefined' ) { // === function, object..?
- obj.app[(method)](targetPath, route[(methodKey)]);
+ _.each(self.methods, function(method, methodKey){
+ if ( typeof(route[(methodKey)]) !== 'undefined' ) {
+ self.app[(method)](targetPath, route[(methodKey)]);
}
});
- if ( typeof(route.content) === 'object' ) obj.parse(route.content, targetPath);
+ if ( typeof(route.content) === 'object' ) self.parse(route.content, targetPath);
});
};
-module.exports = function(routes){
- return new mapRouter(routes);
+module.exports = function(express, routes){
+ return new mapRouter(express, routes);
};
View
3 package.json
@@ -1,6 +1,6 @@
{
"name": "express-treerouter",
- "version": "0.2.0",
+ "version": "0.2.1",
"description": "Easy way for using tree routes in Express.js",
"keywords": [
"treeRouter",
@@ -17,7 +17,6 @@
"url": "git://github.com/whoamicz/express-treerouter.git"
},
"dependencies": {
- "express": "3.1.x",
"underscore": "1.4.x"
},
"engines": {

0 comments on commit f9dcb67

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