Return-Path: Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: (qmail 99485 invoked from network); 12 Apr 2010 03:36:05 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 12 Apr 2010 03:36:05 -0000 Received: (qmail 42649 invoked by uid 500); 12 Apr 2010 03:36:05 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 42494 invoked by uid 500); 12 Apr 2010 03:36:04 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 42485 invoked by uid 99); 12 Apr 2010 03:36:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Apr 2010 03:36:04 +0000 X-ASF-Spam-Status: No, hits=-1264.3 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Apr 2010 03:36:02 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o3C3ZfVP022024 for ; Sun, 11 Apr 2010 23:35:41 -0400 (EDT) Message-ID: <13486782.15621271043341746.JavaMail.jira@thor> Date: Sun, 11 Apr 2010 23:35:41 -0400 (EDT) From: "Chris Anderson (JIRA)" To: dev@couchdb.apache.org Subject: [jira] Resolved: (COUCHDB-693) require function - add support for requiring plain html/xml files in addition to only javascript In-Reply-To: <1039134071.235731268428767188.JavaMail.jira@brutus.apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/COUCHDB-693?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Chris Anderson resolved COUCHDB-693. ------------------------------------ Resolution: Fixed Thanks for the report. Sorry I didn't see it earlier. The proper way to do this in _show _list etc function (where require is available, is to use 'this' which refers to the design document. So you can load templates like: function(doc, req) { var template = this.templates.entry; var Mustache = require("lib/mustache"); return Mustache.to_html(template, doc); } For more examples see Sofa: http://github.com/jchris/sofa/blob/master/shows/edit.js Chris > require function - add support for requiring plain html/xml files in addition to only javascript > ------------------------------------------------------------------------------------------------ > > Key: COUCHDB-693 > URL: https://issues.apache.org/jira/browse/COUCHDB-693 > Project: CouchDB > Issue Type: Improvement > Affects Versions: 0.11 > Environment: MacOS X 10.6.2 > Reporter: Marcos Zanona > Priority: Trivial > > It seems that for now every require function on the main.js it is created an empty exports object which is returned after the call. > I would suggest that instead of creating one empty exports object: > -- > var require = function(name, parent) { > var exports = {}; > var resolved = resolveModule(name.split('/'), parent, ddoc); > var source = resolved[0]; > parent = resolved[1]; > ... > --- > that one pre-populated object could be created: > --- > var require = function(name, parent) { > var resolved = resolveModule(name.split('/'), parent, ddoc); > var source = resolved[0]; > var exports = {"source" : source}; /* <-- this would populate the exports with an embedded source */ > parent = resolved[1]; > -- > this done, users would be able to require plain plain html/xml files directly without need to declare any javascript variable or exports... > this is very nice for templating specifically because javascript support xml syntax without any problem and also it's possible declare javascript variables inside the xml like

Hello there, {name}

> so it would be possible to require something like this > templates/master.html --> > > > title > > >

That's my content

> > > ---- > and then simply require it using: > var template = require("templates/master.html"); > send(template.source); > --- > I'm still trying to adjust it to be possible for user to just user plain text files without quotes which would increase the possibilities for users to create their own view engines such as HAML and SASS. > In case the user is using just regular javascript he can easily overwrite the source variable with exports.source ... -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira