Skip to content
Browse files

Boost version number.

  • Loading branch information...
1 parent 1ebbb7e commit 82c5fc00f21dacfd103e90955333ee1b59fc9d20 @thegrandpoobah thegrandpoobah committed Nov 13, 2011
Showing with 7 additions and 2 deletions.
  1. +5 −0 CHANGES.md
  2. +1 −1 mustache.js
  3. +1 −1 mustache.min.js
View
5 CHANGES.md
@@ -1,5 +1,10 @@
# mustache.js Changes
+## 0.5.2-vcs
+
+* Fixed a scoping bug (thanks gjslick)
+* Added Mustache.format function (similar to String.format from C#)
+
## 0.5.1-vcs
* Added Dot Notation Support
View
2 mustache.js
@@ -626,7 +626,7 @@ var Mustache = (function(undefined) {
return({
name: "mustache.js",
- version: "0.5.1-vcs",
+ version: "0.5.2-vcs",
/*
Turns a template into a JS function
View
2 mustache.min.js
@@ -1 +1 @@
-var Mustache=function(a){function c(){}function e(a){if(!d){var b=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];d=new RegExp("(\\"+b.join("|\\")+")","g")}return a.replace(d,"\\$1")}function f(a){return a.match(/\r?\n/)}function g(a){return a&&typeof a=="function"}function h(a){return a&&typeof a=="object"}function i(a){return Object.prototype.toString.call(a)==="[object Array]"}function k(b,d){var e,g,h;for(e=b.tokens.length;b.cursor<e&&!b.terminated;++b.cursor){h=b.tokens[b.cursor];if(h===""||h===a)continue;h.indexOf(b.openTag)===0?(g=h.charAt(b.openTag.length),b.parser[g]?b.parser[g](b,h,g):b.parser.def(b,h)):b.parser.text(b,h),f(h)?(b.metrics.character=1,b.metrics.line++):b.metrics.character+=h.length}if(b.parser===x&&!b.terminated)throw new j('Closing section tag "'+b.section.variable+'" expected.',b.metrics);if(!d){var i=b.code;return i.length===0?c:i.length===1?i[0]:function(a,b){for(var c=0,d=i.length;c<d;++c)i[c](a,b)}}}function m(a,c,d,f){d=d||"{{",f=f||"}}";var g;if(d==="{{"&&f==="}}")g=l;else{var h=e(d),i=e(f),j=["(\\r?\\n)","("+h+"![\\s\\S]*?!"+i+")","("+h+"[#^/&>]?\\s*[^!{=]\\S*?\\s*"+i+")","("+h+"{\\s*\\S*?\\s*}"+i+")","("+h+"=\\S*?\\s*\\S*?="+i+")"];g=new RegExp(j.join("|"))}var k=[],m={metrics:{partial:null,line:1,character:1},template:a||"",partials:c||{},openTag:d,closeTag:f,parser:w,pragmas:{},code:k,send_code_func:function(a){k.push(a)}};return o(m),m.tokens=b.call(m.template,g),m.cursor=0,m}function o(b){function c(a,b){return b.indexOf("{{"+a)!==-1}if(!c("%",b.template))return b.template;b.template=b.template.replace(/{{%([\w-]+)(\s*)(.*?(?=}}))}}/g,function(c,d,e,f){var h=a,i,k,l,m;if(f.length>0){i=f.split(","),h={};for(l=0,m=i.length;l<m;++l){k=i[l].split("=");if(k.length!==2)throw new j('Malformed pragma option "'+i[l]+'".');h[k[0]]=k[1]}}if(g(n[d]))n[d](b,h);else throw new j('This implementation of mustache does not implement the "'+d+'" pragma.',a);return""})}function p(a,b){function c(a){return a===!1||a===0||a}var d;return c(b[a])&&(d=b[a]),g(d)?d.apply(b):d}function q(b,c){var d;d=p(b,c[c.length-1]);if(d!==a)return d;if(c.length>1){d=p(b,c[0]);if(d!==a)return d}return a}function r(b,c){var d=b.split("."),e=1,f=d.length,g=q(d[0],c);while(g&&e<f)g=p(d[e],g),e++;return e!==f&&!g&&(g=a),g}function s(a,b){a.send_code_func(function(a,c){c(b)})}function t(b,c,d){function e(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var f,g,h;d==="{"?f=g=h=!0:d==="&"&&(f=g=!0);var i=y(b,c,g,h),j=(b.pragmas["IMPLICIT-ITERATOR"]||{iterator:"."}).iterator;b.send_code_func(function(b,c){return function(d,f){var g;b===j?(g={},g[j]=d[d.length-1],g=p(b,g)):g=r(b,d),g!==a&&(c||(g=e(""+g)),f(""+g))}}(i,f))}function u(a,b){var d=y(a,b,!0),e,f;if(!a.partials[d])throw new j('Unknown partial "'+d+'".',a.metrics);if(!g(a.partials[d])){e=a.partials[d],a.partials[d]=c;var h=m(e,a.partials);h.metrics.partial=d,f=k(h),a.partials[d]=function(a,b){var c=q(d,a);c&&a.push(c),f(a,b),c&&a.pop()}}a.send_code_func(function(b,c){a.partials[d](b,c)})}function v(a){var b=a.section,c=b.template_buffer.join(""),d,e=m(c,a.partials,a.openTag,a.closeTag);e.metrics=b.metrics,e.pragmas=a.pragmas,d=k(e),b.inverted?a.send_code_func(function(a,b){return function(c,d){var e=r(b,c);(!e||i(e)&&e.length===0)&&a(c,d)}}(d,b.variable)):a.send_code_func(function(a,b,c,d){return function(e,f){var j=r(b,e);if(i(j))for(var l=0,n=j.length;l<n;++l)e.push(j[l]),a(e,f),e.pop();else h(j)?(e.push(j),a(e,f),e.pop()):g(j)?f(j.call(e[e.length-1],c,function(a){var b=[],c=function(a){b.push(a)},f=m(a,d);return f.metrics.partial="HOS@@anon",k(f)(e,c),b.join("")})):j&&a(e,f)}}(d,b.variable,c,a.partials))}function y(a,b,c,d){var e=b.substring(a.openTag.length+(c?1:0),b.length-a.closeTag.length-(d?1:0));String.prototype.trim?e=e.trim():e=e.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(e.indexOf(" ")!==-1)throw new j('Malformed variable name "'+e+'".',a.metrics);return e}function z(a,b){var c=b.match(new RegExp(e(a.openTag)+"=(\\S*?)\\s*(\\S*?)="+e(a.closeTag)));if((c||[]).length!==3)throw new j('Malformed change delimiter token "'+b+'".',a.metrics);var d=m(a.tokens.slice(a.cursor+1).join(""),a.partials,c[1],c[2]);d.code=a.code,d.send_code_func=a.send_code_func,d.parser=a.parser,d.metrics.line=a.metrics.line,d.metrics.character=a.metrics.character+b.length,d.metrics.partial=a.metrics.partial,d.section=a.section,d.pragmas=a.pragmas,d.section&&d.section.template_buffer.push(b),a.terminated=!0,k(d,!0)}function A(a,b,c){var d=c==="^",e=y(a,b,!0);a.parser===w?(a.parser=x,a.section={variable:e,template_buffer:[],inverted:d,child_sections:[],metrics:{partial:a.metrics.partial,line:a.metrics.line,character:a.metrics.character+b.length}}):(a.section.child_sections.push(e),a.section.template_buffer.push(b))}function B(a,b){a.section.template_buffer.push(b)}function C(a,b){var c=y(a,b,!0);if(a.section.child_sections.length>0){var d=a.section.child_sections[a.section.child_sections.length-1];if(d===c)a.section.child_sections.pop(),a.section.template_buffer.push(b);else throw new j('Unexpected section end tag "'+c+'", expected "'+d+'".',a.metrics)}else if(a.section.variable===c)v(a),delete a.section,a.parser=w;else throw new j('Unexpected section end tag "'+c+'", expected "'+a.section.variable+'".',a.metrics)}var b=function(){function c(c){var d=this,e=a;if(Object.prototype.toString.call(c)!=="[object RegExp]")return String.prototype.split.call(d,c,e);var f=[],g=0,h=(c.ignoreCase?"i":"")+(c.multiline?"m":"")+(c.sticky?"y":""),c=RegExp(c.source,h+"g"),i,j,k,l;d=d+"",b||(i=RegExp("^"+c.source+"$(?!\\s)",h));if(e===a||+e<0)e=Infinity;else{e=Math.floor(+e);if(!e)return[]}while(j=c.exec(d)){k=j.index+j[0].length;if(k>g){f.push(d.slice(g,j.index)),!b&&j.length>1&&j[0].replace(i,function(){for(var b=1;b<arguments.length-2;b++)arguments[b]===a&&(j[b]=a)}),j.length>1&&j.index<d.length&&Array.prototype.push.apply(f,j.slice(1)),l=j[0].length,g=k;if(f.length>=e)break}c.lastIndex===j.index&&c.lastIndex++}return g===d.length?(l||!c.test(""))&&f.push(""):f.push(d.slice(g)),f.length>e?f.slice(0,e):f}var b=/()??/.exec("")[1]===a;return"lol".split(/(o)/).length!==3?c:String.prototype.split}(),d,j=function(a,b){var c="";this.prototype=Error.prototype,this.name="MustacheError",b&&(c="("+b.line+","+b.character+"): ",b.partial&&(c="["+b.partial+"]"+c)),this.message=c+a,b&&(this.line=b.line,this.character=b.character,this.partial=b.partial)},l=/(\r?\n)|({{![\s\S]*?!}})|({{[#\^\/&>]?\s*[^!{=]\S*?\s*}})|({{{\s*\S*?\s*}}})|({{=\S*?\s*\S*?=}})/,n={"IMPLICIT-ITERATOR":function(b,c){b.pragmas["IMPLICIT-ITERATOR"]={iterator:(c||{iterator:a}).iterator||"."}}},w={"!":c,"#":A,"^":A,"/":function(a,b){throw new j('Unbalanced End Section tag "'+b+'".',a.metrics)},"&":t,"{":t,">":u,"=":z,def:t,text:s},x={"!":c,"#":A,"^":A,"/":C,"&":B,"{":B,">":B,"=":z,def:B,text:B};return{name:"mustache.js",version:"0.5.1-vcs",compile:function(a,b){var c={};if(b)for(var d in b)b.hasOwnProperty(d)&&(c[d]=b[d]);var e=k(m(a,c));return function(a,b){var c=[],d=b||function(a){c.push(a)};e([a||{}],d);if(!b)return c.join("")}},to_html:function(a,b,c,d){var e=Mustache.compile(a,c),f=e(b,d);if(!d)return f},format:function(a){var b=Mustache.compile(a),c=Array.prototype.slice.call(arguments),d={};c.shift();for(var e=0,f=c.length;e<f;++e)d[""+e]=c[e];return b(d)},Error:j}}()
+var Mustache=function(a){function c(){}function e(a){if(!d){var b=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];d=new RegExp("(\\"+b.join("|\\")+")","g")}return a.replace(d,"\\$1")}function f(a){return a.match(/\r?\n/)}function g(a){return a&&typeof a=="function"}function h(a){return a&&typeof a=="object"}function i(a){return Object.prototype.toString.call(a)==="[object Array]"}function k(b,d){var e,g,h;for(e=b.tokens.length;b.cursor<e&&!b.terminated;++b.cursor){h=b.tokens[b.cursor];if(h===""||h===a)continue;h.indexOf(b.openTag)===0?(g=h.charAt(b.openTag.length),b.parser[g]?b.parser[g](b,h,g):b.parser.def(b,h)):b.parser.text(b,h),f(h)?(b.metrics.character=1,b.metrics.line++):b.metrics.character+=h.length}if(b.parser===x&&!b.terminated)throw new j('Closing section tag "'+b.section.variable+'" expected.',b.metrics);if(!d){var i=b.code;return i.length===0?c:i.length===1?i[0]:function(a,b){for(var c=0,d=i.length;c<d;++c)i[c](a,b)}}}function m(a,c,d,f){d=d||"{{",f=f||"}}";var g;if(d==="{{"&&f==="}}")g=l;else{var h=e(d),i=e(f),j=["(\\r?\\n)","("+h+"![\\s\\S]*?!"+i+")","("+h+"[#^/&>]?\\s*[^!{=]\\S*?\\s*"+i+")","("+h+"{\\s*\\S*?\\s*}"+i+")","("+h+"=\\S*?\\s*\\S*?="+i+")"];g=new RegExp(j.join("|"))}var k=[],m={metrics:{partial:null,line:1,character:1},template:a||"",partials:c||{},openTag:d,closeTag:f,parser:w,pragmas:{},code:k,send_code_func:function(a){k.push(a)}};return o(m),m.tokens=b.call(m.template,g),m.cursor=0,m}function o(b){function c(a,b){return b.indexOf("{{"+a)!==-1}if(!c("%",b.template))return b.template;b.template=b.template.replace(/{{%([\w-]+)(\s*)(.*?(?=}}))}}/g,function(c,d,e,f){var h=a,i,k,l,m;if(f.length>0){i=f.split(","),h={};for(l=0,m=i.length;l<m;++l){k=i[l].split("=");if(k.length!==2)throw new j('Malformed pragma option "'+i[l]+'".');h[k[0]]=k[1]}}if(g(n[d]))n[d](b,h);else throw new j('This implementation of mustache does not implement the "'+d+'" pragma.',a);return""})}function p(a,b){function c(a){return a===!1||a===0||a}var d;return c(b[a])&&(d=b[a]),g(d)?d.apply(b):d}function q(b,c){var d;d=p(b,c[c.length-1]);if(d!==a)return d;if(c.length>1){d=p(b,c[0]);if(d!==a)return d}return a}function r(b,c){var d=b.split("."),e=1,f=d.length,g=q(d[0],c);while(g&&e<f)g=p(d[e],g),e++;return e!==f&&!g&&(g=a),g}function s(a,b){a.send_code_func(function(a,c){c(b)})}function t(b,c,d){function e(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var f,g,h;d==="{"?f=g=h=!0:d==="&"&&(f=g=!0);var i=y(b,c,g,h),j=(b.pragmas["IMPLICIT-ITERATOR"]||{iterator:"."}).iterator;b.send_code_func(function(b,c){return function(d,f){var g;b===j?(g={},g[j]=d[d.length-1],g=p(b,g)):g=r(b,d),g!==a&&(c||(g=e(""+g)),f(""+g))}}(i,f))}function u(a,b){var d=y(a,b,!0),e,f;if(!a.partials[d])throw new j('Unknown partial "'+d+'".',a.metrics);if(!g(a.partials[d])){e=a.partials[d],a.partials[d]=c;var h=m(e,a.partials);h.metrics.partial=d,f=k(h),a.partials[d]=function(a,b){var c=q(d,a);c&&a.push(c),f(a,b),c&&a.pop()}}a.send_code_func(function(b,c){a.partials[d](b,c)})}function v(a){var b=a.section,c=b.template_buffer.join(""),d,e=m(c,a.partials,a.openTag,a.closeTag);e.metrics=b.metrics,e.pragmas=a.pragmas,d=k(e),b.inverted?a.send_code_func(function(a,b){return function(c,d){var e=r(b,c);(!e||i(e)&&e.length===0)&&a(c,d)}}(d,b.variable)):a.send_code_func(function(a,b,c,d){return function(e,f){var j=r(b,e);if(i(j))for(var l=0,n=j.length;l<n;++l)e.push(j[l]),a(e,f),e.pop();else h(j)?(e.push(j),a(e,f),e.pop()):g(j)?f(j.call(e[e.length-1],c,function(a){var b=[],c=function(a){b.push(a)},f=m(a,d);return f.metrics.partial="HOS@@anon",k(f)(e,c),b.join("")})):j&&a(e,f)}}(d,b.variable,c,a.partials))}function y(a,b,c,d){var e=b.substring(a.openTag.length+(c?1:0),b.length-a.closeTag.length-(d?1:0));String.prototype.trim?e=e.trim():e=e.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(e.indexOf(" ")!==-1)throw new j('Malformed variable name "'+e+'".',a.metrics);return e}function z(a,b){var c=b.match(new RegExp(e(a.openTag)+"=(\\S*?)\\s*(\\S*?)="+e(a.closeTag)));if((c||[]).length!==3)throw new j('Malformed change delimiter token "'+b+'".',a.metrics);var d=m(a.tokens.slice(a.cursor+1).join(""),a.partials,c[1],c[2]);d.code=a.code,d.send_code_func=a.send_code_func,d.parser=a.parser,d.metrics.line=a.metrics.line,d.metrics.character=a.metrics.character+b.length,d.metrics.partial=a.metrics.partial,d.section=a.section,d.pragmas=a.pragmas,d.section&&d.section.template_buffer.push(b),a.terminated=!0,k(d,!0)}function A(a,b,c){var d=c==="^",e=y(a,b,!0);a.parser===w?(a.parser=x,a.section={variable:e,template_buffer:[],inverted:d,child_sections:[],metrics:{partial:a.metrics.partial,line:a.metrics.line,character:a.metrics.character+b.length}}):(a.section.child_sections.push(e),a.section.template_buffer.push(b))}function B(a,b){a.section.template_buffer.push(b)}function C(a,b){var c=y(a,b,!0);if(a.section.child_sections.length>0){var d=a.section.child_sections[a.section.child_sections.length-1];if(d===c)a.section.child_sections.pop(),a.section.template_buffer.push(b);else throw new j('Unexpected section end tag "'+c+'", expected "'+d+'".',a.metrics)}else if(a.section.variable===c)v(a),delete a.section,a.parser=w;else throw new j('Unexpected section end tag "'+c+'", expected "'+a.section.variable+'".',a.metrics)}var b=function(){function c(c){var d=this,e=a;if(Object.prototype.toString.call(c)!=="[object RegExp]")return String.prototype.split.call(d,c,e);var f=[],g=0,h=(c.ignoreCase?"i":"")+(c.multiline?"m":"")+(c.sticky?"y":""),c=RegExp(c.source,h+"g"),i,j,k,l;d=d+"",b||(i=RegExp("^"+c.source+"$(?!\\s)",h));if(e===a||+e<0)e=Infinity;else{e=Math.floor(+e);if(!e)return[]}while(j=c.exec(d)){k=j.index+j[0].length;if(k>g){f.push(d.slice(g,j.index)),!b&&j.length>1&&j[0].replace(i,function(){for(var b=1;b<arguments.length-2;b++)arguments[b]===a&&(j[b]=a)}),j.length>1&&j.index<d.length&&Array.prototype.push.apply(f,j.slice(1)),l=j[0].length,g=k;if(f.length>=e)break}c.lastIndex===j.index&&c.lastIndex++}return g===d.length?(l||!c.test(""))&&f.push(""):f.push(d.slice(g)),f.length>e?f.slice(0,e):f}var b=/()??/.exec("")[1]===a;return"lol".split(/(o)/).length!==3?c:String.prototype.split}(),d,j=function(a,b){var c="";this.prototype=Error.prototype,this.name="MustacheError",b&&(c="("+b.line+","+b.character+"): ",b.partial&&(c="["+b.partial+"]"+c)),this.message=c+a,b&&(this.line=b.line,this.character=b.character,this.partial=b.partial)},l=/(\r?\n)|({{![\s\S]*?!}})|({{[#\^\/&>]?\s*[^!{=]\S*?\s*}})|({{{\s*\S*?\s*}}})|({{=\S*?\s*\S*?=}})/,n={"IMPLICIT-ITERATOR":function(b,c){b.pragmas["IMPLICIT-ITERATOR"]={iterator:(c||{iterator:a}).iterator||"."}}},w={"!":c,"#":A,"^":A,"/":function(a,b){throw new j('Unbalanced End Section tag "'+b+'".',a.metrics)},"&":t,"{":t,">":u,"=":z,def:t,text:s},x={"!":c,"#":A,"^":A,"/":C,"&":B,"{":B,">":B,"=":z,def:B,text:B};return{name:"mustache.js",version:"0.5.2-vcs",compile:function(a,b){var c={};if(b)for(var d in b)b.hasOwnProperty(d)&&(c[d]=b[d]);var e=k(m(a,c));return function(a,b){var c=[],d=b||function(a){c.push(a)};e([a||{}],d);if(!b)return c.join("")}},to_html:function(a,b,c,d){var e=Mustache.compile(a,c),f=e(b,d);if(!d)return f},format:function(a){var b=Mustache.compile(a),c=Array.prototype.slice.call(arguments),d={};c.shift();for(var e=0,f=c.length;e<f;++e)d[""+e]=c[e];return b(d)},Error:j}}()

0 comments on commit 82c5fc0

Please sign in to comment.
Something went wrong with that request. Please try again.