From 0ba8317f8b725f2048b0ddbf5beec5681afab293 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 5 Jul 2012 22:31:17 +0200 Subject: o Automatically showing next/prev links if the collection has next/prev links. --- routes/index.js | 3 +-- views/data.jade | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/routes/index.js b/routes/index.js index 73f82ab..fb81a41 100644 --- a/routes/index.js +++ b/routes/index.js @@ -86,12 +86,11 @@ exports.render = function(req, res) { sendErr(req, res, 'Unable to parse JSON: ' + e, httpResponse); return; } - var collection = collection_json.fromObject(parsedBody).collection; res.render('data', { urlgenerator: urlgenerator(req), url: req.query.url, referer: req.query.referer, params: params, - collection: collection, + root: collection_json.fromObject(parsedBody), httpResponse: httpResponse, formattedBody: JSON.stringify(parsedBody, null, ' ') }); diff --git a/views/data.jade b/views/data.jade index b2910b2..bf22302 100644 --- a/views/data.jade +++ b/views/data.jade @@ -74,6 +74,18 @@ block meta h3(id='link-#{i + 1}') Collection Link ##{i}#{title} block link +block next_prev + - var next = root.findLinkByRel('next'); + - var prev = root.findLinkByRel('prev'); + if next || prev + div(class='fluid-row') + div(class='span12') + if prev + a(class='btn btn-primary btn-mini', href=urlgenerator.render(next.href) + '#items') Previous + | + if next + a(class='btn btn-primary btn-mini', href=urlgenerator.render(next.href) + '#items') Next + // 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. @@ -81,7 +93,8 @@ block items if collection.items.length == 0 p Collection has no items. else - // p The feed has #{collection.items.length} items. + block next_prev + each item, i in collection.items - var href=item.href h2(id='item-#{i+1}') Item ##{i+1} @@ -111,6 +124,8 @@ block items dt #{data.name} dd #{data.value} + block next_prev + block queries if collection.queries.length == 0 p Collection has no queries. @@ -247,6 +262,8 @@ block inner_content h1 Items if collection.items.length > 1 span(class='badge') #{collection.items.length} + if root.findLinkByRel('next') + |+ block items section(id='queries') div(class='page-header') @@ -270,6 +287,7 @@ block inner_content block httpResponse block content + - var collection = root.collection div(class='row-fluid') div(class='span3') block sidebar -- cgit v1.2.3