Created
June 20, 2013 12:47
-
-
Save ssp/5822398 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(doc, req){ | |
provides('json', function(){ | |
return {'json': doc} | |
}); | |
provides('html', function(){ | |
var listItem = function (key, value) { | |
var result = ''; | |
if (key) { result += '<dt>' + key + '</dt><dd>'; } | |
if (typeof value === 'object') { | |
result += '<dl>'; | |
for (var i in value) { | |
if (i[0] !== '_') { | |
result += listItem(i, value[i]); | |
} | |
} | |
result += '</dl>'; | |
} | |
else { | |
result += value; | |
} | |
if (key) { result += '</dd>'; } | |
return result; | |
} | |
return '<html><head><title>'.concat(doc._id, '</title>', | |
'<style type="text/css">dt { font-weight:bold; }</style></head>', | |
'<body><h1>Document »' + doc._id + '«</h1>', | |
listItem(undefined, doc), | |
'</body><html>'); | |
}); | |
registerType('text-json', 'text/json') | |
provides('text-json', function(){ | |
return toJSON(doc); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment