[
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 <p>Hello there, {name}</p>
> so it would be possible to require something like this
> templates/master.html -->
> <html>
> <head>
> <title>title</title>
> </head>
> <body>
> <p>That's my content</p>
> </body>
> </html>
> ----
> 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