Created
May 5, 2010 22:09
-
-
Save natevw/391516 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(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