Skip to content

Commit

Permalink
Merge pull request Marak#20 from rootnot/master
Browse files Browse the repository at this point in the history
Testing forms in inspection view
  • Loading branch information
Marak committed Jun 20, 2011
2 parents 466280b + 7b6005f commit 78ae028
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/createRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ var ws = require('./webservice'),
resourcer = require('resourcer'),
validator = require('resourcer/validator');


//
// Returns a Journey router
//

/* edit (by rootnot)
ws.view.renderRoutes is called with response context
*/

var createRouter = exports.createRouter = function createRouter( module, options ){

var template = fs.readFileSync(__dirname + '/views/home.html'),
Expand All @@ -21,18 +24,18 @@ var createRouter = exports.createRouter = function createRouter( module, options

if(options.bindroot !== false){
router.root.bind(function(res){
res.send(200, {'Content-Type': 'text/html'}, ws.view.renderRoutes('html', '', routes, template.toString()));
res.send(200, {'Content-Type': 'text/html'}, ws.view.renderRoutes.call(res, 'html', '', routes, template.toString()));
});
}

// returns the docs of the API
router.get('/docs').bind(function (res) {
res.send(200, {'Content-Type': 'text/html'}, ws.view.renderRoutes('html', '', routes, template.toString()));
res.send(200, {'Content-Type': 'text/html'}, ws.view.renderRoutes.call(res, 'html', '', routes, template.toString()));
});

// returns the docs of the API
router.get('/docs.json').bind(function (res) {
res.send(200, {'Content-Type': 'text/html'}, ws.view.renderRoutes('html', '', routes, JSON.stringify(routes)));
res.send(200, {'Content-Type': 'text/html'}, ws.view.renderRoutes.call(res, 'html', '', routes, JSON.stringify(routes)));
});

// returns the version of the API
Expand Down
28 changes: 25 additions & 3 deletions lib/view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

/*** simple internal view server ( for documentation ) ***/

var renderRoutes = exports.renderRoutes = function( format, name, items, template ) {
// console.log(util.inspect(request.originalUrl));

/* edit (by rootnot)
1. Now this function is called with response context (this refers to response object).
2. Added inspection form with iframe containing output from called methods
*/

if(format == 'json'){
return JSON.stringify(items, true, 2);
}
Expand All @@ -23,8 +29,9 @@ var renderRoutes = exports.renderRoutes = function( format, name, items, templat
continue;
}

var path = "/" + method;
if(typeof m.regex !== 'undefined') {
// var path = "/" + method;
var path = this.request.originalUrl + method;
if(typeof m.regex !== 'undefined') {
path = m.regex;
}
html += ('<div class="member grad">');
Expand Down Expand Up @@ -72,6 +79,21 @@ var renderRoutes = exports.renderRoutes = function( format, name, items, templat
//html += ('<div class="descriptor">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br/></div>');
html += ('</span></div>');
html += ('</div></div>');

// form
html += ('<div class="form">');
html += ('<form method="get" action="' + items.endpoint + '/' + method + '" + target="' + method + '-output">');
for (var arg in s)
{
html += ('<div class="field">');
html += ('<label for="' + arg + '">' + arg + ': </label>');
html += ('<input type="text" id="' + method + '-' + arg + '" name="' + arg + '">');
html += ('</div>');
}
html += ('<div class="button"><input type="submit"/></div>');
html += ('</form>');
html += ('<iframe class="response" name="' + method + '-output"/>');
html += ('</div');


html += ('<span class="content">JSONP support is currently enabled. To use JSONP, append "&callback=mymethod" to any GET request</span>');
Expand Down
6 changes: 6 additions & 0 deletions lib/views/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
radius: 6px; }
iframe.response {width:100%; height:300px; background-color:white; display:inline-block;}
div.form {width:100%; display:table;}
div.form div.field {display:table-row; }
div.form div.field label {display:table-cell; text-align:right; width:100px; margin-top:3px; mergin-bottom:3px;}
div.form div.field input {display:table-cell; width:300px; margin-top:3px; margin-bottom:3px;}
div.form div.button {position:relative; left:100px; width:300px; margin-top:3px; margin-bottom:3px;}

</style>
<body>
Expand Down

0 comments on commit 78ae028

Please sign in to comment.