You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Vivek Pathak <vp...@orgmeta.com> on 2011/07/20 23:18:35 UTC

accessing common data within show function

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.  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

Re: accessing common data within show function

Posted by Keith Gable <zi...@ignition-project.com>.
On Thu, Jul 21, 2011 at 7:42 AM, Vivek Pathak <vp...@orgmeta.com> wrote:

> 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.
>

I take this to mean that you use some sort of editor with a WYSIWYG
interface. Since you're working with fragments of HTML, this is probably not
a good idea.

Re: accessing common data within show function

Posted by Vivek Pathak <vp...@orgmeta.com>.
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<vp...@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<vp...@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
>>>>
>>>>
>>>
>

Re: accessing common data within show function

Posted by Sean Copenhaver <se...@gmail.com>.
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 <vp...@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<vp...@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
>>>
>>>
>>
>>


-- 
“The limits of language are the limits of one's world. “ -Ludwig von
Wittgenstein

Re: accessing common data within show function

Posted by Vivek Pathak <vp...@orgmeta.com>.
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<vp...@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>.
>>   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
>>
>
>

Re: accessing common data within show function

Posted by Sean Copenhaver <se...@gmail.com>.
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 <vp...@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>.
>  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
>



-- 
“The limits of language are the limits of one's world. “ -Ludwig von
Wittgenstein