Permalink
Browse files

Initial code drop

  • Loading branch information...
1 parent dfe07c5 commit 0ed4c052543b00feebc08868fd8cb2b7fb7fe385 @BorisMoore committed Jun 18, 2011
Showing with 22,223 additions and 0 deletions.
  1. +1 −0 README.md
  2. +77 −0 src/dot.js
  3. +8,374 −0 src/jquery-1.5.2.js
  4. +3,797 −0 src/jquery-templates-strappend-auto.js
  5. +1 −0 src/jquery-templates-strappend-auto.min.js
  6. +938 −0 src/jquery-templates-strappend.js
  7. +1 −0 src/jquery-templates-strappend.min.js
  8. +3,856 −0 src/jquery-templates-strappend2-auto.js
  9. +1,003 −0 src/jquery-templates-strappend2.js
  10. +7 −0 src/jquery-templates-strappend2.min.js
  11. +384 −0 src/jquery.render.js
  12. +6 −0 src/jquery.render.min.js
  13. +484 −0 src/jquery.tmpl.js
  14. +10 −0 src/jquery.tmpl.min.js
  15. +21 −0 tests/benchmarks/benchmarks.html
  16. +63 −0 tests/benchmarks/bm_dot.html
  17. +63 −0 tests/benchmarks/bm_jquery-tmpl-encode.html
  18. +63 −0 tests/benchmarks/bm_jquery-tmpl.html
  19. +63 −0 tests/benchmarks/bm_jsrender-encode.html
  20. +63 −0 tests/benchmarks/bm_jsrender.html
  21. +75 −0 tests/benchmarks/bm_nest_jsrender.html
  22. +75 −0 tests/benchmarks/bm_nest_strappend2.html
  23. +63 −0 tests/benchmarks/bm_strappend-auto-encode.html
  24. +63 −0 tests/benchmarks/bm_strappend-auto.html
  25. +62 −0 tests/benchmarks/bm_strappend-encode.html
  26. +63 −0 tests/benchmarks/bm_strappend.html
  27. +63 −0 tests/benchmarks/bm_strappend2-auto.html
  28. +63 −0 tests/benchmarks/bm_strappend2.html
  29. +47 −0 tests/jsrender/01_local-data.html
  30. +58 −0 tests/jsrender/02_html-tag.html
  31. +64 −0 tests/jsrender/03_if-else-tag.html
  32. +74 −0 tests/jsrender/04_each-tag.html
  33. +87 −0 tests/jsrender/05_javascript.html
  34. +72 −0 tests/jsrender/06_hierarchical-data.html
  35. +104 −0 tests/jsrender/07_tabs-using-wrap-tag.html
  36. +667 −0 tests/jsrender/conformance-suite.html
  37. +13 −0 tests/jsrender/conformance.html
  38. +7 −0 tests/resources/demos.css
  39. +7 −0 tests/resources/movielist.css
  40. +47 −0 tests/strappend2/01_local-data.html
  41. +58 −0 tests/strappend2/02_html-tag.html
  42. +64 −0 tests/strappend2/03_if-else-tag.html
  43. +74 −0 tests/strappend2/04_each-tag.html
  44. +87 −0 tests/strappend2/05_javascript.html
  45. +71 −0 tests/strappend2/06_hierarchical-data.html
  46. +104 −0 tests/strappend2/NOT SUPPORTED 07_tabs-using-wrap-tag.html
  47. +683 −0 tests/strappend2/conformance-suite.html
  48. +13 −0 tests/strappend2/conformance.html
  49. +20 −0 tests/tests.html
View
@@ -0,0 +1 @@
+Tests to compare ongoing implementations of jQuery Templates
View
@@ -0,0 +1,77 @@
+// doT.js
+// 2011, Laura Doktorova
+// https://github.com/olado/doT
+//
+// doT is a custom blend of templating functions from jQote2.js
+// (jQuery plugin) by aefxx (http://aefxx.com/jquery-plugins/jqote2/)
+// and underscore.js (http://documentcloud.github.com/underscore/)
+// plus extensions.
+//
+// Licensed under the MIT license.
+//
+(function() {
+ var doT = { version : '0.1.5' };
+
+ if (typeof module !== 'undefined' && module.exports) {
+ module.exports = doT;
+ } else {
+ this.doT = doT;
+ }
+
+ doT.templateSettings = {
+ evaluate: /\{\{([\s\S]+?)\}\}/g,
+ interpolate: /\{\{=([\s\S]+?)\}\}/g,
+ encode: /\{\{!([\s\S]+?)\}\}/g,
+ use: /\{\{#([\s\S]+?)\}\}/g, //compile time evaluation
+ define: /\{\{#\s*([\w$]+)\s*\:([\s\S]+?)#\}\}/g, //compile time defs
+ varname: 'it',
+ strip : true,
+ append: true
+ };
+
+ function resolveDefs(define, use, str, defs) {
+ return str.replace(define, function (match, code, value) {
+ if (!(code in defs)) defs[code]=value;
+ return '';
+ })
+ .replace(use, function(match, code) {
+ var value; // todo: detect circular use and convert into compiled functions
+ with(defs) {try { value = eval(code);} catch(e) { value='';} }
+ return value ? resolveDefs(define, use, value.toString(), defs) : value;
+ });
+ }
+
+ doT.template = function(tmpl, c, defs) {
+ c = c || doT.templateSettings;
+ var cstart = c.append ? "'+(" : "';out+=(", // optimal choice depends on platform/size of templates
+ cend = c.append ? ")+'" : ");out+='";
+ var str = (c.use || c.define) ? resolveDefs(c.define, c.use, tmpl, defs || {}) : tmpl;
+
+ str = ("var out='" +
+ ((c.strip) ? str.replace(/\s*<!\[CDATA\[\s*|\s*\]\]>\s*|[\r\n\t]|(\/\*[\s\S]*?\*\/)/g, ''): str)
+ .replace(/\\/g, '\\\\')
+ .replace(/'/g, "\\'")
+ .replace(c.interpolate, function(match, code) {
+ return cstart + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + cend;
+ })
+ .replace(c.encode, function(match, code) {
+ return cstart + code.replace(/\\'/g, "'").replace(/\\\\/g, "\\").replace(/[\r\t\n]/g, ' ') + ").toString().replace(/&(?!\\w+;)/g, '&#38;').split('<').join('&#60;').split('>').join('&#62;').split('" + '"' + "').join('&#34;').split(" + '"' + "'" + '"' + ").join('&#39;').split('/').join('&#x2F;'" + cend;
+ })
+ .replace(c.evaluate, function(match, code) {
+ return "';" + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + "out+='";
+ })
+ + "';return out;")
+ .replace(/\n/g, '\\n')
+ .replace(/\t/g, '\\t')
+ .replace(/\r/g, '\\r')
+ .split("out+='';").join('')
+ .split("var out='';out+=").join('var out=');
+
+ try {
+ return new Function(c.varname, str);
+ } catch (e) {
+ if (typeof console !== 'undefined') console.log("Could not create a template function: " + str);
+ throw e;
+ }
+ };
+}());
Oops, something went wrong.

0 comments on commit 0ed4c05

Please sign in to comment.