incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Rose <dopp...@gmail.com>
Subject Re: re couchapp with node
Date Fri, 27 Jan 2012 22:18:25 GMT
couchapp.loadAttachments(ddoc, path.join(__dirname, 'attachments'));
adds all files under the directory "attachments" as attachments to the
design doc.

ddoc.views.lib = couchapp.loadFiles('./lib');
adds any js files in the "./lib" directory as commonjs modules to your
views, which you can then use in your views. Here's a snippet from one
of mine:

ddoc.views.alpha = {
  map : function(doc) {
    if(doc.type == 'event') {
      var skey   = require('views/lib/util').sanitizedKeyData(doc);
      var cvalue = require('views/lib/util').commonEmitValue(doc);
      emit(skey.name, cvalue);
    }
  },
  reduce : "_count"	
}

./lib/utils.js looks like this:

exports.commonEmitValue = function(doc) {
  return({...});
}

exports.sanitizedKeyData = function(doc) {
  // set vars and manipulate stuff
  return({...});
}

You can also define ddoc filters in a similar fashion:

ddoc.filters = couchapp.loadFiles('./filters');

Hope this somewhat incoherent reply helps point you in the right direction.

David Rose


On Fri, Jan 27, 2012 at 3:39 PM, john.tiger <john.tigernassau@gmail.com> wrote:
> I posted this with node google group but then realized I might get a
> response from this group with more couchapp users.
>
> we're trying to use node.couchapp.js but since it's not very documented
> having trouble figuring out whether base files such as index.html, app.css,
> etc should get added as either:
> a) put under attachments folder and get loaded with loadAttachment
> b) or listed under ddoc and loaded with loadFile
>
>
> we have tried both the python version of couchapp which gave all sorts of
> errors and seems overly complicated  and at Kelso - a node version of
> couchapp which also has way too many dependencies making it quite
> complicated as well - we are hoping to clean up, better document and even
> simplify node.couchapp without dependencies.
>

Mime
View raw message