incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Smith <...@couch.io>
Subject Re: Mustache? CommonJS?
Date Mon, 16 Aug 2010 18:35:32 GMT
On Mon, Aug 16, 2010 at 23:04, Michael Lenahan <michael.lenahan@gmail.com>wrote:

> 1. I wasn't able to work out how templating languages like mustache fit in.
> Are there any ways to use mustache inside a "show" to make authoring the
> show more easy?
>

In a show function, the `this` variable is assigned to the Javascript object
of the design doc. Therefore if your design doc is

    { "_id": "_design/default",
      "mustache_lib": "<insert mustache.js CommonJS file here>",
      "an_html_template": "This is a web page called {{name}}",
      etc.
    }

Then you can load mustache via CommonJS in the show function.

    function(doc, req) {
        var mustache = require("mustache_lib");
        var template = this.an_html_template;
        return {body: mustache.to_html(template, {name: "Hi!"});
    }

That is the idea, note I did not test this code just yet but I got it from
working code I use.

-- 
Jason Smith
Couchio Hosting

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message