couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Lenahan <michael.lena...@gmail.com>
Subject Re: Mustache? CommonJS?
Date Tue, 17 Aug 2010 19:19:08 GMT
Thanks Jason - sorry, another question.

When you say "<insert mustache.js CommonJS file here>" what do you mean?

I found this:
http://github.com/janl/mustache.js/tree/master/mustache-commonjs but I'm
unsure what I need to copy into the design doc.

On 16 August 2010 19:35, Jason Smith <jhs@couch.io> wrote:

> 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