MDL-65758 library: Add Moodle modifications for Mustache
[moodle.git] / lib / amd / build / mustache.min.js
CommitLineData
d712127f 1!function(a,b){"object"==typeof exports&&exports&&"string"!=typeof exports.nodeName?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a.Mustache={},b(a.Mustache))}(this,function(a){function b(a){return"function"==typeof a}function c(a){return q(a)?"array":typeof a}function d(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function e(a,b){return null!=a&&"object"==typeof a&&b in a}function f(a,b){return null!=a&&"object"!=typeof a&&a.hasOwnProperty&&a.hasOwnProperty(b)}function g(a,b){return r.call(a,b)}function h(a){return!g(s,a)}function i(a){return String(a).replace(/[&<>"'`=\/]/g,function(a){return t[a]})}function j(b,c){function e(){if(r&&!s)for(;p.length;)delete o[p.pop()];else p=[];r=!1,s=!1}function f(a){if("string"==typeof a&&(a=a.split(v,2)),!q(a)||2!==a.length)throw new Error("Invalid tags: "+a);g=new RegExp(d(a[0])+"\\s*"),i=new RegExp("\\s*"+d(a[1])),j=new RegExp("\\s*"+d("}"+a[1]))}if(!b)return[];var g,i,j,n=[],o=[],p=[],r=!1,s=!1;f(c||a.tags);for(var t,z,A,B,C,D,E=new m(b);!E.eos();){if(t=E.pos,A=E.scanUntil(g))for(var F=0,G=A.length;F<G;++F)B=A.charAt(F),h(B)?p.push(o.length):s=!0,o.push(["text",B,t,t+1]),t+=1,"\n"===B&&e();if(!E.scan(g))break;if(r=!0,z=E.scan(y)||"name",E.scan(u),"="===z?(A=E.scanUntil(w),E.scan(w),E.scanUntil(i)):"{"===z?(A=E.scanUntil(j),E.scan(x),E.scanUntil(i),z="&"):A=E.scanUntil(i),!E.scan(i))throw new Error("Unclosed tag at "+E.pos);if(C=[z,A,t,E.pos],o.push(C),"#"===z||"^"===z||"$"===z||"<"===z)n.push(C);else if("/"===z){if(D=n.pop(),!D)throw new Error('Unopened section "'+A+'" at '+t);if(D[1]!==A)throw new Error('Unclosed section "'+D[1]+'" at '+t)}else"name"===z||"{"===z||"&"===z?s=!0:"="===z&&f(A)}if(D=n.pop())throw new Error('Unclosed section "'+D[1]+'" at '+E.pos);return l(k(o))}function k(a){for(var b,c,d=[],e=0,f=a.length;e<f;++e)b=a[e],b&&("text"===b[0]&&c&&"text"===c[0]?(c[1]+=b[1],c[3]=b[3]):(d.push(b),c=b));return d}function l(a){for(var b,c,d=[],e=d,f=[],g=0,h=a.length;g<h;++g)switch(b=a[g],b[0]){case"$":case"<":case"#":case"^":e.push(b),f.push(b),e=b[4]=[];break;case"/":c=f.pop(),c[5]=b[2],e=f.length>0?f[f.length-1][4]:d;break;default:e.push(b)}return d}function m(a){this.string=a,this.tail=a,this.pos=0}function n(a,b){this.view=a,this.blocks={},this.cache={".":this.view},this.parent=b}function o(){this.cache={}}var p=Object.prototype.toString,q=Array.isArray||function(a){return"[object Array]"===p.call(a)},r=RegExp.prototype.test,s=/\S/,t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"},u=/\s*/,v=/\s+/,w=/\s*=/,x=/\s*\}/,y=/#|\^|\/|>|\{|&|=|!|\$|</;m.prototype.eos=function(){return""===this.tail},m.prototype.scan=function(a){var b=this.tail.match(a);if(!b||0!==b.index)return"";var c=b[0];return this.tail=this.tail.substring(c.length),this.pos+=c.length,c},m.prototype.scanUntil=function(a){var b,c=this.tail.search(a);switch(c){case-1:b=this.tail,this.tail="";break;case 0:b="";break;default:b=this.tail.substring(0,c),this.tail=this.tail.substring(c)}return this.pos+=b.length,b},n.prototype.push=function(a){return new n(a,this)},n.prototype.setBlockVar=function(a,b){var c=this.blocks;return c[a]=b,b},n.prototype.clearBlockVars=function(){this.blocks={}},n.prototype.getBlockVar=function(a){var b,c=this.blocks;return c.hasOwnProperty(a)?b=c[a]:this.parent&&(b=this.parent.getBlockVar(a)),b},n.prototype.lookup=function(a){var c,d=this.cache;if(d.hasOwnProperty(a))c=d[a];else{for(var g,h,i,j=this,k=!1;j;){if(a.indexOf(".")>0)for(g=j.view,h=a.split("."),i=0;null!=g&&i<h.length;)i===h.length-1&&(k=e(g,h[i])||f(g,h[i])),g=g[h[i++]];else g=j.view[a],k=e(j.view,a);if(k){c=g;break}j=j.parent}d[a]=c}return b(c)&&(c=c.call(this.view)),c},o.prototype.clearCache=function(){this.cache={}},o.prototype.parse=function(b,c){var d=this.cache,e=b+":"+(c||a.tags).join(":"),f=d[e];return null==f&&(f=d[e]=j(b,c)),f},o.prototype.render=function(a,b,c,d){var e=this.parse(a,d),f=b instanceof n?b:new n(b);return this.renderTokens(e,f,c,a,d)},o.prototype.renderTokens=function(a,b,c,d,e){for(var f,g,h,i="",j=0,k=a.length;j<k;++j)h=void 0,f=a[j],g=f[0],"#"===g?h=this.renderSection(f,b,c,d):"^"===g?h=this.renderInverted(f,b,c,d):">"===g?h=this.renderPartial(f,b,c,e):"<"===g?h=this.renderBlock(f,b,c,d):"$"===g?h=this.renderBlockVariable(f,b,c,d):"&"===g?h=this.unescapedValue(f,b):"name"===g?h=this.escapedValue(f,b):"text"===g&&(h=this.rawValue(f)),void 0!==h&&(i+=h);return i},o.prototype.renderSection=function(a,c,d,e){function f(a){return g.render(a,c,d)}var g=this,h="",i=c.lookup(a[1]);if(i){if(q(i))for(var j=0,k=i.length;j<k;++j)h+=this.renderTokens(a[4],c.push(i[j]),d,e);else if("object"==typeof i||"string"==typeof i||"number"==typeof i)h+=this.renderTokens(a[4],c.push(i),d,e);else if(b(i)){if("string"!=typeof e)throw new Error("Cannot use higher-order sections without the original template");i=i.call(c.view,e.slice(a[3],a[5]),f),null!=i&&(h+=i)}else h+=this.renderTokens(a[4],c,d,e);return h}},o.prototype.renderInverted=function(a,b,c,d){var e=b.lookup(a[1]);if(!e||q(e)&&0===e.length)return this.renderTokens(a[4],b,c,d)},o.prototype.renderPartial=function(a,c,d,e){if(d){var f=b(d)?d(a[1]):d[a[1]];return null!=f?this.renderTokens(this.parse(f,e),c,d,f):void 0}},o.prototype.renderBlock=function(a,c,d,e){if(d){var f=b(d)?d(a[1]):d[a[1]];null!=f&&c.clearBlockVars(),this.renderTokens(a[4],c,d,e);var g=this.renderTokens(this.parse(f),c,d,f);return c.clearBlockVars(),g}},o.prototype.renderBlockVariable=function(a,b,c,d){var e=a[1],f=b.getBlockVar(e);return f?this.renderTokens(this.parse(f),b,c,f):(b.setBlockVar(e,d.slice(a[3],a[5])),this.renderTokens(a[4],b,c,d))},o.prototype.unescapedValue=function(a,b){var c=b.lookup(a[1]);if(null!=c)return c},o.prototype.escapedValue=function(b,c){var d=c.lookup(b[1]);if(null!=d)return a.escape(d)},o.prototype.rawValue=function(a){return a[1]},a.name="mustache.js",a.version="3.0.1",a.tags=["{{","}}"];var z=new o;return a.clearCache=function(){return z.clearCache()},a.parse=function(a,b){return z.parse(a,b)},a.render=function(a,b,d,e){if("string"!=typeof a)throw new TypeError('Invalid template! Template should be a "string" but "'+c(a)+'" was given as the first argument for mustache#render(template, view, partials)');return z.render(a,b,d,e)},a.to_html=function(c,d,e,f){var g=a.render(c,d,e);return b(f)?void f(g):g},a.escape=i,a.Scanner=m,a.Context=n,a.Writer=o,a});