forked from janl/mustache.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmustache.min.js
1 lines (1 loc) · 8.14 KB
/
mustache.min.js
1
var Mustache=function(e){"use strict";function n(){}function s(e){if(!i){var t=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];i=new RegExp("(\\"+t.join("|\\")+")","g")}return e.replace(i,"\\$1")}function u(e){return e.match(o)}function a(e){return e.match(/^\s*$/)}function f(e){return e&&typeof e=="function"}function l(e){return e&&typeof e=="object"}function c(e){return r.call(e)==="[object Array]"}function h(e){return e===!1||e===0||e}function v(){return{is_standalone:!0,tags:0}}function m(t,n){function r(e){return function(){return e}}var i,s,o;for(i=t.tokens.length;t.cursor<i&&!t.terminated;++t.cursor){o=t.tokens[t.cursor];if(o===""||o===e)continue;t.standalone.tags>1&&(t.standalone.is_standalone=!1),t.metrics.character===1&&t.leadingWhitespace!==""&&t.assemble(r(t.leadingWhitespace)),o.indexOf(t.openTag)===0?(s=o.charAt(t.openTag.length),t.standalone.tags++,t.parser[s]?t.parser[s](t,o,s):t.parser.def(t,o)):t.parser.text(t,o),u(o)?(t.metrics.character=1,t.metrics.line++,t.standalone=v()):t.metrics.character+=o.length}t.standalone.tags===0&&(t.standalone.is_standalone=!1);if(t.parser===H&&!t.terminated)throw new d('Closing section tag "'+t.section.variable+'" expected.',t.metrics);if(!n)return function(e){var n="",r,i;for(r=0;i=t.code[r++];)n+=i(e)||"";return n}}function y(e,n,r,i){r=r||"{{",i=i||"}}";var o;if(r==="{{"&&i==="}}")o=g;else{var u=s(r),a=s(i),f=["(\\r?\\n)","("+u+"![\\s\\S]*?!"+a+")","("+u+"[#^/&>]?\\s*[^!{=]\\S*?\\s*"+a+")","("+u+"{\\s*\\S*?\\s*}"+a+")","("+u+"=\\s*\\S*?\\s*\\S*?=\\s*"+a+")"];o=new RegExp(f.join("|"))}var l=[],c={metrics:{partial:null,line:1,character:1},template:e||"",partials:n||{},openTag:r,closeTag:i,parser:P,standalone:v(),leadingWhitespace:"",code:l,assemble:function(e){l.push(e)}};return c.tokens=t.call(c.template,o),c.cursor=0,c}function b(e,t){var n=t[e];if(h(n))return f(n)?n.apply(t):n}function w(t,n,r){var i,s=n.length,o=s,u;do{i=b(t,n[--o]);if(i!==e){if(!!r&&o>0&&(l(i)||c(i))){for(u=o+1;u<s;++u)if(n[u]===i){i=e;break}if(i===e)continue;break}break}}while(o!==0);return i}function E(t,n,r){if(t===".")return b(".",{".":n[n.length-1]});var i=t.indexOf(".")===-1?[t]:t.split("."),s=1,o=i.length,u=w(i[0],n,r);while(u&&s<o)u=b(i[s],u),s++;return s!==o&&!u&&(u=e),u}function S(e,t){if(e.metrics.character===1&&a(t)&&!u(t)){var n=e.standalone;n.token=t,e.assemble(function(){if(!n.is_standalone)return t})}else if(!e.standalone.is_standalone||!u(t)||e.standalone.tags!==1)e.standalone.is_standalone=!1,e.assemble(function(){return t})}function x(t,n,r){var i,s,o;r==="{"?i=s=o=!0:r==="&"&&(i=s=!0),t.standalone.is_standalone=!1,t.assemble(function(t,n){return function(r){var i=E(t,r);if(i!==e)return n||(i=p(""+i)),""+i}}(C(t,n,s,o),i))}function T(e,t){var r=C(e,t,!0),i;e.partials[r]||(e.partials[r]=n);if(!f(e.partials[r])){i=e.partials[r],e.partials[r]=n;var s=y(i,e.partials);s.leadingWhitespace+=e.leadingWhitespace,e.standalone.is_standalone&&(s.leadingWhitespace+=e.standalone.token||""),s.metrics.partial=r,e.partials[r]=m(s)}e.assemble(function(t){return e.partials[r](t)})}function N(e){var t=e.section,n=t.template_buffer,r,i=y(n,e.partials,e.openTag,e.closeTag);i.standalone.is_standalone=t.standalone.is_standalone,i.metrics=t.metrics,r=m(i),t.inverted?e.assemble(function(e,t){return function(n){var r=E(t,n);if(!r||c(r)&&r.length===0)return e(n)}}(r,t.variable)):e.assemble(function(e,t,n,r){return function(s){var o=E(t,s,!0),u="",a,h,p,d={$:{index:0,count:1,first:0,last:0}};if(c(o)){s.push(o),s.push(d),s.push(null),a=s.length-1;for(h=0,p=o.length;h<p;++h)s[a]=o[h],d.$.index=h,d.$.count=h+1,d.$.first=h===0,d.$.last=h===p-1,u+=e(s)||"";s.pop(),s.pop(),s.pop()}else l(o)?(s.push(o),u+=e(s)||"",s.pop()):f(o)?u+=o.call(s[s.length-1],n,function(e){return i=y(e,r),i.metrics.partial="HOS@@anon",m(i)(s)}):o&&(u+=e(s)||"");return u}}(r,t.variable,n,e.partials))}function C(e,t,n,r){var i=t.substring(e.openTag.length+(n?1:0),t.length-e.closeTag.length-(r?1:0));String.prototype.trim?i=i.trim():i=i.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(i.indexOf(" ")!==-1)throw new d('Malformed variable name "'+i+'".',e.metrics);return i}function L(e,t){var n=t.substring(e.openTag.length,t.length-e.closeTag.length).match(k);if((n||[]).length!==3)throw new d('Malformed change delimiter token "'+t+'".',e.metrics);var r=y(e.tokens.slice(e.cursor+1).join(""),e.partials,n[1],n[2]);r.code=e.code,r.assemble=e.assemble,r.parser=e.parser,r.metrics.line=e.metrics.line,r.metrics.character=e.metrics.character+t.length,r.metrics.partial=e.metrics.partial,r.section=e.section,r.standalone=e.standalone,r.section&&(r.section.template_buffer+=t),e.terminated=!0,m(r,!0)}function A(t,n,r){if(t.section.lookahead_token||t.section.lookahead_token==="")t.section.template_buffer+=t.section.lookahead_token,t.section.lookahead_token=e;r?t.section.template_buffer+=n:t.section.lookahead_token=n}function O(t,n,r){var i=r==="^",s=C(t,n,!0);t.parser===P?(t.parser=H,t.section={variable:s,template_buffer:"",lookahead_token:e,inverted:i,child_sections:[],metrics:{partial:t.metrics.partial,line:t.metrics.line,character:t.metrics.character+n.length},standalone:t.standalone}):(t.section.child_sections.push(s),A(t,n,!0))}function M(e,t){A(e,t,!0)}function _(e,t){e.section.template_buffer===""&&u(t)&&e.standalone.is_standalone?t="":(e.metrics.character!==1||!a(t))&&(!e.standalone.is_standalone||!u(t)||e.standalone.tags!==1)&&(e.standalone.is_standalone=!1),A(e,t,!1)}function D(t,n){var r=C(t,n,!0);if(t.section.child_sections.length>0){var i=t.section.child_sections[t.section.child_sections.length-1];if(i!==r)throw new d('Unexpected section end tag "'+r+'", expected "'+i+'".',t.metrics);t.section.child_sections.pop(),A(t,n,!0)}else{if(t.section.variable!==r)throw new d('Unexpected section end tag "'+r+'", expected "'+t.section.variable+'".',t.metrics);if(t.section.lookahead_token&&a(t.section.lookahead_token)&&!u(t.section.lookahead_token)&&t.standalone.is_standalone){var s,o,f;for(o=t.cursor+1,s=t.tokens.length;o<s;++o){f=t.tokens[o];if(f===""||f===e)continue;if(u(f))break;if(!a(f)){t.standalone.is_standalone=!1;break}}t.standalone.is_standalone||A(t,"",!0)}else A(t,"",!0);N(t),delete t.section,t.parser=P}}var t=function(){function n(n){var r=this,i,s=n;if(Object.prototype.toString.call(s)!=="[object RegExp]")return String.prototype.split.call(r,s,i);var o=[],u=0,a=(s.ignoreCase?"i":"")+(s.multiline?"m":"")+(s.sticky?"y":""),f,l,c,h;s=new RegExp(s.source,a+"g"),r+="",t||(f=new RegExp("^"+s.source+"$(?!\\s)",a));if(i===e||+i<0)i=Infinity;else{i=Math.floor(+i);if(!i)return[]}while(l=s.exec(r)){c=l.index+l[0].length;if(c>u){o.push(r.slice(u,l.index)),!t&&l.length>1&&l[0].replace(f,function(){for(var t=1;t<arguments.length-2;t++)arguments[t]===e&&(l[t]=e)}),l.length>1&&l.index<r.length&&Array.prototype.push.apply(o,l.slice(1)),h=l[0].length,u=c;if(o.length>=i)break}s.lastIndex===l.index&&s.lastIndex++}return u===r.length?(h||!s.test(""))&&o.push(""):o.push(r.slice(u)),o.length>i?o.slice(0,i):o}var t=/()??/.exec("")[1]===e;return"lol".split(/(o)/).length!==3?n:String.prototype.split}(),r=Object.prototype.toString,i,o=/^\r?\n$/,p=function(){function n(e){return t[e]}var e=/[&<>'"]/g,t={"&":"&","<":"<",">":">",'"':""","'":"'"};return function(t){return t.replace(e,n)}}(),d=function(e,t){var n="";this.prototype=Error.prototype,this.name="MustacheError",t&&(n="("+t.line+","+t.character+"): ",t.partial&&(n="["+t.partial+"]"+n)),this.message=n+e,t&&(this.line=t.line,this.character=t.character,this.partial=t.partial)},g=/(\r?\n)|(\{\{![\s\S]*?!\}\})|(\{\{[#\^\/&>]?\s*[^!\{=]\S*?\s*\}\})|(\{\{\{\s*\S*?\s*\}\}\})|(\{\{=\s*\S*?\s*\S*?\s*=\}\})/,k=new RegExp("=\\s*(\\S*?)\\s*(\\S*?)\\s*="),P={"!":n,"#":O,"^":O,"/":function(e,t){throw new d('Unbalanced End Section tag "'+t+'".',e.metrics)},"&":x,"{":x,">":T,"=":L,def:x,text:S},H={"!":n,"#":O,"^":O,"/":D,"&":M,"{":M,">":M,"=":L,def:M,text:_};return{name:"mustache.js",version:"0.6.2-vcs",compile:function(e,t){var n={},r,i;if(t)for(r in t)t.hasOwnProperty(r)&&(n[r]=t[r]);return i=m(y(e,n)),function(e){return i([e||{}])}},render:function(e,t,n){return Mustache.compile(e,n)(t)},to_html:function(){return Mustache.render.apply(null,arguments)},format:function(e){var t=Array.prototype.slice.call(arguments);return t.shift(),Mustache.compile(e)(t)},Error:d}}()