Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-693

require function - add support for requiring plain html/xml files in addition to only javascript



    • Improvement
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 0.11
    • None
    • None
    • MacOS X 10.6.2


      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,



      so it would be possible to require something like this
      templates/master.html -->
      <p>That's my content</p>

      and then simply require it using:

      var template = require("templates/master.html");


      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 ...




            Unassigned Unassigned
            ludicco Marcos Zanona
            0 Vote for this issue
            0 Start watching this issue