-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmustache.js
13 lines (13 loc) · 4.6 KB
/
mustache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
*/
define(function(){var r="undefined"!==typeof module&&module.exports||{};(function(j){function r(a){return(""+a).replace(/&(?!\w+;)|[<>"']/g,function(a){return H[a]||a})}function u(a,c,d,e){for(var e=e||"<template>",b=c.split("\n"),f=Math.max(d-3,0),g=Math.min(b.length,d+3),b=b.slice(f,g),i=0,l=b.length;i<l;++i)g=i+f+1,b[i]=(g===d?" >> ":" ")+b[i];a.template=c;a.line=d;a.file=e;a.message=[e+":"+d,b.join("\n"),"",a.message].join("\n");return a}function y(a,c,d){if("."===a)return c[c.length-1];for(var a=
a.split("."),e=a.length-1,b=a[e],f,g,i=c.length,l,j;i;){j=c.slice(0);g=c[--i];for(l=0;l<e;){g=g[a[l++]];if(null==g)break;j.push(g)}if(g&&"object"===typeof g&&b in g){f=g[b];break}}"function"===typeof f&&(f=f.call(j[j.length-1]));return null==f?d:f}function I(a,c,d,e){var b="",a=y(a,c);if(e){if(null==a||!1===a||v(a)&&0===a.length)b+=d()}else if(v(a))z(a,function(a){c.push(a);b+=d();c.pop()});else if("object"===typeof a)c.push(a),b+=d(),c.pop();else if("function"===typeof a)var f=c[c.length-1],b=b+
(a.call(f,d(),function(a){return n(a,f)})||"");else a&&(b+=d());return b}function A(a,c){for(var c=c||{},d=c.tags||j.tags,e=d[0],b=d[d.length-1],f=['var buffer = "";',"\nvar line = 1;","\ntry {",'\nbuffer += "'],g=[],i=!1,l=!1,r=function(){if(i&&!l&&!c.space)for(;g.length;)f.splice(g.pop(),1);else g=[];l=i=!1},o=[],w,n,q,v=function(a){d=p(a).split(/\s+/);n=d[0];q=d[d.length-1]},x=function(a){f.push('";',w,'\nvar partial = partials["'+p(a)+'"];',"\nif (partial) {","\n buffer += render(partial,stack[stack.length - 1],partials);",
"\n}",'\nbuffer += "')},t=function(b,d){var e=p(b);if(""===e)throw u(Error("Section name may not be empty"),a,s,c.file);o.push({name:e,inverted:d});f.push('";',w,'\nvar name = "'+e+'";',"\nvar callback = (function () {","\n return function () {",'\n var buffer = "";','\nbuffer += "')},y=function(a){t(a,!0)},z=function(b){var b=p(b),d=0!=o.length&&o[o.length-1].name;if(!d||b!=d)throw u(Error('Section named "'+b+'" was never opened'),a,s,c.file);b=o.pop();f.push('";',"\n return buffer;","\n };",
"\n})();");b.inverted?f.push("\nbuffer += renderSection(name,stack,callback,true);"):f.push("\nbuffer += renderSection(name,stack,callback);");f.push('\nbuffer += "')},A=function(a){f.push('";',w,'\nbuffer += lookup("'+p(a)+'",stack,"");','\nbuffer += "')},B=function(a){f.push('";',w,'\nbuffer += escapeHTML(lookup("'+p(a)+'",stack,""));','\nbuffer += "')},s=1,m,k,h=0,C=a.length;h<C;++h)if(a.slice(h,h+e.length)===e){h+=e.length;m=a.substr(h,1);w="\nline = "+s+";";n=e;q=b;i=!0;switch(m){case "!":h++;
k=null;break;case "=":h++;b="="+b;k=v;break;case ">":h++;k=x;break;case "#":h++;k=t;break;case "^":h++;k=y;break;case "/":h++;k=z;break;case "{":b="}"+b;case "&":h++;l=!0;k=A;break;default:l=!0,k=B}m=a.indexOf(b,h);if(-1===m)throw u(Error('Tag "'+e+'" was not closed properly'),a,s,c.file);e=a.substring(h,m);k&&k(e);for(k=0;~(k=e.indexOf("\n",k));)s++,k++;h=m+b.length-1;e=n;b=q}else switch(m=a.substr(h,1),m){case '"':case "\\":l=!0;f.push("\\"+m);break;case "\r":break;case "\n":g.push(f.length);f.push("\\n");
r();s++;break;default:D.test(m)?g.push(f.length):l=!0,f.push(m)}if(0!=o.length)throw u(Error('Section "'+o[o.length-1].name+'" was not closed properly'),a,s,c.file);r();f.push('";',"\nreturn buffer;","\n} catch (e) { throw {error: e, line: line}; }");b=f.join("").replace(/buffer \+= "";\n/g,"");c.debug&&("undefined"!=typeof console&&console.log?console.log(b):"function"===typeof print&&print(b));return b}function B(a,c){var d=A(a,c),e=new Function("view,partials,stack,lookup,escapeHTML,renderSection,render",
d);return function(b,d){var d=d||{},g=[b];try{return e(b,d,g,y,r,I,n)}catch(i){throw u(i.error,a,i.line,c.file);}}}function C(a,c){c=c||{};return!1!==c.cache?(q[a]||(q[a]=B(a,c)),q[a]):B(a,c)}function n(a,c,d){return C(a)(c,d)}j.name="mustache.js";j.version="0.5.0-dev";j.tags=["{{","}}"];j.parse=A;j.compile=C;j.render=n;j.clearCache=function(){q={}};j.to_html=function(a,c,d,e){a=n(a,c,d);if("function"===typeof e)e(a);else return a};var J=Object.prototype.toString,E=Array.isArray,F=Array.prototype.forEach,
G=String.prototype.trim,v;v=E?E:function(a){return"[object Array]"===J.call(a)};var z;z=F?function(a,c,d){return F.call(a,c,d)}:function(a,c,d){for(var e=0,b=a.length;e<b;++e)c.call(d,a[e],e,a)};var D=/^\s*$/,p;if(G)p=function(a){return null==a?"":G.call(a)};else{var x,t;D.test("\u00a0")?(x=/^\s+/,t=/\s+$/):(x=/^[\s\xA0]+/,t=/[\s\xA0]+$/);p=function(a){return a==null?"":(""+a).replace(x,"").replace(t,"")}}var H={"&":"&","<":"<",">":">",'"':""","'":"'"},q={}})(r);return r});