couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <jch...@apache.org>
Subject document forms
Date Wed, 24 Dec 2008 02:15:07 GMT
Couch devs,

I've been working on a new feature (based on Damien's specification)
called forms. It's a little like action.js, but with decent
performance and caching characteristics. The upshot is that it allows
you to generate HTML (or other) output based on a single document.
There will be forms for views, with a similar concept, but they aren't
part of this patch.

Forms are defined in design documents, as an object under the key
"forms". Each form is a function from a document and a request, to the
output. Form responses have etags based on the form function, the
document, and the Accept headers as sent by the client. This ensures
that an HTML representation will have a different Etag from an Atom
representation.

I've also added a helper function called respondWith() to main.js, so
that you can easily switch based on client requests. The best example
code at this point is in couch_tests.js. Here I've linked to the line
where respondWith() is invoked:
http://github.com/jchris/couchdb/tree/templates/share/www/script/couch_tests.js#L2084

Comments about the API and implementation welcome. I think this code
is fairly solid, but I'd like to put a few eyes on it before it goes
into trunk. One thing that is known to be missing, is there is no way
to return direct binary from a form (eg have a form generate an
image/png from a document). This will probably involve just a little
bit of base64 work and the right conventions.

The diff itself (cleaned up to work against current svn trunk) is
available here: http://friendpaste.com/5pZcOrLZGkOi1vepapGHso

Chris



-- 
Chris Anderson
http://jchris.mfdz.com

Mime
View raw message