Comparing version 1.1.0 to 1.1.3
@@ -8,3 +8,3 @@ { | ||
"description": "Mobile-first JavaScript template engine", | ||
"version": "1.1.0", | ||
"version": "1.1.2", | ||
"author": "Vladimir Kharlampidi", | ||
@@ -11,0 +11,0 @@ "homepage": "http://www.idangero.us/template7/", |
# Change Log | ||
## Template7 v1.1.2 - Released on September 1, 2016 | ||
* Added number, boolean, and single-quote-strings argument types support for template helpers #19 | ||
* Ability to use single/double quotes in helpers and mix them | ||
## Template7 v1.1.0 - Released on October 3, 2015 | ||
* Support for access to data (@index, @key) and root context (@root) in partials | ||
* Access to data (@index, @key) and root context (@root) in partials | ||
@@ -31,3 +35,3 @@ ## Template7 v1.0.7 - Released on September 28, 2015 | ||
* New `.unregisterHelper` method to remove registered helpers | ||
## Template7 v1.0.0 - Released on September 12, 2014 |
/** | ||
* Template7 1.1.0 | ||
* Template7 1.1.2 | ||
* Mobile-first JavaScript template engine | ||
@@ -7,3 +7,3 @@ * | ||
* | ||
* Copyright 2015, Vladimir Kharlampidi | ||
* Copyright 2016, Vladimir Kharlampidi | ||
* The iDangero.us | ||
@@ -14,3 +14,3 @@ * http://www.idangero.us/ | ||
* | ||
* Released on: October 3, 2015 | ||
* Released on: November 2, 2016 | ||
*/ | ||
@@ -28,3 +28,12 @@ window.Template7 = (function () { | ||
} | ||
function _escape(string) { | ||
return typeof window !== 'undefined' && window.escape ? window.escape(string) : string | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
} | ||
var cache = {}; | ||
var quoteSingleRexExp = new RegExp('\'', 'g'); | ||
var quoteDoubleRexExp = new RegExp('"', 'g'); | ||
function helperToSlices(string) { | ||
@@ -36,7 +45,10 @@ var helperParts = string.replace(/[{}#}]/g, '').split(' '); | ||
var part = helperParts[i]; | ||
var blockQuoteRegExp, openingQuote; | ||
if (i === 0) slices.push(part); | ||
else { | ||
if (part.indexOf('"') === 0) { | ||
if (part.indexOf('"') === 0 || part.indexOf('\'') === 0) { | ||
blockQuoteRegExp = part.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp; | ||
openingQuote = part.indexOf('"') === 0 ? '"' : '\''; | ||
// Plain String | ||
if (part.match(/"/g).length === 2) { | ||
if (part.match(blockQuoteRegExp).length === 2) { | ||
// One word string | ||
@@ -50,3 +62,3 @@ slices.push(part); | ||
part += ' ' + helperParts[j]; | ||
if (helperParts[j].indexOf('"') >= 0) { | ||
if (helperParts[j].indexOf(openingQuote) >= 0) { | ||
shiftIndex = j; | ||
@@ -66,7 +78,7 @@ slices.push(part); | ||
var hashContent = hashParts[1]; | ||
if (hashContent.match(/"/g).length !== 2) { | ||
if (hashContent.match(blockQuoteRegExp).length !== 2) { | ||
shiftIndex = 0; | ||
for (j = i + 1; j < helperParts.length; j++) { | ||
hashContent += ' ' + helperParts[j]; | ||
if (helperParts[j].indexOf('"') >= 0) { | ||
if (helperParts[j].indexOf(openingQuote) >= 0) { | ||
shiftIndex = j; | ||
@@ -78,3 +90,3 @@ break; | ||
} | ||
var hash = [hashName, hashContent.replace(/"/g,'')]; | ||
var hash = [hashName, hashContent.replace(blockQuoteRegExp,'')]; | ||
slices.push(hash); | ||
@@ -132,3 +144,3 @@ } | ||
} | ||
if (block.indexOf('{#') >= 0) { | ||
@@ -203,6 +215,6 @@ // Condition/Helper | ||
} | ||
var Template7 = function (template) { | ||
var Template7 = function (template, options) { | ||
var t = this; | ||
t.template = template; | ||
function getCompileFn(block, depth) { | ||
@@ -251,7 +263,7 @@ if (block.content) return compile(block.content, depth); | ||
else { | ||
if (part.indexOf('this') === 0) { | ||
if (part === 'this' || part.indexOf('this.') >= 0 || part.indexOf('this[') >= 0 || part.indexOf('this(') >= 0) { | ||
variable = part.replace('this', ctx); | ||
} | ||
else { | ||
variable += '.' + part; | ||
variable += '.' + part; | ||
} | ||
@@ -267,3 +279,4 @@ } | ||
for (var i = 0; i < contextArray.length; i++) { | ||
if (contextArray[i].indexOf('"') === 0) arr.push(contextArray[i]); | ||
if (/^['"]/.test(contextArray[i])) arr.push(contextArray[i]); | ||
else if (/^(true|false|\d+)$/.test(contextArray[i])) arr.push(contextArray[i]); | ||
else { | ||
@@ -319,5 +332,5 @@ arr.push(getCompileVar(contextArray[i], ctx)); | ||
compiledArguments = getCompiledArguments(block.contextName, ctx); | ||
resultString += 'r += (Template7.helpers.' + block.helperName + ').call(' + ctx + ', ' + (compiledArguments && (compiledArguments + ', ')) +'{hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth + 1) + ', inverse: ' + getCompileInverse(block, depth + 1) + ', root: root});'; | ||
} | ||
@@ -358,3 +371,3 @@ else { | ||
if (!p.compiled) { | ||
p.compiled = t7.compile(p.template); | ||
p.compiled = new Template7(p.template).compile(); | ||
} | ||
@@ -371,7 +384,3 @@ var ctx = this; | ||
} | ||
return context | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
return _escape(context); | ||
}, | ||
@@ -450,3 +459,3 @@ 'if': function (context, options) { | ||
else { | ||
return options.inverse(this, options.data); | ||
return options.inverse(this, options.data); | ||
} | ||
@@ -469,3 +478,3 @@ } | ||
t7.unregisterHelper = function (name) { | ||
Template7.prototype.helpers[name] = undefined; | ||
Template7.prototype.helpers[name] = undefined; | ||
delete Template7.prototype.helpers[name]; | ||
@@ -482,3 +491,2 @@ }; | ||
}; | ||
t7.compile = function (template, options) { | ||
@@ -488,3 +496,3 @@ var instance = new Template7(template, options); | ||
}; | ||
t7.options = Template7.prototype.options; | ||
@@ -491,0 +499,0 @@ t7.helpers = Template7.prototype.helpers; |
/** | ||
* Template7 1.1.0 | ||
* Template7 1.1.2 | ||
* Mobile-first JavaScript template engine | ||
@@ -7,3 +7,3 @@ * | ||
* | ||
* Copyright 2015, Vladimir Kharlampidi | ||
* Copyright 2016, Vladimir Kharlampidi | ||
* The iDangero.us | ||
@@ -14,5 +14,5 @@ * http://www.idangero.us/ | ||
* | ||
* Released on: October 3, 2015 | ||
* Released on: November 2, 2016 | ||
*/ | ||
window.Template7=function(){"use strict";function e(e){return"[object Array]"===Object.prototype.toString.apply(e)}function t(e){return"function"==typeof e}function r(e){var t,r,n,i=e.replace(/[{}#}]/g,"").split(" "),a=[];for(r=0;r<i.length;r++){var l=i[r];if(0===r)a.push(l);else if(0===l.indexOf('"'))if(2===l.match(/"/g).length)a.push(l);else{for(t=0,n=r+1;n<i.length;n++)if(l+=" "+i[n],i[n].indexOf('"')>=0){t=n,a.push(l);break}t&&(r=t)}else if(l.indexOf("=")>0){var o=l.split("="),p=o[0],s=o[1];if(2!==s.match(/"/g).length){for(t=0,n=r+1;n<i.length;n++)if(s+=" "+i[n],i[n].indexOf('"')>=0){t=n;break}t&&(r=t)}var f=[p,s.replace(/"/g,"")];a.push(f)}else a.push(l)}return a}function n(t){var n,i,a=[];if(!t)return[];var l=t.split(/({{[^{^}]*}})/);for(n=0;n<l.length;n++){var o=l[n];if(""!==o)if(o.indexOf("{{")<0)a.push({type:"plain",content:o});else{if(o.indexOf("{/")>=0)continue;if(o.indexOf("{#")<0&&o.indexOf(" ")<0&&o.indexOf("else")<0){a.push({type:"variable",contextName:o.replace(/[{}]/g,"")});continue}var p=r(o),s=p[0],f=">"===s,c=[],u={};for(i=1;i<p.length;i++){var h=p[i];e(h)?u[h[0]]="false"===h[1]?!1:h[1]:c.push(h)}if(o.indexOf("{#")>=0){var d,v="",g="",m=0,x=!1,y=!1,O=0;for(i=n+1;i<l.length;i++)if(l[i].indexOf("{{#")>=0&&O++,l[i].indexOf("{{/")>=0&&O--,l[i].indexOf("{{#"+s)>=0)v+=l[i],y&&(g+=l[i]),m++;else if(l[i].indexOf("{{/"+s)>=0){if(!(m>0)){d=i,x=!0;break}m--,v+=l[i],y&&(g+=l[i])}else l[i].indexOf("else")>=0&&0===O?y=!0:(y||(v+=l[i]),y&&(g+=l[i]));x&&(d&&(n=d),a.push({type:"helper",helperName:s,contextName:c,content:v,inverseContent:g,hash:u}))}else o.indexOf(" ")>0&&(f&&(s="_partial",c[0]&&(c[0]='"'+c[0].replace(/"|'/g,"")+'"')),a.push({type:"helper",helperName:s,contextName:c,hash:u}))}}return a}var i=function(e){function t(e,t){return e.content?l(e.content,t):function(){return""}}function r(e,t){return e.inverseContent?l(e.inverseContent,t):function(){return""}}function i(e,t){var r,n,i=0;if(0===e.indexOf("../")){i=e.split("../").length-1;var a=t.split("_")[1]-i;t="ctx_"+(a>=1?a:1),n=e.split("../")[i].split(".")}else 0===e.indexOf("@global")?(t="Template7.global",n=e.split("@global.")[1].split(".")):0===e.indexOf("@root")?(t="root",n=e.split("@root.")[1].split(".")):n=e.split(".");r=t;for(var l=0;l<n.length;l++){var o=n[l];0===o.indexOf("@")?l>0?r+="[(data && data."+o.replace("@","")+")]":r="(data && data."+e.replace("@","")+")":isFinite(o)?r+="["+o+"]":0===o.indexOf("this")?r=o.replace("this",t):r+="."+o}return r}function a(e,t){for(var r=[],n=0;n<e.length;n++)0===e[n].indexOf('"')?r.push(e[n]):r.push(i(e[n],t));return r.join(", ")}function l(e,l){if(l=l||1,e=e||o.template,"string"!=typeof e)throw new Error("Template7: Template must be a string");var p=n(e);if(0===p.length)return function(){return""};var s="ctx_"+l,f="";f+=1===l?"(function ("+s+", data, root) {\n":"(function ("+s+", data) {\n",1===l&&(f+="function isArray(arr){return Object.prototype.toString.apply(arr) === '[object Array]';}\n",f+="function isFunction(func){return (typeof func === 'function');}\n",f+='function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n',f+="root = root || ctx_1 || {};\n"),f+="var r = '';\n";var c;for(c=0;c<p.length;c++){var u=p[c];if("plain"!==u.type){var h,d;if("variable"===u.type&&(h=i(u.contextName,s),f+="r += c("+h+", "+s+");"),"helper"===u.type)if(u.helperName in o.helpers)d=a(u.contextName,s),f+="r += (Template7.helpers."+u.helperName+").call("+s+", "+(d&&d+", ")+"{hash:"+JSON.stringify(u.hash)+", data: data || {}, fn: "+t(u,l+1)+", inverse: "+r(u,l+1)+", root: root});";else{if(u.contextName.length>0)throw new Error('Template7: Missing helper: "'+u.helperName+'"');h=i(u.helperName,s),f+="if ("+h+") {",f+="if (isArray("+h+")) {",f+="r += (Template7.helpers.each).call("+s+", "+h+", {hash:"+JSON.stringify(u.hash)+", data: data || {}, fn: "+t(u,l+1)+", inverse: "+r(u,l+1)+", root: root});",f+="}else {",f+="r += (Template7.helpers.with).call("+s+", "+h+", {hash:"+JSON.stringify(u.hash)+", data: data || {}, fn: "+t(u,l+1)+", inverse: "+r(u,l+1)+", root: root});",f+="}}"}}else f+="r +='"+u.content.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/'/g,"\\'")+"';"}return f+="\nreturn r;})",eval.call(window,f)}var o=this;o.template=e,o.compile=function(e){return o.compiled||(o.compiled=l(e)),o.compiled}};i.prototype={options:{},partials:{},helpers:{_partial:function(e,t){var r=i.prototype.partials[e];if(!r||r&&!r.template)return"";r.compiled||(r.compiled=a.compile(r.template));var n=this;for(var l in t.hash)n[l]=t.hash[l];return r.compiled(n,t.data,t.root)},escape:function(e,t){if("string"!=typeof e)throw new Error('Template7: Passed context to "escape" helper should be a string');return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},"if":function(e,r){return t(e)&&(e=e.call(this)),e?r.fn(this,r.data):r.inverse(this,r.data)},unless:function(e,r){return t(e)&&(e=e.call(this)),e?r.inverse(this,r.data):r.fn(this,r.data)},each:function(r,n){var i="",a=0;if(t(r)&&(r=r.call(this)),e(r)){for(n.hash.reverse&&(r=r.reverse()),a=0;a<r.length;a++)i+=n.fn(r[a],{first:0===a,last:a===r.length-1,index:a});n.hash.reverse&&(r=r.reverse())}else for(var l in r)a++,i+=n.fn(r[l],{key:l});return a>0?i:n.inverse(this)},"with":function(e,r){return t(e)&&(e=e.call(this)),r.fn(e)},join:function(e,r){return t(e)&&(e=e.call(this)),e.join(r.hash.delimiter||r.hash.delimeter)},js:function(e,t){var r;return r=e.indexOf("return")>=0?"(function(){"+e+"})":"(function(){return ("+e+")})",eval.call(this,r).call(this)},js_compare:function(e,t){var r;r=e.indexOf("return")>=0?"(function(){"+e+"})":"(function(){return ("+e+")})";var n=eval.call(this,r).call(this);return n?t.fn(this,t.data):t.inverse(this,t.data)}}};var a=function(e,t){if(2===arguments.length){var r=new i(e),n=r.compile()(t);return r=null,n}return new i(e)};return a.registerHelper=function(e,t){i.prototype.helpers[e]=t},a.unregisterHelper=function(e){i.prototype.helpers[e]=void 0,delete i.prototype.helpers[e]},a.registerPartial=function(e,t){i.prototype.partials[e]={template:t}},a.unregisterPartial=function(e,t){i.prototype.partials[e]&&(i.prototype.partials[e]=void 0,delete i.prototype.partials[e])},a.compile=function(e,t){var r=new i(e,t);return r.compile()},a.options=i.prototype.options,a.helpers=i.prototype.helpers,a.partials=i.prototype.partials,a}(); | ||
window.Template7=function(){"use strict";function e(e){return"[object Array]"===Object.prototype.toString.apply(e)}function t(e){return"function"==typeof e}function r(e){return"undefined"!=typeof window&&window.escape?window.escape(e):e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function n(e){var t,r,n,i=e.replace(/[{}#}]/g,"").split(" "),o=[];for(r=0;r<i.length;r++){var p,s,f=i[r];if(0===r)o.push(f);else if(0===f.indexOf('"')||0===f.indexOf("'"))if(p=0===f.indexOf('"')?l:a,s=0===f.indexOf('"')?'"':"'",2===f.match(p).length)o.push(f);else{for(t=0,n=r+1;n<i.length;n++)if(f+=" "+i[n],i[n].indexOf(s)>=0){t=n,o.push(f);break}t&&(r=t)}else if(f.indexOf("=")>0){var c=f.split("="),u=c[0],h=c[1];if(2!==h.match(p).length){for(t=0,n=r+1;n<i.length;n++)if(h+=" "+i[n],i[n].indexOf(s)>=0){t=n;break}t&&(r=t)}var d=[u,h.replace(p,"")];o.push(d)}else o.push(f)}return o}function i(t){var r,i,a=[];if(!t)return[];var l=t.split(/({{[^{^}]*}})/);for(r=0;r<l.length;r++){var o=l[r];if(""!==o)if(o.indexOf("{{")<0)a.push({type:"plain",content:o});else{if(o.indexOf("{/")>=0)continue;if(o.indexOf("{#")<0&&o.indexOf(" ")<0&&o.indexOf("else")<0){a.push({type:"variable",contextName:o.replace(/[{}]/g,"")});continue}var p=n(o),s=p[0],f=">"===s,c=[],u={};for(i=1;i<p.length;i++){var h=p[i];e(h)?u[h[0]]="false"!==h[1]&&h[1]:c.push(h)}if(o.indexOf("{#")>=0){var d,v="",g="",m=0,x=!1,y=!1,O=0;for(i=r+1;i<l.length;i++)if(l[i].indexOf("{{#")>=0&&O++,l[i].indexOf("{{/")>=0&&O--,l[i].indexOf("{{#"+s)>=0)v+=l[i],y&&(g+=l[i]),m++;else if(l[i].indexOf("{{/"+s)>=0){if(!(m>0)){d=i,x=!0;break}m--,v+=l[i],y&&(g+=l[i])}else l[i].indexOf("else")>=0&&0===O?y=!0:(y||(v+=l[i]),y&&(g+=l[i]));x&&(d&&(r=d),a.push({type:"helper",helperName:s,contextName:c,content:v,inverseContent:g,hash:u}))}else o.indexOf(" ")>0&&(f&&(s="_partial",c[0]&&(c[0]='"'+c[0].replace(/"|'/g,"")+'"')),a.push({type:"helper",helperName:s,contextName:c,hash:u}))}}return a}var a=new RegExp("'","g"),l=new RegExp('"',"g"),o=function(e,t){function r(e,t){return e.content?o(e.content,t):function(){return""}}function n(e,t){return e.inverseContent?o(e.inverseContent,t):function(){return""}}function a(e,t){var r,n,i=0;if(0===e.indexOf("../")){i=e.split("../").length-1;var a=t.split("_")[1]-i;t="ctx_"+(a>=1?a:1),n=e.split("../")[i].split(".")}else 0===e.indexOf("@global")?(t="Template7.global",n=e.split("@global.")[1].split(".")):0===e.indexOf("@root")?(t="root",n=e.split("@root.")[1].split(".")):n=e.split(".");r=t;for(var l=0;l<n.length;l++){var o=n[l];0===o.indexOf("@")?l>0?r+="[(data && data."+o.replace("@","")+")]":r="(data && data."+e.replace("@","")+")":isFinite(o)?r+="["+o+"]":"this"===o||o.indexOf("this.")>=0||o.indexOf("this[")>=0||o.indexOf("this(")>=0?r=o.replace("this",t):r+="."+o}return r}function l(e,t){for(var r=[],n=0;n<e.length;n++)/^['"]/.test(e[n])?r.push(e[n]):/^(true|false|\d+)$/.test(e[n])?r.push(e[n]):r.push(a(e[n],t));return r.join(", ")}function o(e,t){if(t=t||1,e=e||p.template,"string"!=typeof e)throw new Error("Template7: Template must be a string");var o=i(e);if(0===o.length)return function(){return""};var s="ctx_"+t,f="";f+=1===t?"(function ("+s+", data, root) {\n":"(function ("+s+", data) {\n",1===t&&(f+="function isArray(arr){return Object.prototype.toString.apply(arr) === '[object Array]';}\n",f+="function isFunction(func){return (typeof func === 'function');}\n",f+='function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n',f+="root = root || ctx_1 || {};\n"),f+="var r = '';\n";var c;for(c=0;c<o.length;c++){var u=o[c];if("plain"!==u.type){var h,d;if("variable"===u.type&&(h=a(u.contextName,s),f+="r += c("+h+", "+s+");"),"helper"===u.type)if(u.helperName in p.helpers)d=l(u.contextName,s),f+="r += (Template7.helpers."+u.helperName+").call("+s+", "+(d&&d+", ")+"{hash:"+JSON.stringify(u.hash)+", data: data || {}, fn: "+r(u,t+1)+", inverse: "+n(u,t+1)+", root: root});";else{if(u.contextName.length>0)throw new Error('Template7: Missing helper: "'+u.helperName+'"');h=a(u.helperName,s),f+="if ("+h+") {",f+="if (isArray("+h+")) {",f+="r += (Template7.helpers.each).call("+s+", "+h+", {hash:"+JSON.stringify(u.hash)+", data: data || {}, fn: "+r(u,t+1)+", inverse: "+n(u,t+1)+", root: root});",f+="}else {",f+="r += (Template7.helpers.with).call("+s+", "+h+", {hash:"+JSON.stringify(u.hash)+", data: data || {}, fn: "+r(u,t+1)+", inverse: "+n(u,t+1)+", root: root});",f+="}}"}}else f+="r +='"+u.content.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/'/g,"\\'")+"';"}return f+="\nreturn r;})",eval.call(window,f)}var p=this;p.template=e,p.compile=function(e){return p.compiled||(p.compiled=o(e)),p.compiled}};o.prototype={options:{},partials:{},helpers:{_partial:function(e,t){var r=o.prototype.partials[e];if(!r||r&&!r.template)return"";r.compiled||(r.compiled=new o(r.template).compile());var n=this;for(var i in t.hash)n[i]=t.hash[i];return r.compiled(n,t.data,t.root)},escape:function(e,t){if("string"!=typeof e)throw new Error('Template7: Passed context to "escape" helper should be a string');return r(e)},if:function(e,r){return t(e)&&(e=e.call(this)),e?r.fn(this,r.data):r.inverse(this,r.data)},unless:function(e,r){return t(e)&&(e=e.call(this)),e?r.inverse(this,r.data):r.fn(this,r.data)},each:function(r,n){var i="",a=0;if(t(r)&&(r=r.call(this)),e(r)){for(n.hash.reverse&&(r=r.reverse()),a=0;a<r.length;a++)i+=n.fn(r[a],{first:0===a,last:a===r.length-1,index:a});n.hash.reverse&&(r=r.reverse())}else for(var l in r)a++,i+=n.fn(r[l],{key:l});return a>0?i:n.inverse(this)},with:function(e,r){return t(e)&&(e=e.call(this)),r.fn(e)},join:function(e,r){return t(e)&&(e=e.call(this)),e.join(r.hash.delimiter||r.hash.delimeter)},js:function(e,t){var r;return r=e.indexOf("return")>=0?"(function(){"+e+"})":"(function(){return ("+e+")})",eval.call(this,r).call(this)},js_compare:function(e,t){var r;r=e.indexOf("return")>=0?"(function(){"+e+"})":"(function(){return ("+e+")})";var n=eval.call(this,r).call(this);return n?t.fn(this,t.data):t.inverse(this,t.data)}}};var p=function(e,t){if(2===arguments.length){var r=new o(e),n=r.compile()(t);return r=null,n}return new o(e)};return p.registerHelper=function(e,t){o.prototype.helpers[e]=t},p.unregisterHelper=function(e){o.prototype.helpers[e]=void 0,delete o.prototype.helpers[e]},p.registerPartial=function(e,t){o.prototype.partials[e]={template:t}},p.unregisterPartial=function(e,t){o.prototype.partials[e]&&(o.prototype.partials[e]=void 0,delete o.prototype.partials[e])},p.compile=function(e,t){var r=new o(e,t);return r.compile()},p.options=o.prototype.options,p.helpers=o.prototype.helpers,p.partials=o.prototype.partials,p}(); | ||
//# sourceMappingURL=template7.min.js.map |
{ | ||
"name": "template7", | ||
"version": "1.1.0", | ||
"version": "1.1.3", | ||
"description": "Mobile-first HTML template engine", | ||
@@ -36,12 +36,12 @@ "main": "dist/", | ||
"devDependencies": { | ||
"jshint": "~2.8.0", | ||
"jshint": "~2.9.3", | ||
"gulp": "~3.9.0", | ||
"gulp-connect": "~2.2.0", | ||
"gulp-connect": "~5.0.0", | ||
"gulp-open": "~1.0.0", | ||
"gulp-uglify": "~1.4.1", | ||
"gulp-uglify": "~2.0.0", | ||
"gulp-sourcemaps": "~1.6.0", | ||
"gulp-jshint": "~1.11.2", | ||
"gulp-jshint": "~2.0.1", | ||
"gulp-rename": "~1.2.2", | ||
"gulp-header": "~1.7.1", | ||
"jshint-stylish": "~2.0.1" | ||
"gulp-header": "~1.8.8", | ||
"jshint-stylish": "~2.2.1" | ||
}, | ||
@@ -48,0 +48,0 @@ "scripts": { |
[![devDependency Status](https://david-dm.org/nolimits4web/template7/dev-status.svg)](https://david-dm.org/nolimits4web/template7#info=devDependencies) | ||
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=nolimits4web&url=https://github.com/nolimits4web/framework7/&title=Framework7&language=JavaScript&tags=github&category=software) | ||
@@ -4,0 +3,0 @@ Template7 |
@@ -12,3 +12,12 @@ window.Template7 = (function () { | ||
} | ||
function _escape(string) { | ||
return typeof window !== 'undefined' && window.escape ? window.escape(string) : string | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
} | ||
var cache = {}; | ||
var quoteSingleRexExp = new RegExp('\'', 'g'); | ||
var quoteDoubleRexExp = new RegExp('"', 'g'); | ||
function helperToSlices(string) { | ||
@@ -20,7 +29,10 @@ var helperParts = string.replace(/[{}#}]/g, '').split(' '); | ||
var part = helperParts[i]; | ||
var blockQuoteRegExp, openingQuote; | ||
if (i === 0) slices.push(part); | ||
else { | ||
if (part.indexOf('"') === 0) { | ||
if (part.indexOf('"') === 0 || part.indexOf('\'') === 0) { | ||
blockQuoteRegExp = part.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp; | ||
openingQuote = part.indexOf('"') === 0 ? '"' : '\''; | ||
// Plain String | ||
if (part.match(/"/g).length === 2) { | ||
if (part.match(blockQuoteRegExp).length === 2) { | ||
// One word string | ||
@@ -34,3 +46,3 @@ slices.push(part); | ||
part += ' ' + helperParts[j]; | ||
if (helperParts[j].indexOf('"') >= 0) { | ||
if (helperParts[j].indexOf(openingQuote) >= 0) { | ||
shiftIndex = j; | ||
@@ -50,7 +62,7 @@ slices.push(part); | ||
var hashContent = hashParts[1]; | ||
if (hashContent.match(/"/g).length !== 2) { | ||
if (hashContent.match(blockQuoteRegExp).length !== 2) { | ||
shiftIndex = 0; | ||
for (j = i + 1; j < helperParts.length; j++) { | ||
hashContent += ' ' + helperParts[j]; | ||
if (helperParts[j].indexOf('"') >= 0) { | ||
if (helperParts[j].indexOf(openingQuote) >= 0) { | ||
shiftIndex = j; | ||
@@ -62,3 +74,3 @@ break; | ||
} | ||
var hash = [hashName, hashContent.replace(/"/g,'')]; | ||
var hash = [hashName, hashContent.replace(blockQuoteRegExp,'')]; | ||
slices.push(hash); | ||
@@ -116,3 +128,3 @@ } | ||
} | ||
if (block.indexOf('{#') >= 0) { | ||
@@ -187,6 +199,6 @@ // Condition/Helper | ||
} | ||
var Template7 = function (template) { | ||
var Template7 = function (template, options) { | ||
var t = this; | ||
t.template = template; | ||
function getCompileFn(block, depth) { | ||
@@ -235,7 +247,7 @@ if (block.content) return compile(block.content, depth); | ||
else { | ||
if (part.indexOf('this') === 0) { | ||
if (part === 'this' || part.indexOf('this.') >= 0 || part.indexOf('this[') >= 0 || part.indexOf('this(') >= 0) { | ||
variable = part.replace('this', ctx); | ||
} | ||
else { | ||
variable += '.' + part; | ||
variable += '.' + part; | ||
} | ||
@@ -251,3 +263,4 @@ } | ||
for (var i = 0; i < contextArray.length; i++) { | ||
if (contextArray[i].indexOf('"') === 0) arr.push(contextArray[i]); | ||
if (/^['"]/.test(contextArray[i])) arr.push(contextArray[i]); | ||
else if (/^(true|false|\d+)$/.test(contextArray[i])) arr.push(contextArray[i]); | ||
else { | ||
@@ -303,5 +316,5 @@ arr.push(getCompileVar(contextArray[i], ctx)); | ||
compiledArguments = getCompiledArguments(block.contextName, ctx); | ||
resultString += 'r += (Template7.helpers.' + block.helperName + ').call(' + ctx + ', ' + (compiledArguments && (compiledArguments + ', ')) +'{hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth + 1) + ', inverse: ' + getCompileInverse(block, depth + 1) + ', root: root});'; | ||
} | ||
@@ -342,3 +355,3 @@ else { | ||
if (!p.compiled) { | ||
p.compiled = t7.compile(p.template); | ||
p.compiled = new Template7(p.template).compile(); | ||
} | ||
@@ -355,7 +368,3 @@ var ctx = this; | ||
} | ||
return context | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
return _escape(context); | ||
}, | ||
@@ -434,3 +443,3 @@ 'if': function (context, options) { | ||
else { | ||
return options.inverse(this, options.data); | ||
return options.inverse(this, options.data); | ||
} | ||
@@ -453,3 +462,3 @@ } | ||
t7.unregisterHelper = function (name) { | ||
Template7.prototype.helpers[name] = undefined; | ||
Template7.prototype.helpers[name] = undefined; | ||
delete Template7.prototype.helpers[name]; | ||
@@ -466,3 +475,2 @@ }; | ||
}; | ||
t7.compile = function (template, options) { | ||
@@ -472,3 +480,3 @@ var instance = new Template7(template, options); | ||
}; | ||
t7.options = Template7.prototype.options; | ||
@@ -475,0 +483,0 @@ t7.helpers = Template7.prototype.helpers; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
236801
1109
15