mikeal / node.couchapp.js

Utility for writing couchapps.
Apache License 2.0
406 stars 78 forks source link

Support transformations & aggregations of attachments #34

Open miccolis opened 12 years ago

miccolis commented 12 years ago

The idea here would be to allow a couch app to provide it's own functions to transform and/or aggregate various attachment files. This would enable you to do things like transform templates into javascript and aggregate them together to be served as a single file to a browser.

This is a more general case of using uglify to minimize attachments.

I've got the basics working in my fork (for push only, not sync) though I'd like to make the API more simple.

couchapp.loadAttachments(ddoc, path.join(__dirname, 'templates'), {
   operators: [function(f, data) {
     var content = data.toString('utf8'));
     // Do something...
     return new Buffer(content);
   }],
   aggregator: function(files) {
      // `files` is an array of objects..
      // e.g. [{data: '', name: '', mime: ''}]
      // Return aggregated version of this array.
   return files;
 });

My question here is basically whether this is something that would be considered for inclusion. If so whether this sort of API looks reasonable.