summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.js2
-rw-r--r--package.json3
-rw-r--r--routes/index.js17
-rw-r--r--views/data.jade80
-rw-r--r--views/index.jade2
5 files changed, 57 insertions, 47 deletions
diff --git a/app.js b/app.js
index 788679d..3558bca 100644
--- a/app.js
+++ b/app.js
@@ -17,7 +17,7 @@ app.configure(function(){
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
- app.use(express.static(__dirname + '/public'));
+ app.use(express.static(__dirname + '/public', {maxAge: 60 * 60 * 1000}));
});
app.configure('development', function(){
diff --git a/package.json b/package.json
index 6670270..3b3c99c 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,8 @@
"dependencies": {
"collection_json": "git+http://trygvis.dyndns.org/~trygvis/git/2012/06/collection_json.js.git",
"express": "3.0.0beta4",
- "jade": "~0.26.3"
+ "jade": "~0.26.3",
+ "underscore": "~1.3.3"
},
"engines": {
"node": "0.6.x",
diff --git a/routes/index.js b/routes/index.js
index a5b1bdc..efed59c 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -1,6 +1,7 @@
-var http = require('http')
+var collection_json = require('collection_json')
+ , http = require('http')
, url = require('url')
- , collection_json = require('collection_json');
+ , _ = require('underscore');
function urlgenerator(req) {
var host = req.headers.host;
@@ -24,7 +25,16 @@ exports.render = function(req, res) {
err: err
});
}
- fetchCollection(req.query.url, function(err, headers, body) {
+ var u = url.parse(req.query.url, true);
+ var params = _.reduce(req.query, function(q, value, key) {
+ if(!key.match(/^param-/)) {
+ return q;
+ }
+ q[key.substr(6)] = value;
+ return q;
+ }, {});
+ u.query = _.extend({}, u.query, params);
+ fetchCollection(url.format(u), function(err, headers, body) {
if(err) {
sendErr(err);
}
@@ -47,6 +57,7 @@ exports.render = function(req, res) {
isUrl: isUrl,
urlgenerator: urlgenerator(req),
url: req.query.url,
+ params: params,
collection: collection,
headers: headers,
rawBody: body,
diff --git a/views/data.jade b/views/data.jade
index f5a3b0a..5ef6ab6 100644
--- a/views/data.jade
+++ b/views/data.jade
@@ -48,23 +48,23 @@ block meta
form(action='http://redbot.org/?')
p
- input(name='uri', value=url, type='hidden')
- input(name='req_hdr', value='Accept: application/vnd.collection+json', type='hidden')
- input(type='submit', value='Check with redbot.org')
+ input(type='text', name='uri', value=url, type='hidden')
+ input(type='text', name='req_hdr', value='Accept: application/vnd.collection+json', type='hidden')
+ input(type='text', type='submit', value='Check with redbot.org')
- h2 Collection Links
- if collection.links.length == 0
- p Collection has no links.
- else
+ if collection.links.length > 0
+ h2 Collection Links
each link, i in collection.links
- var title = link.prompt || link.name
- title = title ? ': ' + title : ''
h3 Collection Link ##{i}#{title}
block link
+// TODO: If the collection has prev/next links, add buttons to
+// automaticaly navigate those.
+// TODO: Add ability to show the raw part of the collection.
block items
- // a(id='items'): h1: a(href='#items') Items
if collection.items.length == 0
p Collection has to items.
else
@@ -77,10 +77,8 @@ block items
p href:
block href
- h3 Item Links
- if item.links.length == 0
- p Item has no links.
- else
+ if item.links.length > 0
+ h3 Item Links
each link, i in item.links
h4 Item Link ##{i}
block link
@@ -90,19 +88,28 @@ block items
each data in item.data
dt #{data.name}
dd #{data.value}
- //
- table(class='table table-striped table-bordered')
- each data in item.data
- tr
- th #{data.name}
- td #{data.value}
- //
- div(class='form-horizontal')
- each data in item.data
- div(class='control-group')
- label(class='control-label') #{data.name}
- div(class='controls')
- div #{data.value}
+
+block queries
+ each query in collection.queries
+ - var name = query.prompt || query.name || 'Unnamed query'
+ h2= name
+
+ div(class='row')
+ div(class='span12')
+ form(action='/render', class='well form-horizontal')
+ input(type='hidden', name='url', value=query.href)
+ fieldset
+ each data in query.data
+ - var value = params[data.name] || data.value
+ div(class='control-group')
+ label(class='control-label', for=data.name) #{data.name}
+ div(class='controls')
+ input(type='text', name='param-' + data.name, value=value, class='input-xlarge')
+
+ div(class='control-group')
+ div(class='controls')
+ input(type='submit') Execute
+ // button(class='execute-query') Execute
block headers
// a(id='headers'): h1: a(href='#headers') Headers
@@ -121,21 +128,6 @@ block raw_body
// a(id='body'): h1: a(href='#body') Raw body
pre= rawBody
-block tabs
- div(class='tabbable')
- ul(class='nav nav-tabs')
- li(class='active'): a(href='#tab-meta', data-toggle='tab') Meta
- li: a(href='#tab-items', data-toggle='tab') Items
- li: a(href='#tab-headers', data-toggle='tab') Headers
- li: a(href='#tab-formatted-body', data-toggle='tab') Formatted Body
- li: a(href='#tab-raw-body', data-toggle='tab') Raw Body
- div(class='tab-content')
- div(class='tab-pane active', id='tab-meta'): block meta
- div(class='tab-pane', id='tab-items'): block items
- div(class='tab-pane', id='tab-headers'): block headers
- div(class='tab-pane', id='tab-formatted-body'): block formatted_body
- div(class='tab-pane', id='tab-raw-body'): block raw_body
-
block navbar
div(class='navbar navbar-fixed-top')
div(class='navbar-inner')
@@ -146,11 +138,13 @@ block navbar
span(class='icon-bar')
span(class='icon-bar')
span(class='icon-bar')
- a(class='brand', href='#') Collection+JSON Explorer
+ span(class='icon-bar')
+ a(class='brand', href='/') Collection+JSON Explorer
div(class='nav-collapse')
ul(class='nav')
li(class='active'): a(href='#meta') Meta
li: a(href='#items') Items
+ li: a(href='#queries') Queries
li: a(href='#headers') Headers
li: a(href='#formatted-body') Formatted Body
li: a(href='#raw-body') Raw Body
@@ -172,6 +166,10 @@ block content
if collection.items.length > 1
small #{collection.items.length} items
block items
+ section(id='queries')
+ div(class='page-header')
+ h1 Queries
+ block queries
section(id='headers')
div(class='page-header')
h1 Headers
diff --git a/views/index.jade b/views/index.jade
index 5800f5f..3cbf438 100644
--- a/views/index.jade
+++ b/views/index.jade
@@ -6,7 +6,7 @@ block content
form(action='/render', class='well')
div(class='row')
div(class='span10')
- input(name='url', size='100', placeholder='Enter URL to explore...', class='span10')
+ input(type='text', name='url', size='100', placeholder='Enter URL to explore...', class='span10')
// TODO: Fix
div(class='row')
div(class='span12')