Permalink
Browse files

Router.toString() for inspecting routes, version bump

  • Loading branch information...
1 parent 563fc2a commit 2ee39f3cbd41906f12bc9c0600dfdbe1214b0210 @kieran committed Oct 13, 2012
Showing with 26 additions and 4 deletions.
  1. +22 −0 lib/route.js
  2. +3 −3 lib/router.js
  3. +1 −1 package.json
View
@@ -443,3 +443,25 @@ Route.prototype.nest = function(cb){
cb.call( this )
return this // for chaining
}
+
+
+Route.prototype.toString = function(){
+
+ var path = this.path
+ , method = this.method || 'ALL'
+ , controller = this.params.controller
+ , action = this.params.action
+
+ // right-pads strings
+ function rpad(str,len){
+ var ret = new Array(len+1) // +1 for fenceposting
+ ret.splice(0, str.length, str)
+ return ret.join(' ')
+ }
+
+ return [
+ rpad(method,8),
+ rpad(path,50),
+ [this.params.controller, this.params.action].join('.')
+ ].join('')
+}
View
@@ -251,6 +251,6 @@ Router.prototype.defer = function( fn ) {
}
-Router.prototype.list = function(){
- console.log(this.routes.map(function(rt){return rt.path}))
-}
+Router.prototype.toString = function(){
+ return this.routes.map(function(rt){return rt.toString()}).join('\n')
+}
View
@@ -1,7 +1,7 @@
{
"name": "barista",
"description": "URL router & generator, similar to Rails / merb",
- "version": "0.0.7",
+ "version": "0.0.8",
"author": "Kieran Huggins <kieran@kieran.ca>",
"repository": "git://github.com/kieran/barista",
"main": "./index.js",

0 comments on commit 2ee39f3

Please sign in to comment.