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.
-
You can reply to this email to add a comment to the issue online.