Commits

kai zhu  committed 4ba23c9

modify stringFormat to use standard javascript attribute access

  • Participants
  • Parent commits 89e2fef

Comments (0)

Files changed (2)

File libBootstrap.js

         if (!fnd) { break; }
         file = JSON.parse(fnd[1]);
         //// save pseudo-file's source code
-        EXPORTS.MODULE_FILE[file.name] = local.stringFormat(
+        EXPORTS.MODULE_FILE[file.name] = EXPORTS.stringFormat(
           str.slice(0, rgx.lastIndex - fnd[0].length).replace((/[^\n]+/g), '') + fnd[2],
           { EXPORTS: EXPORTS }
         );
 
     stringFormat: function (str, obj) {
       //// shared client / server template engine
-      var arr, fnd, flag, ii, jj, result, rgx, val;
+      var arr, fnd, fnd2, flag, ii, jj, result, rgx, rgx2, val;
       if (!(obj && (/\{\{/).test(str))) { return str; }
       ii = 0;
       result = '';
-      rgx = (/\{\{(\w[\w\-\.\/\\]*)([ \w]*)\}\}/g);
+      rgx = (/\{\{(\w[^}]+)([ \w]*)\}\}/g);
       while (true) {
         fnd = rgx.exec(str);
         //// stop searching for strings to replace
         if (!fnd) { break; }
         result += str.slice(ii, fnd.index);
         //// get attribute from obj
-        arr = fnd[1].replace(/\\\./g, '\\').split('.');
-        ii = fnd.index + fnd[0].length;
+        rgx2 = (/["']([^"']+)["']|(\w+)/g);
         val = obj;
-        for (jj = 0; jj < arr.length; jj += 1) {
-          if ((val = val[arr[jj].replace(/\\/g, '.')]) === undefined) { break; }
+        while (true) {
+          fnd2 = rgx2.exec(fnd[1]);
+          ii = fnd.index + fnd[0].length;
+          if (!(fnd2 && val)) { break; }
+          val = val[fnd2[1] || fnd2[2]];
         }
         if (val === undefined) {
           result += fnd[0];

File libUnstable.js2

 /*
 CHANGELOG
-add cache versioning for /public/cacheVersion
+modify stringFormat to use standard javascript attribute access
 
 TODO
-modify stringFormat to use standard javascript attribute access
 add optional istanbul coverage in require
 add client side interactive tests
 rewrite db