Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1F57863D8 for ; Thu, 21 Jul 2011 12:43:15 +0000 (UTC) Received: (qmail 8537 invoked by uid 500); 21 Jul 2011 12:43:13 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 8423 invoked by uid 500); 21 Jul 2011 12:43:12 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 8414 invoked by uid 99); 21 Jul 2011 12:43:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jul 2011 12:43:11 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: 209.85.216.173 is neither permitted nor denied by domain of vpathak@orgmeta.com) Received: from [209.85.216.173] (HELO mail-qy0-f173.google.com) (209.85.216.173) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jul 2011 12:43:04 +0000 Received: by qyk10 with SMTP id 10so3962847qyk.11 for ; Thu, 21 Jul 2011 05:42:43 -0700 (PDT) Received: by 10.224.193.137 with SMTP id du9mr187087qab.115.1311252162846; Thu, 21 Jul 2011 05:42:42 -0700 (PDT) Received: from [192.168.1.111] (c-68-45-67-155.hsd1.pa.comcast.net [68.45.67.155]) by mx.google.com with ESMTPS id m7sm815331qct.5.2011.07.21.05.42.41 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 21 Jul 2011 05:42:41 -0700 (PDT) Message-ID: <4E281EC0.8000308@orgmeta.com> Date: Thu, 21 Jul 2011 08:42:40 -0400 From: Vivek Pathak User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Thunderbird/3.1.11 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: accessing common data within show function References: <4E27462B.8000703@orgmeta.com> <4E274CEB.1020409@orgmeta.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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 wrote: > >> It is static data. thanks, i already got it working by using the "this" >> object within show function (which points to the _design/ >> object) . eg: >> >> var html = this.common.html. ; >> >> >> >> >> >> >> 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 >>> 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 >>>> >>>>> . >>>> 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 >>>> >>>> >>> >