incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vivek Pathak <vpat...@orgmeta.com>
Subject Re: accessing common data within show function
Date Thu, 21 Jul 2011 12:42:40 GMT
I tried using require, but from what I could gather through trial and 
error, I would need to wrap the html in a js wrapper like this:

var exports.html = ' ... html code .... ' ;

This would make it hard to edit the html in a normal editor.  Now I can 
keep my (templatized) html intact in a file, and upload it to a place it 
couchdb.

Is there a way to use "require" that can help me?  I saw the usages 
given on the web page http://wiki.apache.org/couchdb/CommonJS_Modules , 
but could not figure out a way of making my case work.  In particular, 
if the field fld_name has the raw templatized html code, then I would 
like to do this in show fn:

var html_template = require( "common/html/fld_name" ) ;

I tried a number of variants of the above but couldnt get it to work.  
Also, is there an inherent advantage of using require?

Thanks!


On 07/21/2011 07:39 AM, Sean Copenhaver wrote:
> I was going to suggest making a module that had all your static data in it
> and just require it in to use. Added benefit of being able to use it in
> other design doc functions that support CommonJS modules and also using it
> in node.js if you ever needed to.
>
> Sounds like you are doing something similar but navigating the object path
> of the design document instead of a require() call.
>
> On Wed, Jul 20, 2011 at 5:47 PM, Vivek Pathak<vpathak@orgmeta.com>  wrote:
>
>> It is static data.  thanks, i already got it working by using the "this"
>> object within show function (which points to the _design/<designname>
>> object) .  eg:
>>
>> var html = this.common.html.<fld_name>  ;
>>
>>
>>
>>
>>
>>
>> On 07/20/2011 05:26 PM, Sean Copenhaver wrote:
>>
>>> Is this data that is constantly changing and would not be present in the
>>> document being transformed? Or is this static data?
>>>
>>> On Wed, Jul 20, 2011 at 5:18 PM, Vivek Pathak<vpathak@orgmeta.com>
>>>   wrote:
>>>
>>>   Hi
>>>> I would like access common data within my show functions.  What I need is
>>>> very much like accessing common code using the require() function as
>>>> shown
>>>> here:  http://wiki.apache.org/****couchdb/CommonJS_Modules<http://wiki.apache.org/**couchdb/CommonJS_Modules>
>>>> <http:**//wiki.apache.org/couchdb/**CommonJS_Modules<http://wiki.apache.org/couchdb/CommonJS_Modules>
>>>>> .
>>>>   Instead of accessing code, I would like to assign the common data to a
>>>> local js variable.
>>>>
>>>> Is there a simple way to do it?
>>>>
>>>> Thanks
>>>> Vivek Pathak
>>>>
>>>>
>>>
>

Mime
View raw message