You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by "john.tiger" <jo...@gmail.com> on 2012/02/16 02:01:03 UTC

using mustache in couchapp

assuming my app.js and mustache.js are in the same attachments folder - 
when I've used:
var Mustache = require('mustache');
=> require not found

do I have to include require.js as well ?




Re: using mustache in couchapp

Posted by "john.tiger" <jo...@gmail.com>.
On 02/16/2012 12:08 AM, Nathan Vander Wilt wrote:
> On Feb 15, 2012, at 5:01 PM, john.tiger wrote:
>> assuming my app.js and mustache.js are in the same attachments folder - when I've used:
>> var Mustache = require('mustache');
>> =>  require not found
>>
>> do I have to include require.js as well ?
> If you want to use JavaScript on the server side, you'll need to store it as a *property* on your design doc. So in a "lib" folder (outside of _attachments) with the 'couchapp' it will get included like:
>
>
> couchapp folder
>    _id file
>    |_ _attachments folder
>        |_ ...clientside media...
>    |_ lib folder
>        |_ mustache.js
>
> <---->
>
> {_id:"<file contents>", _attachments: {...}, lib:{mustache:"<file contents>"}}
>
> Then you would use it in a _show/_list/_update function with `var Mustache = require('lib/mustache')`. When I do need a library both server and clientside with 'couchapp', I tend to symlink it so it appears in both _attachments and other properties.
>
>
> hope this helps,

yes, it does - thks.

Re: using mustache in couchapp

Posted by Nathan Vander Wilt <na...@calftrail.com>.
On Feb 15, 2012, at 5:01 PM, john.tiger wrote:
> assuming my app.js and mustache.js are in the same attachments folder - when I've used:
> var Mustache = require('mustache');
> => require not found
> 
> do I have to include require.js as well ?

If you want to use JavaScript on the server side, you'll need to store it as a *property* on your design doc. So in a "lib" folder (outside of _attachments) with the 'couchapp' it will get included like:


couchapp folder
  _id file
  |_ _attachments folder
      |_ ...clientside media...
  |_ lib folder
      |_ mustache.js

<---->

{_id:"<file contents>", _attachments: {...}, lib:{mustache:"<file contents>"}}

Then you would use it in a _show/_list/_update function with `var Mustache = require('lib/mustache')`. When I do need a library both server and clientside with 'couchapp', I tend to symlink it so it appears in both _attachments and other properties.


hope this helps,
-natevw