Skip to content
Browse files

[dist] Added code

  • Loading branch information...
1 parent ad75223 commit 92b10a18e750046a2018a0dd61ab1f575138a14e @Marak Marak committed May 30, 2012
Showing with 144 additions and 0 deletions.
  1. 0 README
  2. +60 −0 README.md
  3. +36 −0 examples/server.js
  4. +26 −0 lib/director-explorer.js
  5. +22 −0 package.json
View
0 README
No changes.
View
60 README.md
@@ -0,0 +1,60 @@
+# director-explorer
+
+tools for interacting with and exploring <a href="http://github.com/flatiron/director">Director</a> routers.
+
+# Features
+
+ - Can currently output a plain-text view of a `Director.Router` instance
+
+# Installation
+
+ npm install director-explorer
+
+# Usage
+
+``` js
+var de = require('director-explorer'),
+ director = require('director');
+
+var router = new director.http.Router();
+
+// simple noop for demo
+var n = function(){};
+
+router.get('/', n);
+
+router.path('/users/:id', function(){
+ this.post(n);
+ this.get(n);
+ this.delete(n);
+ this.put(n);
+ this.path('/dongles', function(){
+ this.get(n);
+ this.post(n);
+ })
+})
+
+console.log(de.table(router));
+
+/*
+
+ OUTPUTS:
+
+ GET /
+ POST /users/([._a-zA-Z0-9-]+)
+ GET /users/([._a-zA-Z0-9-]+)
+ DELETE /users/([._a-zA-Z0-9-]+)
+ PUT /users/([._a-zA-Z0-9-]+)
+ GET /users/([._a-zA-Z0-9-]+)/dongles
+ POST /users/([._a-zA-Z0-9-]+)/dongles
+
+*/
+
+```
+
+# TODO
+
+ - Add HTML view with collapsable menus
+ - Add WSDL view
+ - Create director-client project for auto-generated director clients
+ - Create html demo forms and auto-documentation for director routers
View
36 examples/server.js
@@ -0,0 +1,36 @@
+var de = require('../lib/director-explorer'),
+ director = require('director');
+
+var router = new director.http.Router();
+
+// simple noop for demo
+var n = function(){};
+
+router.get('/', n);
+
+router.path('/users/:id', function(){
+ this.post(n);
+ this.get(n);
+ this.delete(n);
+ this.put(n);
+ this.path('/dongles', function(){
+ this.get(n);
+ this.post(n);
+ })
+})
+
+console.log(de.table(router));
+
+/*
+
+ OUTPUTS:
+
+ GET /
+ POST /users/([._a-zA-Z0-9-]+)
+ GET /users/([._a-zA-Z0-9-]+)
+ DELETE /users/([._a-zA-Z0-9-]+)
+ PUT /users/([._a-zA-Z0-9-]+)
+ GET /users/([._a-zA-Z0-9-]+)/dongles
+ POST /users/([._a-zA-Z0-9-]+)/dongles
+
+*/
View
26 lib/director-explorer.js
@@ -0,0 +1,26 @@
+var de = exports,
+ traverse = require('traverse');
+
+exports.table = function (router) {
+
+ var niceRoutes = router.routes,
+ verbs = ['get', 'post', 'put', 'delete'],
+ str = '';
+
+ traverse(niceRoutes).forEach(visitor);
+
+ function visitor () {
+ var path = this.path,
+ pad = '';
+ if (path[path.length - 1] && verbs.indexOf(path[path.length - 1]) !== -1) {
+ pad += path.pop().toUpperCase();
+ for (var i = pad.length; i < 8; i++) {
+ pad += ' ';
+ }
+ path = path.join('/');
+ str += pad + '/' + path + ' \n'
+ }
+ }
+
+ return str;
+}
View
22 package.json
@@ -0,0 +1,22 @@
+{
+ "name": "director-explorer",
+ "author": "Nodejitsu Inc. <info@nodejitsu.com>",
+ "maintainers": [
+ "marak <marak@nodejitsu.com>"
+ ],
+ "version": "0.0.1",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Marak/director-explorer.git"
+ },
+ "main": "./lib/director-explorer",
+ "dependencies": {
+ "director": "1.0.10",
+ "traverse": "0.6.1"
+ },
+ "devDependencies": {},
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ }
+}

0 comments on commit 92b10a1

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