Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created April 13, 2012 21:18
Show Gist options
  • Save boxxxie/2380254 to your computer and use it in GitHub Desktop.
Save boxxxie/2380254 to your computer and use it in GitHub Desktop.
ddoc.shows = {
csv:function(doc,req){
function csvEscapeOnePerLine(arr){
var csv = '';
var arr_last = arr.length - 1;
for(var i = 0; i <= arr_last; i++){
var value = arr[i].replace(/"/g, '""');
csv += '"' + value + '"';
if( i != arr_last ){
csv += ";";
}
}
return csv;
}
log(doc)
//provides("text", function() {
return {
"headers" : {
'Content-Type' : "text/csv",
'Content-Disposition':'attachment; filename="doc.csv"'
},
"body" : doc.content.map(csvEscapeOnePerLine).join('\n')
}
// })
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment