Can dust.js templates be used in the "show" function of CouchDB?

dust.js is an asynchronous JavaScript templating engine - you pass a callback to the "render" function.

CouchDB's "show" functions, on the other hand, should actually return HTML.

So I can't use dust.js in my show function! ... it just won't work. How can I get around this synchronous / asynchronous problem?

EDIT: I would have to do this using the (asynchronous) "send" function:

function(doc,req){
    var dust = require('lib/dust');
    dust.renderSource('Hello, my name is {name}',{name:'Nick'},function(err,output){
        send(output);
    });
}

      

.. but it doesn't work, I get this:

{"error":"render_error","reason":"function raised error: (new TypeError(\"dust.compile is not a function\", \"\", 37)) \nstacktrace: (\"Hello, my name is {name}\")@:37\n(\"Hello, my name is {name}\",[object Object],(function (err, output) {send(output);}))@:33\n([object Object],[object Object])@:2\napply([object Object],[object Array])@:0\nrunShow(function (doc, req) {var dust = require(\"lib/dust\");dust.renderSource(\"Hello, my name is {name}\", {name:\"Nick\"}, function (err, output) {send(output);});},[object Object],[object Array])@/usr/share/couchdb/server/main.js:886\n(function (doc, req) {var dust = require(\"lib/dust\");dust.renderSource(\"Hello, my name is {name}\", {name:\"Nick\"}, function (err, output) {send(output);});},[object Object],[object Array])@/usr/share/couchdb/server/main.js:989\napply(null,[object Array])@:0\n(\"_design/ibs_policies\",[object Array],[object Array])@/usr/share/couchdb/server/main.js:1401\napply(null,[object Array])@:0\n()@/usr/share/couchdb/server/main.js:1443\n@/usr/share/couchdb/server/main.js:1454\n"}

      

Does "dust.js" seem to expose all of its functionality when imported as a CommonJS module? Why is this? How can I make this work?

+3


source to share


1 answer


Just based on the dust source preview, it seems to be expecting to find some nodejs specific stuff if it doesn't work in the browser. In particular, it looks like dust.compile is only exported from code, which is only called if a process is defined and there is no window. None of these will be detected when running in CouchDB view mode.



+1


source







All Articles