Skip to content

Instantly share code, notes, and snippets.

@natevw
Created May 5, 2010 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natevw/391516 to your computer and use it in GitHub Desktop.
Save natevw/391516 to your computer and use it in GitHub Desktop.
function(head, req) {
// !code lib/mustache.js
// !json templates.thumbnails
//var databaseURL = "http://stravinsky.local:5984/a70_digipics/";
//var databaseURL = "http://dvorak.local:5984/temp/";
var databaseURL = "/temp/";
// requires moustache.js is_array function patched to return (a instanceof Array);
function RowArray(rowToObject) {
this.map = function (fn) {
var resultArray = [];
var row;
while (row = getRow()) {
var res = fn(rowToObject(row));
resultArray.push(res);
}
return resultArray;
}
}
RowArray.prototype = new Array;
provides("html", function () {
var contents = {"title": "Thumbnails", "photos" : new RowArray(function(row) {
// show ordering of this call
// NOTE: currently mustache still seems to do the whole map up front before calling the line function
send("*");
var parts = row.value.path.split("/");
return {"src" : databaseURL + row.id + "/small.jpg", "name" : parts[parts.length-1]};
})};
Mustache.to_html(templates.thumbnails, contents, null, function(line) {
send(line);
// show each line sent separately
send("|");
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment