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 3184670A9 for ; Mon, 26 Sep 2011 15:14:28 +0000 (UTC) Received: (qmail 53797 invoked by uid 500); 26 Sep 2011 15:14:26 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 53763 invoked by uid 500); 26 Sep 2011 15:14:26 -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 53755 invoked by uid 99); 26 Sep 2011 15:14:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2011 15:14:26 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of zachary.zolton@gmail.com designates 209.85.161.180 as permitted sender) Received: from [209.85.161.180] (HELO mail-gx0-f180.google.com) (209.85.161.180) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2011 15:14:20 +0000 Received: by gxk23 with SMTP id 23so5756951gxk.11 for ; Mon, 26 Sep 2011 08:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=nIvHgVTOoQO+Ru3v0+0BXA/uCe73ojAUAg6m5wTwa5A=; b=Dl165WwtX5T5nKDXW6cSP7oIJIrti8sInA3th9dJsJkIEzuWBY/KDB+o/XLPfyl0bQ PmWNb+VgOg6927lG2Q7K5dQGE0FOY5i0CEkkQp134n3XfGCDQUsJ+rFgmNqYvgwdThJj OT6neE688Kam3HzhfstQP4v8NP6z8FnuX4ucY= Received: by 10.68.19.34 with SMTP id b2mr14330263pbe.60.1317050039100; Mon, 26 Sep 2011 08:13:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.143.69.17 with HTTP; Mon, 26 Sep 2011 08:13:38 -0700 (PDT) In-Reply-To: References: From: Zachary Zolton Date: Mon, 26 Sep 2011 10:13:38 -0500 Message-ID: Subject: Re: generate _update body using _show function To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Gert, Move your HTML templates to somewhere in the design doc, for example make an object property called templates. Now, within your update/list/show functions, you can then access them as follows: this.templates.templateName Also, I'd strongly suggest using a templating library (e.g. Mustache.js) instead of string concatenation as this will further simplify your code. Cheers, Zach On Sun, Sep 25, 2011 at 6:36 PM, Gert Cuykens wrot= e: > On Mon, Sep 26, 2011 at 1:33 AM, Gert Cuykens wr= ote: >> Can you call a show function inside a update function to generate a upda= te body? >> Example >> { >> =A0"updates":{ >> =A0"post":"function(doc,req){ >> =A0 for(i in req.form)doc[i]=3Dreq.form[i] >> =A0 return [doc,{'headers':{'Content-Type':'text/html'}, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'body':'\ >> =A0> value=3D\"'+doc.adress+'\"/>
\\n\ >> =A0 =A0> value=3D\"'+doc.city+'\"/>
\\n\ >> > value=3D\"'+doc.country+'\"/>
\\n\ >> =A0 > value=3D\"'+doc.phone+'\"/>
\\n\ >> =A0 > value=3D\"'+doc.email+'\"/>
\\n\ >> \= \n\ >> \\n\ >> ' >> =A0 }] >> =A0}" >> =A0}, >> =A0"shows":{ >> =A0"html":"function(doc,req){ >> =A0 return {headers:{'Content-Type':'text/html'}, >> =A0 =A0 =A0 =A0 =A0 body:'\ >> =A0> value=3D\"'+doc.adress+'\"/>
\\n\ >> =A0 =A0> value=3D\"'+doc.city+'\"/>
\\n\ >> > value=3D\"'+doc.country+'\"/>
\\n\ >> =A0 > value=3D\"'+doc.phone+'\"/>
\\n\ >> =A0 > value=3D\"'+doc.email+'\"/>
\\n\ >> \= \n\ >> \\n\ >> ' >> =A0 } >> =A0}" >> =A0} >> } >> > > Or assign a global variable that can be used in _show and _update functio= ns? >