Skip to content

Instantly share code, notes, and snippets.

@ssp
Created June 20, 2013 12:47
Show Gist options
  • Save ssp/5822398 to your computer and use it in GitHub Desktop.
Save ssp/5822398 to your computer and use it in GitHub Desktop.
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