Details
Description
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 =
; /* <-- 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,
</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 ...