summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--routes/index.js10
-rw-r--r--views/data.jade81
-rw-r--r--views/index.jade4
3 files changed, 69 insertions, 26 deletions
diff --git a/routes/index.js b/routes/index.js
index 0bd432d..6d57023 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -25,7 +25,17 @@ exports.render = function(req, res){
else {
var parsedBody = JSON.parse(body);
var doc = collection_json.fromObject(parsedBody);
+ var isUrl = function(u) {
+ try {
+ var x = url.parse(u);
+ return _.isString(x.protocol) && _.isString(x.host) && _.isString(path);
+ }
+ catch(e) {
+ return false;
+ }
+ };
res.render('data', {
+ isUrl: isUrl,
url: req.query.url,
doc: doc,
headers: headers,
diff --git a/views/data.jade b/views/data.jade
index 8fbd05e..15189e9 100644
--- a/views/data.jade
+++ b/views/data.jade
@@ -1,5 +1,30 @@
extends layout
+block link
+ - var name = typeof link.name == 'string' ? link.name : '<no name attribute>'
+ - var prompt = typeof link.prompt == 'string' ? link.prompt : '<no prompt attribute>'
+ table
+ tr
+ td href
+ td: a(href=link.href, name=link.name) #{link.href}
+ tr
+ td rel
+ td
+ if isUrl(link.rel)
+ a(href=link.rel) #{link.rel}
+ else
+ | #{link.rel}
+ tr
+ td name
+ td #{name}
+ tr
+ td prompt
+ td #{prompt}
+ if link.render == 'image'
+ tr
+ td
+ td: img(src=link.href, alt=link.name, title=name)
+
block content
h1 Collection+JSON Explorer
p Viewing #{url}
@@ -7,12 +32,12 @@ block content
form(action="/render")
p
label URL:
- input(name="url", value="#{url}")
+ input(name="url", value=url)
input(type="submit", value="Render")
form(action="http://redbot.org/?")
p
- input(name="uri", value="#{url}", type="hidden")
+ input(name="uri", value=url, type="hidden")
input(type="submit", value="Check with redbot.org")
ul
@@ -23,9 +48,9 @@ block content
li
a(href="#headers") Headers
li
- a(href="#body") Raw body
- li
a(href="#formatted-body") Formatted body
+ li
+ a(href="#body") Raw body
a(id="meta")
h1
@@ -39,25 +64,37 @@ block content
td URI
td
if typeof doc.uri == 'string'
- a(href="#{doc.uri}") #{doc.uri}
+ a(href=doc.uri) #{doc.uri}
else
span No URI
- a(id="items")
- h1
- a(href="#items") Items
+ h2 Collection Links
+ each link, i in doc.links
+ h3 Collection Link ##{i}
+ block link
+
+ a(id="items"): h1: a(href="#items") Items
each item, i in doc.items
a(id="item-#{i+1}")
- h2
- a(href="#item-#{i+1}") Item ##{i+1}
+ h2: a(href="#item-#{i+1}") Item ##{i+1}
+
+ if typeof item.href == 'string'
+ | href
+ a(href=item.href) #{item.href}
+
+ h2 Item Links
+ each link, i in item.links
+ h3 Item Link ##{i}
+ block link
+
h3 Data
- ul
- each data in item.data
- li #{data.name}: #{data.value}
+ table
+ each data in item.data
+ tr
+ td #{data.name}
+ td #{data.value}
- a(id="headers")
- h1
- a(href="#headers") Headers
+ a(id="headers"): h1: a(href="#headers") Headers
pre
table
each value, key in headers
@@ -65,12 +102,8 @@ block content
td #{key}:
td #{value}
- a(id="body")
- h1
- a(href="#body") Raw body
- pre= raw
-
- a(id="formatted-body")
- h1
- a(href="#formatted-body") Formatted body
+ a(id="formatted-body"): h1: a(href="#formatted-body") Formatted body
pre= formattedRaw
+
+ a(id="body"): h1: a(href="#body") Raw body
+ pre= raw
diff --git a/views/index.jade b/views/index.jade
index caf2954..5625546 100644
--- a/views/index.jade
+++ b/views/index.jade
@@ -12,8 +12,8 @@ block content
h2 Examples
- p Taken from
- a(href='http://amundsen.com/media-types/collection/examples/') Mike Admundsen's examples
+ p Taken from:
+ a(href='http://amundsen.com/media-types/collection/examples/') Mike Amundsen's examples
ul
each example in examples