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 248E47D11 for ; Mon, 26 Sep 2011 17:24:56 +0000 (UTC) Received: (qmail 93026 invoked by uid 500); 26 Sep 2011 17:24:54 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 92974 invoked by uid 500); 26 Sep 2011 17:24:54 -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 92965 invoked by uid 99); 26 Sep 2011 17:24:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2011 17:24:54 +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 (nike.apache.org: domain of gert.cuykens@gmail.com designates 209.85.216.173 as permitted sender) Received: from [209.85.216.173] (HELO mail-qy0-f173.google.com) (209.85.216.173) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2011 17:24:46 +0000 Received: by qyc1 with SMTP id 1so21890344qyc.11 for ; Mon, 26 Sep 2011 10:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=z3AYjQ7xg3u6Azc8fEKQDUXGZzpJpeNzMKQGPjs8Bqw=; b=Iqj9lX+05AhwYppsX5xWNWzdUBpRbnC471G7/4kEMLuLuDFbff38Zjq8NYcZJMzMKW /hNxEsd6TqufUCWh+G6VLupju/jmPE+YY4ycO8x+l5s8yzjALfJfgf8FC4+RqV+cg2PR 1kBJONGPs1K8hZsN9LE3ZIkT17XlRel//IRJ0= MIME-Version: 1.0 Received: by 10.229.186.195 with SMTP id ct3mr5037015qcb.235.1317057865681; Mon, 26 Sep 2011 10:24:25 -0700 (PDT) Received: by 10.229.55.136 with HTTP; Mon, 26 Sep 2011 10:24:25 -0700 (PDT) In-Reply-To: References: Date: Mon, 26 Sep 2011 19:24:25 +0200 Message-ID: Subject: Re: generate _update body using _show function From: Gert Cuykens To: user@couchdb.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Unfortunately templates can only be a static string and not a function? { "validate_doc_update":"function(n,o,u){if(!n['_id'])throw({forbidden:'no _id'})}", "updates":{ "post":"function(doc,req){ for(i in req.form)doc[i]=3Dreq.form[i] return [doc,{headers:{'Content-Type':'text/html'},body:this.innerHTML(do= c)}] }" }, "shows":{"html":"function(doc,req){return {headers:{'Content-Type':'text/html'},body:this.innerHTML(doc)}}"}, "filters":{"design":"function(doc,req){return '_design/'=3D=3D=3Ddoc._id.substr(0,8)}"}, "innerHTML":"function(doc){return '\
\\n\
\\n\
\\n\
\\n\
\\n\ \\n\ \\n\ ' }" } PS syntax debugging design docs in couch db is !!!!!! because it does not show the the character the parser did not like. On Mon, Sep 26, 2011 at 5:13 PM, Zachary Zolton wrote: > 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: > > =C2=A0this.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 wr= ote: >> On Mon, Sep 26, 2011 at 1:33 AM, Gert Cuykens w= rote: >>> Can you call a show function inside a update function to generate a upd= ate body? >>> Example >>> { >>> =C2=A0"updates":{ >>> =C2=A0"post":"function(doc,req){ >>> =C2=A0 for(i in req.form)doc[i]=3Dreq.form[i] >>> =C2=A0 return [doc,{'headers':{'Content-Type':'text/html'}, >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'body':'\ >>> =C2=A0>> value=3D\"'+doc.adress+'\"/>
\\n\ >>> =C2=A0 =C2=A0>> value=3D\"'+doc.city+'\"/>
\\n\ >>> >> value=3D\"'+doc.country+'\"/>
\\n\ >>> =C2=A0 >> value=3D\"'+doc.phone+'\"/>
\\n\ >>> =C2=A0 >> value=3D\"'+doc.email+'\"/>
\\n\ >>> \\n\ >>> \\n\ >>> ' >>> =C2=A0 }] >>> =C2=A0}" >>> =C2=A0}, >>> =C2=A0"shows":{ >>> =C2=A0"html":"function(doc,req){ >>> =C2=A0 return {headers:{'Content-Type':'text/html'}, >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 body:'\ >>> =C2=A0>> value=3D\"'+doc.adress+'\"/>
\\n\ >>> =C2=A0 =C2=A0>> value=3D\"'+doc.city+'\"/>
\\n\ >>> >> value=3D\"'+doc.country+'\"/>
\\n\ >>> =C2=A0 >> value=3D\"'+doc.phone+'\"/>
\\n\ >>> =C2=A0 >> value=3D\"'+doc.email+'\"/>
\\n\ >>> \\n\ >>> \\n\ >>> ' >>> =C2=A0 } >>> =C2=A0}" >>> =C2=A0} >>> } >>> >> >> Or assign a global variable that can be used in _show and _update functi= ons? >> >