summaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-07-07 16:09:23 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-07-07 16:12:43 +0200
commit1d3a63d75fce583032333a9d088a0d6d6569f58d (patch)
tree23805370570fe29e05706e55d3ce4d8d04facb58 /routes
parent8c53aec1ce4d34cc245a755498c068a15ca99997 (diff)
downloadcollection-json-explorer-1d3a63d75fce583032333a9d088a0d6d6569f58d.tar.gz
collection-json-explorer-1d3a63d75fce583032333a9d088a0d6d6569f58d.tar.bz2
collection-json-explorer-1d3a63d75fce583032333a9d088a0d6d6569f58d.tar.xz
collection-json-explorer-1d3a63d75fce583032333a9d088a0d6d6569f58d.zip
o Splitting 'hrefs' so the user can click on any path segment.
Diffstat (limited to 'routes')
-rw-r--r--routes/index.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/routes/index.js b/routes/index.js
index fb81a41..cace65e 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -4,9 +4,35 @@ var collection_json = require('collection_json')
, util = require('util')
, _ = require('underscore');
+function split(str) {
+ var u = url.parse(str);
+
+ var segments = u.pathname.replace(/\/$/, '').split('/');
+
+ var splits = _.map(_.range(segments.length), function(i) {
+ var x = _.clone(u);
+ x.pathname = _.first(segments, i + 1).join('/');
+ x.search = '';
+ if(i == 0) {
+ return [u.protocol + '//' + u.host, url.format(x)];
+ }
+ else {
+ return ['/' + segments[i], url.format(x)];
+ }
+ });
+
+ if(u.search) {
+ splits.push([(u.pathname.match(/\/$/) ? '/' : '') + u.search, url.format(u)]);
+ }
+
+ return splits;
+}
+exports.split = split;
+
function urlgenerator(req) {
var host = req.headers.host;
return {
+ split: split,
render: function(u) { return 'http://' + host + '/render?url=' + encodeURIComponent(u)},
delete: function(referer, u) { return 'http://' + host + '/delete?referer=' + encodeURIComponent(referer) + '&url=' + encodeURIComponent(u)},
isUrl: function(u) {