Comparing version 1.4.0 to 1.4.1
# Change Log | ||
## Template7 v1.4.1 - Released on February 5, 2019 | ||
* Relaxed `escape` helper to escape only `<>&"'` characters | ||
* Improved variables parsing in `js` and `js_if` helpers | ||
## Template7 v1.4.0 - Released on August 31, 2018 | ||
@@ -4,0 +8,0 @@ * Added TypeScript definitions |
/** | ||
* Template7 1.4.0 | ||
* Template7 1.4.1 | ||
* Mobile-first HTML template engine | ||
@@ -7,3 +7,3 @@ * | ||
* | ||
* Copyright 2018, Vladimir Kharlampidi | ||
* Copyright 2019, Vladimir Kharlampidi | ||
* The iDangero.us | ||
@@ -14,4 +14,5 @@ * http://www.idangero.us/ | ||
* | ||
* Released on: August 31, 2018 | ||
* Released on: February 5, 2019 | ||
*/ | ||
let t7ctx; | ||
@@ -34,10 +35,9 @@ if (typeof window !== 'undefined') { | ||
}, | ||
escape(string) { | ||
return (typeof Template7Context !== 'undefined' && Template7Context.escape) ? | ||
Template7Context.escape(string) : | ||
string | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
escape(string = '') { | ||
return string | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
}, | ||
@@ -225,5 +225,15 @@ helperToSlices(string) { | ||
parseJsVariable(expression, replace, object) { | ||
return expression.split(/([+ \-*/^])/g).map((part) => { | ||
if (part.indexOf(replace) < 0) return part; | ||
if (!object) return JSON.stringify(''); | ||
return expression.split(/([+ \-*/^()&=|<>!%:?])/g).reduce((arr, part) => { | ||
if (!part) { | ||
return arr; | ||
} | ||
if (part.indexOf(replace) < 0) { | ||
arr.push(part); | ||
return arr; | ||
} | ||
if (!object) { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
let variable = object; | ||
@@ -240,9 +250,23 @@ if (part.indexOf(`${replace}.`) >= 0) { | ||
if (variable === undefined) variable = 'undefined'; | ||
return variable; | ||
}).join(''); | ||
arr.push(variable); | ||
return arr; | ||
}, []).join(''); | ||
}, | ||
parseJsParents(expression, parents) { | ||
return expression.split(/([+ \-*^])/g).map((part) => { | ||
if (part.indexOf('../') < 0) return part; | ||
if (!parents || parents.length === 0) return JSON.stringify(''); | ||
return expression.split(/([+ \-*^()&=|<>!%:?])/g).reduce((arr, part) => { | ||
if (!part) { | ||
return arr; | ||
} | ||
if (part.indexOf('../') < 0) { | ||
arr.push(part); | ||
return arr; | ||
} | ||
if (!parents || parents.length === 0) { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
const levelsUp = part.split('../').length - 1; | ||
@@ -254,7 +278,16 @@ const parentData = levelsUp > parents.length ? parents[parents.length - 1] : parents[levelsUp - 1]; | ||
parentPart.split('.').forEach((partName) => { | ||
if (variable[partName]) variable = variable[partName]; | ||
if (typeof variable[partName] !== 'undefined') variable = variable[partName]; | ||
else variable = 'undefined'; | ||
}); | ||
return JSON.stringify(variable); | ||
}).join(''); | ||
if (variable === false || variable === true) { | ||
arr.push(JSON.stringify(variable)); | ||
return arr; | ||
} | ||
if (variable === null || variable === 'undefined') { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
arr.push(JSON.stringify(variable)); | ||
return arr; | ||
}, []).join(''); | ||
}, | ||
@@ -317,2 +350,3 @@ getCompileVar(name, ctx, data = 'data_1') { | ||
/* eslint no-eval: "off" */ | ||
const Template7Helpers = { | ||
@@ -319,0 +353,0 @@ _partial(partialName, options) { |
/** | ||
* Template7 1.4.0 | ||
* Template7 1.4.1 | ||
* Mobile-first HTML template engine | ||
@@ -7,3 +7,3 @@ * | ||
* | ||
* Copyright 2018, Vladimir Kharlampidi | ||
* Copyright 2019, Vladimir Kharlampidi | ||
* The iDangero.us | ||
@@ -14,613 +14,648 @@ * http://www.idangero.us/ | ||
* | ||
* Released on: August 31, 2018 | ||
* Released on: February 5, 2019 | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.Template7 = factory()); | ||
}(this, (function () { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.Template7 = factory()); | ||
}(this, function () { 'use strict'; | ||
var t7ctx; | ||
if (typeof window !== 'undefined') { | ||
t7ctx = window; | ||
} else if (typeof global !== 'undefined') { | ||
t7ctx = global; | ||
} else { | ||
t7ctx = undefined; | ||
} | ||
var t7ctx; | ||
if (typeof window !== 'undefined') { | ||
t7ctx = window; | ||
} else if (typeof global !== 'undefined') { | ||
t7ctx = global; | ||
} else { | ||
t7ctx = undefined; | ||
} | ||
var Template7Context = t7ctx; | ||
var Template7Context = t7ctx; | ||
var Template7Utils = { | ||
quoteSingleRexExp: new RegExp('\'', 'g'), | ||
quoteDoubleRexExp: new RegExp('"', 'g'), | ||
isFunction: function isFunction(func) { | ||
return typeof func === 'function'; | ||
}, | ||
escape: function escape(string) { | ||
return (typeof Template7Context !== 'undefined' && Template7Context.escape) ? | ||
Template7Context.escape(string) : | ||
string | ||
var Template7Utils = { | ||
quoteSingleRexExp: new RegExp('\'', 'g'), | ||
quoteDoubleRexExp: new RegExp('"', 'g'), | ||
isFunction: function isFunction(func) { | ||
return typeof func === 'function'; | ||
}, | ||
escape: function escape(string) { | ||
if ( string === void 0 ) string = ''; | ||
return string | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
}, | ||
helperToSlices: function helperToSlices(string) { | ||
var quoteDoubleRexExp = Template7Utils.quoteDoubleRexExp; | ||
var quoteSingleRexExp = Template7Utils.quoteSingleRexExp; | ||
var helperParts = string.replace(/[{}#}]/g, '').trim().split(' '); | ||
var slices = []; | ||
var shiftIndex; | ||
var i; | ||
var j; | ||
for (i = 0; i < helperParts.length; i += 1) { | ||
var part = helperParts[i]; | ||
var blockQuoteRegExp = (void 0); | ||
var openingQuote = (void 0); | ||
if (i === 0) { slices.push(part); } | ||
else if (part.indexOf('"') === 0 || part.indexOf('\'') === 0) { | ||
blockQuoteRegExp = part.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp; | ||
openingQuote = part.indexOf('"') === 0 ? '"' : '\''; | ||
// Plain String | ||
if (part.match(blockQuoteRegExp).length === 2) { | ||
// One word string | ||
slices.push(part); | ||
} else { | ||
// Find closed Index | ||
shiftIndex = 0; | ||
for (j = i + 1; j < helperParts.length; j += 1) { | ||
part += " " + (helperParts[j]); | ||
if (helperParts[j].indexOf(openingQuote) >= 0) { | ||
shiftIndex = j; | ||
slices.push(part); | ||
break; | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
}, | ||
helperToSlices: function helperToSlices(string) { | ||
var quoteDoubleRexExp = Template7Utils.quoteDoubleRexExp; | ||
var quoteSingleRexExp = Template7Utils.quoteSingleRexExp; | ||
var helperParts = string.replace(/[{}#}]/g, '').trim().split(' '); | ||
var slices = []; | ||
var shiftIndex; | ||
var i; | ||
var j; | ||
for (i = 0; i < helperParts.length; i += 1) { | ||
var part = helperParts[i]; | ||
var blockQuoteRegExp = (void 0); | ||
var openingQuote = (void 0); | ||
if (i === 0) { slices.push(part); } | ||
else if (part.indexOf('"') === 0 || part.indexOf('\'') === 0) { | ||
blockQuoteRegExp = part.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp; | ||
openingQuote = part.indexOf('"') === 0 ? '"' : '\''; | ||
// Plain String | ||
if (part.match(blockQuoteRegExp).length === 2) { | ||
// One word string | ||
slices.push(part); | ||
} else { | ||
// Find closed Index | ||
shiftIndex = 0; | ||
for (j = i + 1; j < helperParts.length; j += 1) { | ||
part += " " + (helperParts[j]); | ||
if (helperParts[j].indexOf(openingQuote) >= 0) { | ||
shiftIndex = j; | ||
slices.push(part); | ||
break; | ||
} | ||
} | ||
if (shiftIndex) { i = shiftIndex; } | ||
} | ||
if (shiftIndex) { i = shiftIndex; } | ||
} | ||
} else if (part.indexOf('=') > 0) { | ||
// Hash | ||
var hashParts = part.split('='); | ||
var hashName = hashParts[0]; | ||
var hashContent = hashParts[1]; | ||
if (!blockQuoteRegExp) { | ||
blockQuoteRegExp = hashContent.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp; | ||
openingQuote = hashContent.indexOf('"') === 0 ? '"' : '\''; | ||
} | ||
if (hashContent.match(blockQuoteRegExp).length !== 2) { | ||
shiftIndex = 0; | ||
for (j = i + 1; j < helperParts.length; j += 1) { | ||
hashContent += " " + (helperParts[j]); | ||
if (helperParts[j].indexOf(openingQuote) >= 0) { | ||
shiftIndex = j; | ||
break; | ||
} else if (part.indexOf('=') > 0) { | ||
// Hash | ||
var hashParts = part.split('='); | ||
var hashName = hashParts[0]; | ||
var hashContent = hashParts[1]; | ||
if (!blockQuoteRegExp) { | ||
blockQuoteRegExp = hashContent.indexOf('"') === 0 ? quoteDoubleRexExp : quoteSingleRexExp; | ||
openingQuote = hashContent.indexOf('"') === 0 ? '"' : '\''; | ||
} | ||
if (hashContent.match(blockQuoteRegExp).length !== 2) { | ||
shiftIndex = 0; | ||
for (j = i + 1; j < helperParts.length; j += 1) { | ||
hashContent += " " + (helperParts[j]); | ||
if (helperParts[j].indexOf(openingQuote) >= 0) { | ||
shiftIndex = j; | ||
break; | ||
} | ||
} | ||
if (shiftIndex) { i = shiftIndex; } | ||
} | ||
if (shiftIndex) { i = shiftIndex; } | ||
var hash = [hashName, hashContent.replace(blockQuoteRegExp, '')]; | ||
slices.push(hash); | ||
} else { | ||
// Plain variable | ||
slices.push(part); | ||
} | ||
var hash = [hashName, hashContent.replace(blockQuoteRegExp, '')]; | ||
slices.push(hash); | ||
} else { | ||
// Plain variable | ||
slices.push(part); | ||
} | ||
} | ||
return slices; | ||
}, | ||
stringToBlocks: function stringToBlocks(string) { | ||
var blocks = []; | ||
var i; | ||
var j; | ||
if (!string) { return []; } | ||
var stringBlocks = string.split(/({{[^{^}]*}})/); | ||
for (i = 0; i < stringBlocks.length; i += 1) { | ||
var block = stringBlocks[i]; | ||
if (block === '') { continue; } | ||
if (block.indexOf('{{') < 0) { | ||
blocks.push({ | ||
type: 'plain', | ||
content: block, | ||
}); | ||
} else { | ||
if (block.indexOf('{/') >= 0) { | ||
continue; | ||
} | ||
block = block | ||
.replace(/{{([#/])*([ ])*/, '{{$1') | ||
.replace(/([ ])*}}/, '}}'); | ||
if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) { | ||
// Simple variable | ||
return slices; | ||
}, | ||
stringToBlocks: function stringToBlocks(string) { | ||
var blocks = []; | ||
var i; | ||
var j; | ||
if (!string) { return []; } | ||
var stringBlocks = string.split(/({{[^{^}]*}})/); | ||
for (i = 0; i < stringBlocks.length; i += 1) { | ||
var block = stringBlocks[i]; | ||
if (block === '') { continue; } | ||
if (block.indexOf('{{') < 0) { | ||
blocks.push({ | ||
type: 'variable', | ||
contextName: block.replace(/[{}]/g, ''), | ||
type: 'plain', | ||
content: block, | ||
}); | ||
continue; | ||
} | ||
// Helpers | ||
var helperSlices = Template7Utils.helperToSlices(block); | ||
var helperName = helperSlices[0]; | ||
var isPartial = helperName === '>'; | ||
var helperContext = []; | ||
var helperHash = {}; | ||
for (j = 1; j < helperSlices.length; j += 1) { | ||
var slice = helperSlices[j]; | ||
if (Array.isArray(slice)) { | ||
// Hash | ||
helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1]; | ||
} else { | ||
helperContext.push(slice); | ||
} else { | ||
if (block.indexOf('{/') >= 0) { | ||
continue; | ||
} | ||
} | ||
block = block | ||
.replace(/{{([#/])*([ ])*/, '{{$1') | ||
.replace(/([ ])*}}/, '}}'); | ||
if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) { | ||
// Simple variable | ||
blocks.push({ | ||
type: 'variable', | ||
contextName: block.replace(/[{}]/g, ''), | ||
}); | ||
continue; | ||
} | ||
// Helpers | ||
var helperSlices = Template7Utils.helperToSlices(block); | ||
var helperName = helperSlices[0]; | ||
var isPartial = helperName === '>'; | ||
var helperContext = []; | ||
var helperHash = {}; | ||
for (j = 1; j < helperSlices.length; j += 1) { | ||
var slice = helperSlices[j]; | ||
if (Array.isArray(slice)) { | ||
// Hash | ||
helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1]; | ||
} else { | ||
helperContext.push(slice); | ||
} | ||
} | ||
if (block.indexOf('{#') >= 0) { | ||
// Condition/Helper | ||
var helperContent = ''; | ||
var elseContent = ''; | ||
var toSkip = 0; | ||
var shiftIndex = (void 0); | ||
var foundClosed = false; | ||
var foundElse = false; | ||
var depth = 0; | ||
for (j = i + 1; j < stringBlocks.length; j += 1) { | ||
if (stringBlocks[j].indexOf('{{#') >= 0) { | ||
depth += 1; | ||
} | ||
if (stringBlocks[j].indexOf('{{/') >= 0) { | ||
depth -= 1; | ||
} | ||
if (stringBlocks[j].indexOf(("{{#" + helperName)) >= 0) { | ||
helperContent += stringBlocks[j]; | ||
if (foundElse) { elseContent += stringBlocks[j]; } | ||
toSkip += 1; | ||
} else if (stringBlocks[j].indexOf(("{{/" + helperName)) >= 0) { | ||
if (toSkip > 0) { | ||
toSkip -= 1; | ||
if (block.indexOf('{#') >= 0) { | ||
// Condition/Helper | ||
var helperContent = ''; | ||
var elseContent = ''; | ||
var toSkip = 0; | ||
var shiftIndex = (void 0); | ||
var foundClosed = false; | ||
var foundElse = false; | ||
var depth = 0; | ||
for (j = i + 1; j < stringBlocks.length; j += 1) { | ||
if (stringBlocks[j].indexOf('{{#') >= 0) { | ||
depth += 1; | ||
} | ||
if (stringBlocks[j].indexOf('{{/') >= 0) { | ||
depth -= 1; | ||
} | ||
if (stringBlocks[j].indexOf(("{{#" + helperName)) >= 0) { | ||
helperContent += stringBlocks[j]; | ||
if (foundElse) { elseContent += stringBlocks[j]; } | ||
toSkip += 1; | ||
} else if (stringBlocks[j].indexOf(("{{/" + helperName)) >= 0) { | ||
if (toSkip > 0) { | ||
toSkip -= 1; | ||
helperContent += stringBlocks[j]; | ||
if (foundElse) { elseContent += stringBlocks[j]; } | ||
} else { | ||
shiftIndex = j; | ||
foundClosed = true; | ||
break; | ||
} | ||
} else if (stringBlocks[j].indexOf('else') >= 0 && depth === 0) { | ||
foundElse = true; | ||
} else { | ||
shiftIndex = j; | ||
foundClosed = true; | ||
break; | ||
if (!foundElse) { helperContent += stringBlocks[j]; } | ||
if (foundElse) { elseContent += stringBlocks[j]; } | ||
} | ||
} else if (stringBlocks[j].indexOf('else') >= 0 && depth === 0) { | ||
foundElse = true; | ||
} else { | ||
if (!foundElse) { helperContent += stringBlocks[j]; } | ||
if (foundElse) { elseContent += stringBlocks[j]; } | ||
} | ||
} | ||
if (foundClosed) { | ||
if (shiftIndex) { i = shiftIndex; } | ||
if (helperName === 'raw') { | ||
blocks.push({ | ||
type: 'plain', | ||
content: helperContent, | ||
}); | ||
} else { | ||
blocks.push({ | ||
type: 'helper', | ||
helperName: helperName, | ||
contextName: helperContext, | ||
content: helperContent, | ||
inverseContent: elseContent, | ||
hash: helperHash, | ||
}); | ||
if (foundClosed) { | ||
if (shiftIndex) { i = shiftIndex; } | ||
if (helperName === 'raw') { | ||
blocks.push({ | ||
type: 'plain', | ||
content: helperContent, | ||
}); | ||
} else { | ||
blocks.push({ | ||
type: 'helper', | ||
helperName: helperName, | ||
contextName: helperContext, | ||
content: helperContent, | ||
inverseContent: elseContent, | ||
hash: helperHash, | ||
}); | ||
} | ||
} | ||
} | ||
} else if (block.indexOf(' ') > 0) { | ||
if (isPartial) { | ||
helperName = '_partial'; | ||
if (helperContext[0]) { | ||
if (helperContext[0].indexOf('[') === 0) { helperContext[0] = helperContext[0].replace(/[[\]]/g, ''); } | ||
else { helperContext[0] = "\"" + (helperContext[0].replace(/"|'/g, '')) + "\""; } | ||
} else if (block.indexOf(' ') > 0) { | ||
if (isPartial) { | ||
helperName = '_partial'; | ||
if (helperContext[0]) { | ||
if (helperContext[0].indexOf('[') === 0) { helperContext[0] = helperContext[0].replace(/[[\]]/g, ''); } | ||
else { helperContext[0] = "\"" + (helperContext[0].replace(/"|'/g, '')) + "\""; } | ||
} | ||
} | ||
blocks.push({ | ||
type: 'helper', | ||
helperName: helperName, | ||
contextName: helperContext, | ||
hash: helperHash, | ||
}); | ||
} | ||
blocks.push({ | ||
type: 'helper', | ||
helperName: helperName, | ||
contextName: helperContext, | ||
hash: helperHash, | ||
} | ||
} | ||
return blocks; | ||
}, | ||
parseJsVariable: function parseJsVariable(expression, replace, object) { | ||
return expression.split(/([+ \-*/^()&=|<>!%:?])/g).reduce(function (arr, part) { | ||
if (!part) { | ||
return arr; | ||
} | ||
if (part.indexOf(replace) < 0) { | ||
arr.push(part); | ||
return arr; | ||
} | ||
if (!object) { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
var variable = object; | ||
if (part.indexOf((replace + ".")) >= 0) { | ||
part.split((replace + "."))[1].split('.').forEach(function (partName) { | ||
if (partName in variable) { variable = variable[partName]; } | ||
else { variable = undefined; } | ||
}); | ||
} | ||
} | ||
} | ||
return blocks; | ||
}, | ||
parseJsVariable: function parseJsVariable(expression, replace, object) { | ||
return expression.split(/([+ \-*/^])/g).map(function (part) { | ||
if (part.indexOf(replace) < 0) { return part; } | ||
if (!object) { return JSON.stringify(''); } | ||
var variable = object; | ||
if (part.indexOf((replace + ".")) >= 0) { | ||
part.split((replace + "."))[1].split('.').forEach(function (partName) { | ||
if (partName in variable) { variable = variable[partName]; } | ||
else { variable = undefined; } | ||
if (typeof variable === 'string') { | ||
variable = JSON.stringify(variable); | ||
} | ||
if (variable === undefined) { variable = 'undefined'; } | ||
arr.push(variable); | ||
return arr; | ||
}, []).join(''); | ||
}, | ||
parseJsParents: function parseJsParents(expression, parents) { | ||
return expression.split(/([+ \-*^()&=|<>!%:?])/g).reduce(function (arr, part) { | ||
if (!part) { | ||
return arr; | ||
} | ||
if (part.indexOf('../') < 0) { | ||
arr.push(part); | ||
return arr; | ||
} | ||
if (!parents || parents.length === 0) { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
var levelsUp = part.split('../').length - 1; | ||
var parentData = levelsUp > parents.length ? parents[parents.length - 1] : parents[levelsUp - 1]; | ||
var variable = parentData; | ||
var parentPart = part.replace(/..\//g, ''); | ||
parentPart.split('.').forEach(function (partName) { | ||
if (typeof variable[partName] !== 'undefined') { variable = variable[partName]; } | ||
else { variable = 'undefined'; } | ||
}); | ||
if (variable === false || variable === true) { | ||
arr.push(JSON.stringify(variable)); | ||
return arr; | ||
} | ||
if (variable === null || variable === 'undefined') { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
arr.push(JSON.stringify(variable)); | ||
return arr; | ||
}, []).join(''); | ||
}, | ||
getCompileVar: function getCompileVar(name, ctx, data) { | ||
if ( data === void 0 ) data = 'data_1'; | ||
var variable = ctx; | ||
var parts; | ||
var levelsUp = 0; | ||
var newDepth; | ||
if (name.indexOf('../') === 0) { | ||
levelsUp = name.split('../').length - 1; | ||
newDepth = variable.split('_')[1] - levelsUp; | ||
variable = "ctx_" + (newDepth >= 1 ? newDepth : 1); | ||
parts = name.split('../')[levelsUp].split('.'); | ||
} else if (name.indexOf('@global') === 0) { | ||
variable = 'Template7.global'; | ||
parts = name.split('@global.')[1].split('.'); | ||
} else if (name.indexOf('@root') === 0) { | ||
variable = 'root'; | ||
parts = name.split('@root.')[1].split('.'); | ||
} else { | ||
parts = name.split('.'); | ||
} | ||
if (typeof variable === 'string') { | ||
variable = JSON.stringify(variable); | ||
for (var i = 0; i < parts.length; i += 1) { | ||
var part = parts[i]; | ||
if (part.indexOf('@') === 0) { | ||
var dataLevel = data.split('_')[1]; | ||
if (levelsUp > 0) { | ||
dataLevel = newDepth; | ||
} | ||
if (i > 0) { | ||
variable += "[(data_" + dataLevel + " && data_" + dataLevel + "." + (part.replace('@', '')) + ")]"; | ||
} else { | ||
variable = "(data_" + dataLevel + " && data_" + dataLevel + "." + (part.replace('@', '')) + ")"; | ||
} | ||
} else if (Number.isFinite ? Number.isFinite(part) : Template7Context.isFinite(part)) { | ||
variable += "[" + part + "]"; | ||
} else if (part === 'this' || part.indexOf('this.') >= 0 || part.indexOf('this[') >= 0 || part.indexOf('this(') >= 0) { | ||
variable = part.replace('this', ctx); | ||
} else { | ||
variable += "." + part; | ||
} | ||
} | ||
if (variable === undefined) { variable = 'undefined'; } | ||
return variable; | ||
}).join(''); | ||
}, | ||
parseJsParents: function parseJsParents(expression, parents) { | ||
return expression.split(/([+ \-*^])/g).map(function (part) { | ||
if (part.indexOf('../') < 0) { return part; } | ||
if (!parents || parents.length === 0) { return JSON.stringify(''); } | ||
var levelsUp = part.split('../').length - 1; | ||
var parentData = levelsUp > parents.length ? parents[parents.length - 1] : parents[levelsUp - 1]; | ||
}, | ||
getCompiledArguments: function getCompiledArguments(contextArray, ctx, data) { | ||
var arr = []; | ||
for (var i = 0; i < contextArray.length; i += 1) { | ||
if (/^['"]/.test(contextArray[i])) { arr.push(contextArray[i]); } | ||
else if (/^(true|false|\d+)$/.test(contextArray[i])) { arr.push(contextArray[i]); } | ||
else { | ||
arr.push(Template7Utils.getCompileVar(contextArray[i], ctx, data)); | ||
} | ||
} | ||
var variable = parentData; | ||
var parentPart = part.replace(/..\//g, ''); | ||
parentPart.split('.').forEach(function (partName) { | ||
if (variable[partName]) { variable = variable[partName]; } | ||
else { variable = 'undefined'; } | ||
return arr.join(', '); | ||
}, | ||
}; | ||
/* eslint no-eval: "off" */ | ||
var Template7Helpers = { | ||
_partial: function _partial(partialName, options) { | ||
var ctx = this; | ||
var p = Template7Class.partials[partialName]; | ||
if (!p || (p && !p.template)) { return ''; } | ||
if (!p.compiled) { | ||
p.compiled = new Template7Class(p.template).compile(); | ||
} | ||
Object.keys(options.hash).forEach(function (hashName) { | ||
ctx[hashName] = options.hash[hashName]; | ||
}); | ||
return JSON.stringify(variable); | ||
}).join(''); | ||
}, | ||
getCompileVar: function getCompileVar(name, ctx, data) { | ||
if ( data === void 0 ) data = 'data_1'; | ||
return p.compiled(ctx, options.data, options.root); | ||
}, | ||
escape: function escape(context) { | ||
if (typeof context !== 'string') { | ||
throw new Error('Template7: Passed context to "escape" helper should be a string'); | ||
} | ||
return Template7Utils.escape(context); | ||
}, | ||
if: function if$1(context, options) { | ||
var ctx = context; | ||
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | ||
if (ctx) { | ||
return options.fn(this, options.data); | ||
} | ||
var variable = ctx; | ||
var parts; | ||
var levelsUp = 0; | ||
var newDepth; | ||
if (name.indexOf('../') === 0) { | ||
levelsUp = name.split('../').length - 1; | ||
newDepth = variable.split('_')[1] - levelsUp; | ||
variable = "ctx_" + (newDepth >= 1 ? newDepth : 1); | ||
parts = name.split('../')[levelsUp].split('.'); | ||
} else if (name.indexOf('@global') === 0) { | ||
variable = 'Template7.global'; | ||
parts = name.split('@global.')[1].split('.'); | ||
} else if (name.indexOf('@root') === 0) { | ||
variable = 'root'; | ||
parts = name.split('@root.')[1].split('.'); | ||
} else { | ||
parts = name.split('.'); | ||
} | ||
for (var i = 0; i < parts.length; i += 1) { | ||
var part = parts[i]; | ||
if (part.indexOf('@') === 0) { | ||
var dataLevel = data.split('_')[1]; | ||
if (levelsUp > 0) { | ||
dataLevel = newDepth; | ||
return options.inverse(this, options.data); | ||
}, | ||
unless: function unless(context, options) { | ||
var ctx = context; | ||
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | ||
if (!ctx) { | ||
return options.fn(this, options.data); | ||
} | ||
return options.inverse(this, options.data); | ||
}, | ||
each: function each(context, options) { | ||
var ctx = context; | ||
var ret = ''; | ||
var i = 0; | ||
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | ||
if (Array.isArray(ctx)) { | ||
if (options.hash.reverse) { | ||
ctx = ctx.reverse(); | ||
} | ||
if (i > 0) { | ||
variable += "[(data_" + dataLevel + " && data_" + dataLevel + "." + (part.replace('@', '')) + ")]"; | ||
} else { | ||
variable = "(data_" + dataLevel + " && data_" + dataLevel + "." + (part.replace('@', '')) + ")"; | ||
for (i = 0; i < ctx.length; i += 1) { | ||
ret += options.fn(ctx[i], { first: i === 0, last: i === ctx.length - 1, index: i }); | ||
} | ||
} else if (Number.isFinite ? Number.isFinite(part) : Template7Context.isFinite(part)) { | ||
variable += "[" + part + "]"; | ||
} else if (part === 'this' || part.indexOf('this.') >= 0 || part.indexOf('this[') >= 0 || part.indexOf('this(') >= 0) { | ||
variable = part.replace('this', ctx); | ||
if (options.hash.reverse) { | ||
ctx = ctx.reverse(); | ||
} | ||
} else { | ||
variable += "." + part; | ||
// eslint-disable-next-line | ||
for (var key in ctx) { | ||
i += 1; | ||
ret += options.fn(ctx[key], { key: key }); | ||
} | ||
} | ||
} | ||
return variable; | ||
}, | ||
getCompiledArguments: function getCompiledArguments(contextArray, ctx, data) { | ||
var arr = []; | ||
for (var i = 0; i < contextArray.length; i += 1) { | ||
if (/^['"]/.test(contextArray[i])) { arr.push(contextArray[i]); } | ||
else if (/^(true|false|\d+)$/.test(contextArray[i])) { arr.push(contextArray[i]); } | ||
else { | ||
arr.push(Template7Utils.getCompileVar(contextArray[i], ctx, data)); | ||
if (i > 0) { return ret; } | ||
return options.inverse(this); | ||
}, | ||
with: function with$1(context, options) { | ||
var ctx = context; | ||
if (Template7Utils.isFunction(ctx)) { ctx = context.call(this); } | ||
return options.fn(ctx); | ||
}, | ||
join: function join(context, options) { | ||
var ctx = context; | ||
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | ||
return ctx.join(options.hash.delimiter || options.hash.delimeter); | ||
}, | ||
js: function js(expression, options) { | ||
var data = options.data; | ||
var func; | ||
var execute = expression; | ||
('index first last key').split(' ').forEach(function (prop) { | ||
if (typeof data[prop] !== 'undefined') { | ||
var re1 = new RegExp(("this.@" + prop), 'g'); | ||
var re2 = new RegExp(("@" + prop), 'g'); | ||
execute = execute | ||
.replace(re1, JSON.stringify(data[prop])) | ||
.replace(re2, JSON.stringify(data[prop])); | ||
} | ||
}); | ||
if (options.root && execute.indexOf('@root') >= 0) { | ||
execute = Template7Utils.parseJsVariable(execute, '@root', options.root); | ||
} | ||
} | ||
return arr.join(', '); | ||
}, | ||
}; | ||
/* eslint no-eval: "off" */ | ||
var Template7Helpers = { | ||
_partial: function _partial(partialName, options) { | ||
var ctx = this; | ||
var p = Template7Class.partials[partialName]; | ||
if (!p || (p && !p.template)) { return ''; } | ||
if (!p.compiled) { | ||
p.compiled = new Template7Class(p.template).compile(); | ||
} | ||
Object.keys(options.hash).forEach(function (hashName) { | ||
ctx[hashName] = options.hash[hashName]; | ||
}); | ||
return p.compiled(ctx, options.data, options.root); | ||
}, | ||
escape: function escape(context) { | ||
if (typeof context !== 'string') { | ||
throw new Error('Template7: Passed context to "escape" helper should be a string'); | ||
} | ||
return Template7Utils.escape(context); | ||
}, | ||
if: function if$1(context, options) { | ||
var ctx = context; | ||
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | ||
if (ctx) { | ||
return options.fn(this, options.data); | ||
} | ||
return options.inverse(this, options.data); | ||
}, | ||
unless: function unless(context, options) { | ||
var ctx = context; | ||
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | ||
if (!ctx) { | ||
return options.fn(this, options.data); | ||
} | ||
return options.inverse(this, options.data); | ||
}, | ||
each: function each(context, options) { | ||
var ctx = context; | ||
var ret = ''; | ||
var i = 0; | ||
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | ||
if (Array.isArray(ctx)) { | ||
if (options.hash.reverse) { | ||
ctx = ctx.reverse(); | ||
if (execute.indexOf('@global') >= 0) { | ||
execute = Template7Utils.parseJsVariable(execute, '@global', Template7Context.Template7.global); | ||
} | ||
for (i = 0; i < ctx.length; i += 1) { | ||
ret += options.fn(ctx[i], { first: i === 0, last: i === ctx.length - 1, index: i }); | ||
if (execute.indexOf('../') >= 0) { | ||
execute = Template7Utils.parseJsParents(execute, options.parents); | ||
} | ||
if (options.hash.reverse) { | ||
ctx = ctx.reverse(); | ||
if (execute.indexOf('return') >= 0) { | ||
func = "(function(){" + execute + "})"; | ||
} else { | ||
func = "(function(){return (" + execute + ")})"; | ||
} | ||
} else { | ||
// eslint-disable-next-line | ||
for (var key in ctx) { | ||
i += 1; | ||
ret += options.fn(ctx[key], { key: key }); | ||
return eval(func).call(this); | ||
}, | ||
js_if: function js_if(expression, options) { | ||
var data = options.data; | ||
var func; | ||
var execute = expression; | ||
('index first last key').split(' ').forEach(function (prop) { | ||
if (typeof data[prop] !== 'undefined') { | ||
var re1 = new RegExp(("this.@" + prop), 'g'); | ||
var re2 = new RegExp(("@" + prop), 'g'); | ||
execute = execute | ||
.replace(re1, JSON.stringify(data[prop])) | ||
.replace(re2, JSON.stringify(data[prop])); | ||
} | ||
}); | ||
if (options.root && execute.indexOf('@root') >= 0) { | ||
execute = Template7Utils.parseJsVariable(execute, '@root', options.root); | ||
} | ||
} | ||
if (i > 0) { return ret; } | ||
return options.inverse(this); | ||
}, | ||
with: function with$1(context, options) { | ||
var ctx = context; | ||
if (Template7Utils.isFunction(ctx)) { ctx = context.call(this); } | ||
return options.fn(ctx); | ||
}, | ||
join: function join(context, options) { | ||
var ctx = context; | ||
if (Template7Utils.isFunction(ctx)) { ctx = ctx.call(this); } | ||
return ctx.join(options.hash.delimiter || options.hash.delimeter); | ||
}, | ||
js: function js(expression, options) { | ||
var data = options.data; | ||
var func; | ||
var execute = expression; | ||
('index first last key').split(' ').forEach(function (prop) { | ||
if (typeof data[prop] !== 'undefined') { | ||
var re1 = new RegExp(("this.@" + prop), 'g'); | ||
var re2 = new RegExp(("@" + prop), 'g'); | ||
execute = execute | ||
.replace(re1, JSON.stringify(data[prop])) | ||
.replace(re2, JSON.stringify(data[prop])); | ||
if (execute.indexOf('@global') >= 0) { | ||
execute = Template7Utils.parseJsVariable(execute, '@global', Template7Context.Template7.global); | ||
} | ||
}); | ||
if (options.root && execute.indexOf('@root') >= 0) { | ||
execute = Template7Utils.parseJsVariable(execute, '@root', options.root); | ||
} | ||
if (execute.indexOf('@global') >= 0) { | ||
execute = Template7Utils.parseJsVariable(execute, '@global', Template7Context.Template7.global); | ||
} | ||
if (execute.indexOf('../') >= 0) { | ||
execute = Template7Utils.parseJsParents(execute, options.parents); | ||
} | ||
if (execute.indexOf('return') >= 0) { | ||
func = "(function(){" + execute + "})"; | ||
} else { | ||
func = "(function(){return (" + execute + ")})"; | ||
} | ||
return eval(func).call(this); | ||
}, | ||
js_if: function js_if(expression, options) { | ||
var data = options.data; | ||
var func; | ||
var execute = expression; | ||
('index first last key').split(' ').forEach(function (prop) { | ||
if (typeof data[prop] !== 'undefined') { | ||
var re1 = new RegExp(("this.@" + prop), 'g'); | ||
var re2 = new RegExp(("@" + prop), 'g'); | ||
execute = execute | ||
.replace(re1, JSON.stringify(data[prop])) | ||
.replace(re2, JSON.stringify(data[prop])); | ||
if (execute.indexOf('../') >= 0) { | ||
execute = Template7Utils.parseJsParents(execute, options.parents); | ||
} | ||
}); | ||
if (options.root && execute.indexOf('@root') >= 0) { | ||
execute = Template7Utils.parseJsVariable(execute, '@root', options.root); | ||
} | ||
if (execute.indexOf('@global') >= 0) { | ||
execute = Template7Utils.parseJsVariable(execute, '@global', Template7Context.Template7.global); | ||
} | ||
if (execute.indexOf('../') >= 0) { | ||
execute = Template7Utils.parseJsParents(execute, options.parents); | ||
} | ||
if (execute.indexOf('return') >= 0) { | ||
func = "(function(){" + execute + "})"; | ||
} else { | ||
func = "(function(){return (" + execute + ")})"; | ||
} | ||
var condition = eval(func).call(this); | ||
if (condition) { | ||
return options.fn(this, options.data); | ||
} | ||
if (execute.indexOf('return') >= 0) { | ||
func = "(function(){" + execute + "})"; | ||
} else { | ||
func = "(function(){return (" + execute + ")})"; | ||
} | ||
var condition = eval(func).call(this); | ||
if (condition) { | ||
return options.fn(this, options.data); | ||
} | ||
return options.inverse(this, options.data); | ||
}, | ||
}; | ||
Template7Helpers.js_compare = Template7Helpers.js_if; | ||
return options.inverse(this, options.data); | ||
}, | ||
}; | ||
Template7Helpers.js_compare = Template7Helpers.js_if; | ||
var Template7Options = {}; | ||
var Template7Partials = {}; | ||
var Template7Options = {}; | ||
var Template7Partials = {}; | ||
var Template7Class = function Template7Class(template) { | ||
var t = this; | ||
t.template = template; | ||
}; | ||
var Template7Class = function Template7Class(template) { | ||
var t = this; | ||
t.template = template; | ||
}; | ||
var staticAccessors = { options: { configurable: true },partials: { configurable: true },helpers: { configurable: true } }; | ||
Template7Class.prototype.compile = function compile (template, depth) { | ||
if ( template === void 0 ) template = this.template; | ||
if ( depth === void 0 ) depth = 1; | ||
var staticAccessors = { options: { configurable: true },partials: { configurable: true },helpers: { configurable: true } }; | ||
Template7Class.prototype.compile = function compile (template, depth) { | ||
if ( template === void 0 ) template = this.template; | ||
if ( depth === void 0 ) depth = 1; | ||
var t = this; | ||
if (t.compiled) { return t.compiled; } | ||
var t = this; | ||
if (t.compiled) { return t.compiled; } | ||
if (typeof template !== 'string') { | ||
throw new Error('Template7: Template must be a string'); | ||
} | ||
var stringToBlocks = Template7Utils.stringToBlocks; | ||
var getCompileVar = Template7Utils.getCompileVar; | ||
var getCompiledArguments = Template7Utils.getCompiledArguments; | ||
if (typeof template !== 'string') { | ||
throw new Error('Template7: Template must be a string'); | ||
} | ||
var stringToBlocks = Template7Utils.stringToBlocks; | ||
var getCompileVar = Template7Utils.getCompileVar; | ||
var getCompiledArguments = Template7Utils.getCompiledArguments; | ||
var blocks = stringToBlocks(template); | ||
var ctx = "ctx_" + depth; | ||
var data = "data_" + depth; | ||
if (blocks.length === 0) { | ||
return function empty() { return ''; }; | ||
} | ||
var blocks = stringToBlocks(template); | ||
var ctx = "ctx_" + depth; | ||
var data = "data_" + depth; | ||
if (blocks.length === 0) { | ||
return function empty() { return ''; }; | ||
} | ||
function getCompileFn(block, newDepth) { | ||
if (block.content) { return t.compile(block.content, newDepth); } | ||
return function empty() { return ''; }; | ||
} | ||
function getCompileInverse(block, newDepth) { | ||
if (block.inverseContent) { return t.compile(block.inverseContent, newDepth); } | ||
return function empty() { return ''; }; | ||
} | ||
function getCompileFn(block, newDepth) { | ||
if (block.content) { return t.compile(block.content, newDepth); } | ||
return function empty() { return ''; }; | ||
} | ||
function getCompileInverse(block, newDepth) { | ||
if (block.inverseContent) { return t.compile(block.inverseContent, newDepth); } | ||
return function empty() { return ''; }; | ||
} | ||
var resultString = ''; | ||
if (depth === 1) { | ||
resultString += "(function (" + ctx + ", " + data + ", root) {\n"; | ||
} else { | ||
resultString += "(function (" + ctx + ", " + data + ") {\n"; | ||
} | ||
if (depth === 1) { | ||
resultString += 'function isArray(arr){return Array.isArray(arr);}\n'; | ||
resultString += 'function isFunction(func){return (typeof func === \'function\');}\n'; | ||
resultString += 'function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n'; | ||
resultString += 'root = root || ctx_1 || {};\n'; | ||
} | ||
resultString += 'var r = \'\';\n'; | ||
var i; | ||
for (i = 0; i < blocks.length; i += 1) { | ||
var block = blocks[i]; | ||
// Plain block | ||
if (block.type === 'plain') { | ||
// eslint-disable-next-line | ||
resultString += "r +='" + ((block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'')) + "';"; | ||
continue; | ||
var resultString = ''; | ||
if (depth === 1) { | ||
resultString += "(function (" + ctx + ", " + data + ", root) {\n"; | ||
} else { | ||
resultString += "(function (" + ctx + ", " + data + ") {\n"; | ||
} | ||
var variable = (void 0); | ||
var compiledArguments = (void 0); | ||
// Variable block | ||
if (block.type === 'variable') { | ||
variable = getCompileVar(block.contextName, ctx, data); | ||
resultString += "r += c(" + variable + ", " + ctx + ");"; | ||
if (depth === 1) { | ||
resultString += 'function isArray(arr){return Array.isArray(arr);}\n'; | ||
resultString += 'function isFunction(func){return (typeof func === \'function\');}\n'; | ||
resultString += 'function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n'; | ||
resultString += 'root = root || ctx_1 || {};\n'; | ||
} | ||
// Helpers block | ||
if (block.type === 'helper') { | ||
var parents = (void 0); | ||
if (ctx !== 'ctx_1') { | ||
var level = ctx.split('_')[1]; | ||
var parentsString = "ctx_" + (level - 1); | ||
for (var j = level - 2; j >= 1; j -= 1) { | ||
parentsString += ", ctx_" + j; | ||
} | ||
parents = "[" + parentsString + "]"; | ||
} else { | ||
parents = "[" + ctx + "]"; | ||
resultString += 'var r = \'\';\n'; | ||
var i; | ||
for (i = 0; i < blocks.length; i += 1) { | ||
var block = blocks[i]; | ||
// Plain block | ||
if (block.type === 'plain') { | ||
// eslint-disable-next-line | ||
resultString += "r +='" + ((block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'')) + "';"; | ||
continue; | ||
} | ||
var dynamicHelper = (void 0); | ||
if (block.helperName.indexOf('[') === 0) { | ||
block.helperName = getCompileVar(block.helperName.replace(/[[\]]/g, ''), ctx, data); | ||
dynamicHelper = true; | ||
var variable = (void 0); | ||
var compiledArguments = (void 0); | ||
// Variable block | ||
if (block.type === 'variable') { | ||
variable = getCompileVar(block.contextName, ctx, data); | ||
resultString += "r += c(" + variable + ", " + ctx + ");"; | ||
} | ||
if (dynamicHelper || block.helperName in Template7Helpers) { | ||
compiledArguments = getCompiledArguments(block.contextName, ctx, data); | ||
resultString += "r += (Template7Helpers" + (dynamicHelper ? ("[" + (block.helperName) + "]") : ("." + (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, parents: " + parents + "});"; | ||
} else if (block.contextName.length > 0) { | ||
throw new Error(("Template7: Missing helper: \"" + (block.helperName) + "\"")); | ||
} else { | ||
variable = getCompileVar(block.helperName, ctx, data); | ||
resultString += "if (" + variable + ") {"; | ||
resultString += "if (isArray(" + variable + ")) {"; | ||
resultString += "r += (Template7Helpers.each).call(" + ctx + ", " + variable + ", {hash:" + (JSON.stringify(block.hash)) + ", data: " + data + " || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root, parents: " + parents + "});"; | ||
resultString += '}else {'; | ||
resultString += "r += (Template7Helpers.with).call(" + ctx + ", " + variable + ", {hash:" + (JSON.stringify(block.hash)) + ", data: " + data + " || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root, parents: " + parents + "});"; | ||
resultString += '}}'; | ||
// Helpers block | ||
if (block.type === 'helper') { | ||
var parents = (void 0); | ||
if (ctx !== 'ctx_1') { | ||
var level = ctx.split('_')[1]; | ||
var parentsString = "ctx_" + (level - 1); | ||
for (var j = level - 2; j >= 1; j -= 1) { | ||
parentsString += ", ctx_" + j; | ||
} | ||
parents = "[" + parentsString + "]"; | ||
} else { | ||
parents = "[" + ctx + "]"; | ||
} | ||
var dynamicHelper = (void 0); | ||
if (block.helperName.indexOf('[') === 0) { | ||
block.helperName = getCompileVar(block.helperName.replace(/[[\]]/g, ''), ctx, data); | ||
dynamicHelper = true; | ||
} | ||
if (dynamicHelper || block.helperName in Template7Helpers) { | ||
compiledArguments = getCompiledArguments(block.contextName, ctx, data); | ||
resultString += "r += (Template7Helpers" + (dynamicHelper ? ("[" + (block.helperName) + "]") : ("." + (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, parents: " + parents + "});"; | ||
} else if (block.contextName.length > 0) { | ||
throw new Error(("Template7: Missing helper: \"" + (block.helperName) + "\"")); | ||
} else { | ||
variable = getCompileVar(block.helperName, ctx, data); | ||
resultString += "if (" + variable + ") {"; | ||
resultString += "if (isArray(" + variable + ")) {"; | ||
resultString += "r += (Template7Helpers.each).call(" + ctx + ", " + variable + ", {hash:" + (JSON.stringify(block.hash)) + ", data: " + data + " || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root, parents: " + parents + "});"; | ||
resultString += '}else {'; | ||
resultString += "r += (Template7Helpers.with).call(" + ctx + ", " + variable + ", {hash:" + (JSON.stringify(block.hash)) + ", data: " + data + " || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root, parents: " + parents + "});"; | ||
resultString += '}}'; | ||
} | ||
} | ||
} | ||
} | ||
resultString += '\nreturn r;})'; | ||
resultString += '\nreturn r;})'; | ||
if (depth === 1) { | ||
// eslint-disable-next-line | ||
t.compiled = eval(resultString); | ||
return t.compiled; | ||
} | ||
return resultString; | ||
}; | ||
staticAccessors.options.get = function () { | ||
return Template7Options; | ||
}; | ||
staticAccessors.partials.get = function () { | ||
return Template7Partials; | ||
}; | ||
staticAccessors.helpers.get = function () { | ||
return Template7Helpers; | ||
}; | ||
if (depth === 1) { | ||
// eslint-disable-next-line | ||
t.compiled = eval(resultString); | ||
return t.compiled; | ||
} | ||
return resultString; | ||
}; | ||
staticAccessors.options.get = function () { | ||
return Template7Options; | ||
}; | ||
staticAccessors.partials.get = function () { | ||
return Template7Partials; | ||
}; | ||
staticAccessors.helpers.get = function () { | ||
return Template7Helpers; | ||
}; | ||
Object.defineProperties( Template7Class, staticAccessors ); | ||
Object.defineProperties( Template7Class, staticAccessors ); | ||
function Template7() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
function Template7() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var template = args[0]; | ||
var data = args[1]; | ||
if (args.length === 2) { | ||
var instance = new Template7Class(template); | ||
var rendered = instance.compile()(data); | ||
instance = null; | ||
return (rendered); | ||
var template = args[0]; | ||
var data = args[1]; | ||
if (args.length === 2) { | ||
var instance = new Template7Class(template); | ||
var rendered = instance.compile()(data); | ||
instance = null; | ||
return (rendered); | ||
} | ||
return new Template7Class(template); | ||
} | ||
return new Template7Class(template); | ||
} | ||
Template7.registerHelper = function registerHelper(name, fn) { | ||
Template7Class.helpers[name] = fn; | ||
}; | ||
Template7.unregisterHelper = function unregisterHelper(name) { | ||
Template7Class.helpers[name] = undefined; | ||
delete Template7Class.helpers[name]; | ||
}; | ||
Template7.registerPartial = function registerPartial(name, template) { | ||
Template7Class.partials[name] = { template: template }; | ||
}; | ||
Template7.unregisterPartial = function unregisterPartial(name) { | ||
if (Template7Class.partials[name]) { | ||
Template7Class.partials[name] = undefined; | ||
delete Template7Class.partials[name]; | ||
} | ||
}; | ||
Template7.compile = function compile(template, options) { | ||
var instance = new Template7Class(template, options); | ||
return instance.compile(); | ||
}; | ||
Template7.registerHelper = function registerHelper(name, fn) { | ||
Template7Class.helpers[name] = fn; | ||
}; | ||
Template7.unregisterHelper = function unregisterHelper(name) { | ||
Template7Class.helpers[name] = undefined; | ||
delete Template7Class.helpers[name]; | ||
}; | ||
Template7.registerPartial = function registerPartial(name, template) { | ||
Template7Class.partials[name] = { template: template }; | ||
}; | ||
Template7.unregisterPartial = function unregisterPartial(name) { | ||
if (Template7Class.partials[name]) { | ||
Template7Class.partials[name] = undefined; | ||
delete Template7Class.partials[name]; | ||
} | ||
}; | ||
Template7.compile = function compile(template, options) { | ||
var instance = new Template7Class(template, options); | ||
return instance.compile(); | ||
}; | ||
Template7.options = Template7Class.options; | ||
Template7.helpers = Template7Class.helpers; | ||
Template7.partials = Template7Class.partials; | ||
Template7.options = Template7Class.options; | ||
Template7.helpers = Template7Class.helpers; | ||
Template7.partials = Template7Class.partials; | ||
return Template7; | ||
return Template7; | ||
}))); | ||
})); | ||
//# sourceMappingURL=template7.js.map |
/** | ||
* Template7 1.4.0 | ||
* Template7 1.4.1 | ||
* Mobile-first HTML template engine | ||
@@ -7,3 +7,3 @@ * | ||
* | ||
* Copyright 2018, Vladimir Kharlampidi | ||
* Copyright 2019, Vladimir Kharlampidi | ||
* The iDangero.us | ||
@@ -14,5 +14,5 @@ * http://www.idangero.us/ | ||
* | ||
* Released on: August 31, 2018 | ||
* Released on: February 5, 2019 | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Template7=t()}(this,function(){"use strict";function Template7(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var i=e[0],r=e[1];if(2===e.length){var n=new Template7Class(i),l=n.compile()(r);return n=null,l}return new Template7Class(i)}var t7ctx;t7ctx="undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0;var Template7Context=t7ctx,Template7Utils={quoteSingleRexExp:new RegExp("'","g"),quoteDoubleRexExp:new RegExp('"',"g"),isFunction:function(e){return"function"==typeof e},escape:function(e){return void 0!==Template7Context&&Template7Context.escape?Template7Context.escape(e):e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},helperToSlices:function(e){var t,i,r,n=Template7Utils.quoteDoubleRexExp,l=Template7Utils.quoteSingleRexExp,a=e.replace(/[{}#}]/g,"").trim().split(" "),s=[];for(i=0;i<a.length;i+=1){var o=a[i],p=void 0,c=void 0;if(0===i)s.push(o);else if(0===o.indexOf('"')||0===o.indexOf("'"))if(p=0===o.indexOf('"')?n:l,c=0===o.indexOf('"')?'"':"'",2===o.match(p).length)s.push(o);else{for(t=0,r=i+1;r<a.length;r+=1)if(o+=" "+a[r],a[r].indexOf(c)>=0){t=r,s.push(o);break}t&&(i=t)}else if(o.indexOf("=")>0){var u=o.split("="),f=u[0],m=u[1];if(p||(p=0===m.indexOf('"')?n:l,c=0===m.indexOf('"')?'"':"'"),2!==m.match(p).length){for(t=0,r=i+1;r<a.length;r+=1)if(m+=" "+a[r],a[r].indexOf(c)>=0){t=r;break}t&&(i=t)}var d=[f,m.replace(p,"")];s.push(d)}else s.push(o)}return s},stringToBlocks:function(e){var t,i,r=[];if(!e)return[];var n=e.split(/({{[^{^}]*}})/);for(t=0;t<n.length;t+=1){var l=n[t];if(""!==l)if(l.indexOf("{{")<0)r.push({type:"plain",content:l});else{if(l.indexOf("{/")>=0)continue;if((l=l.replace(/{{([#/])*([ ])*/,"{{$1").replace(/([ ])*}}/,"}}")).indexOf("{#")<0&&l.indexOf(" ")<0&&l.indexOf("else")<0){r.push({type:"variable",contextName:l.replace(/[{}]/g,"")});continue}var a=Template7Utils.helperToSlices(l),s=a[0],o=">"===s,p=[],c={};for(i=1;i<a.length;i+=1){var u=a[i];Array.isArray(u)?c[u[0]]="false"!==u[1]&&u[1]:p.push(u)}if(l.indexOf("{#")>=0){var f="",m="",d=0,g=void 0,h=!1,x=!1,v=0;for(i=t+1;i<n.length;i+=1)if(n[i].indexOf("{{#")>=0&&(v+=1),n[i].indexOf("{{/")>=0&&(v-=1),n[i].indexOf("{{#"+s)>=0)f+=n[i],x&&(m+=n[i]),d+=1;else if(n[i].indexOf("{{/"+s)>=0){if(!(d>0)){g=i,h=!0;break}d-=1,f+=n[i],x&&(m+=n[i])}else n[i].indexOf("else")>=0&&0===v?x=!0:(x||(f+=n[i]),x&&(m+=n[i]));h&&(g&&(t=g),"raw"===s?r.push({type:"plain",content:f}):r.push({type:"helper",helperName:s,contextName:p,content:f,inverseContent:m,hash:c}))}else l.indexOf(" ")>0&&(o&&(s="_partial",p[0]&&(0===p[0].indexOf("[")?p[0]=p[0].replace(/[[\]]/g,""):p[0]='"'+p[0].replace(/"|'/g,"")+'"')),r.push({type:"helper",helperName:s,contextName:p,hash:c}))}}return r},parseJsVariable:function(e,t,i){return e.split(/([+ \-*/^])/g).map(function(e){if(e.indexOf(t)<0)return e;if(!i)return JSON.stringify("");var r=i;return e.indexOf(t+".")>=0&&e.split(t+".")[1].split(".").forEach(function(e){r=e in r?r[e]:void 0}),"string"==typeof r&&(r=JSON.stringify(r)),void 0===r&&(r="undefined"),r}).join("")},parseJsParents:function(e,t){return e.split(/([+ \-*^])/g).map(function(e){if(e.indexOf("../")<0)return e;if(!t||0===t.length)return JSON.stringify("");var i=e.split("../").length-1,r=i>t.length?t[t.length-1]:t[i-1];return e.replace(/..\//g,"").split(".").forEach(function(e){r=r[e]?r[e]:"undefined"}),JSON.stringify(r)}).join("")},getCompileVar:function(e,t,i){void 0===i&&(i="data_1");var r,n,l=t,a=0;0===e.indexOf("../")?(a=e.split("../").length-1,l="ctx_"+((n=l.split("_")[1]-a)>=1?n:1),r=e.split("../")[a].split(".")):0===e.indexOf("@global")?(l="Template7.global",r=e.split("@global.")[1].split(".")):0===e.indexOf("@root")?(l="root",r=e.split("@root.")[1].split(".")):r=e.split(".");for(var s=0;s<r.length;s+=1){var o=r[s];if(0===o.indexOf("@")){var p=i.split("_")[1];a>0&&(p=n),s>0?l+="[(data_"+p+" && data_"+p+"."+o.replace("@","")+")]":l="(data_"+p+" && data_"+p+"."+o.replace("@","")+")"}else(Number.isFinite?Number.isFinite(o):Template7Context.isFinite(o))?l+="["+o+"]":"this"===o||o.indexOf("this.")>=0||o.indexOf("this[")>=0||o.indexOf("this(")>=0?l=o.replace("this",t):l+="."+o}return l},getCompiledArguments:function(e,t,i){for(var r=[],n=0;n<e.length;n+=1)/^['"]/.test(e[n])?r.push(e[n]):/^(true|false|\d+)$/.test(e[n])?r.push(e[n]):r.push(Template7Utils.getCompileVar(e[n],t,i));return r.join(", ")}},Template7Helpers={_partial:function(e,t){var i=this,r=Template7Class.partials[e];return!r||r&&!r.template?"":(r.compiled||(r.compiled=new Template7Class(r.template).compile()),Object.keys(t.hash).forEach(function(e){i[e]=t.hash[e]}),r.compiled(i,t.data,t.root))},escape:function(e){if("string"!=typeof e)throw new Error('Template7: Passed context to "escape" helper should be a string');return Template7Utils.escape(e)},if:function(e,t){var i=e;return Template7Utils.isFunction(i)&&(i=i.call(this)),i?t.fn(this,t.data):t.inverse(this,t.data)},unless:function(e,t){var i=e;return Template7Utils.isFunction(i)&&(i=i.call(this)),i?t.inverse(this,t.data):t.fn(this,t.data)},each:function(e,t){var i=e,r="",n=0;if(Template7Utils.isFunction(i)&&(i=i.call(this)),Array.isArray(i)){for(t.hash.reverse&&(i=i.reverse()),n=0;n<i.length;n+=1)r+=t.fn(i[n],{first:0===n,last:n===i.length-1,index:n});t.hash.reverse&&(i=i.reverse())}else for(var l in i)n+=1,r+=t.fn(i[l],{key:l});return n>0?r:t.inverse(this)},with:function(e,t){var i=e;return Template7Utils.isFunction(i)&&(i=e.call(this)),t.fn(i)},join:function(e,t){var i=e;return Template7Utils.isFunction(i)&&(i=i.call(this)),i.join(t.hash.delimiter||t.hash.delimeter)},js:function js(expression,options){var data=options.data,func,execute=expression;return"index first last key".split(" ").forEach(function(e){if(void 0!==data[e]){var t=new RegExp("this.@"+e,"g"),i=new RegExp("@"+e,"g");execute=execute.replace(t,JSON.stringify(data[e])).replace(i,JSON.stringify(data[e]))}}),options.root&&execute.indexOf("@root")>=0&&(execute=Template7Utils.parseJsVariable(execute,"@root",options.root)),execute.indexOf("@global")>=0&&(execute=Template7Utils.parseJsVariable(execute,"@global",Template7Context.Template7.global)),execute.indexOf("../")>=0&&(execute=Template7Utils.parseJsParents(execute,options.parents)),func=execute.indexOf("return")>=0?"(function(){"+execute+"})":"(function(){return ("+execute+")})",eval(func).call(this)},js_if:function js_if(expression,options){var data=options.data,func,execute=expression;"index first last key".split(" ").forEach(function(e){if(void 0!==data[e]){var t=new RegExp("this.@"+e,"g"),i=new RegExp("@"+e,"g");execute=execute.replace(t,JSON.stringify(data[e])).replace(i,JSON.stringify(data[e]))}}),options.root&&execute.indexOf("@root")>=0&&(execute=Template7Utils.parseJsVariable(execute,"@root",options.root)),execute.indexOf("@global")>=0&&(execute=Template7Utils.parseJsVariable(execute,"@global",Template7Context.Template7.global)),execute.indexOf("../")>=0&&(execute=Template7Utils.parseJsParents(execute,options.parents)),func=execute.indexOf("return")>=0?"(function(){"+execute+"})":"(function(){return ("+execute+")})";var condition=eval(func).call(this);return condition?options.fn(this,options.data):options.inverse(this,options.data)}};Template7Helpers.js_compare=Template7Helpers.js_if;var Template7Options={},Template7Partials={},Template7Class=function(e){this.template=e},staticAccessors={options:{configurable:!0},partials:{configurable:!0},helpers:{configurable:!0}};return Template7Class.prototype.compile=function compile(template,depth){function getCompileFn(e,i){return e.content?t.compile(e.content,i):function(){return""}}function getCompileInverse(e,i){return e.inverseContent?t.compile(e.inverseContent,i):function(){return""}}void 0===template&&(template=this.template),void 0===depth&&(depth=1);var t=this;if(t.compiled)return t.compiled;if("string"!=typeof template)throw new Error("Template7: Template must be a string");var stringToBlocks=Template7Utils.stringToBlocks,getCompileVar=Template7Utils.getCompileVar,getCompiledArguments=Template7Utils.getCompiledArguments,blocks=stringToBlocks(template),ctx="ctx_"+depth,data="data_"+depth;if(0===blocks.length)return function(){return""};var resultString="";resultString+=1===depth?"(function ("+ctx+", "+data+", root) {\n":"(function ("+ctx+", "+data+") {\n",1===depth&&(resultString+="function isArray(arr){return Array.isArray(arr);}\n",resultString+="function isFunction(func){return (typeof func === 'function');}\n",resultString+='function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n',resultString+="root = root || ctx_1 || {};\n"),resultString+="var r = '';\n";var i;for(i=0;i<blocks.length;i+=1){var block=blocks[i];if("plain"!==block.type){var variable=void 0,compiledArguments=void 0;if("variable"===block.type&&(variable=getCompileVar(block.contextName,ctx,data),resultString+="r += c("+variable+", "+ctx+");"),"helper"===block.type){var parents=void 0;if("ctx_1"!==ctx){for(var level=ctx.split("_")[1],parentsString="ctx_"+(level-1),j=level-2;j>=1;j-=1)parentsString+=", ctx_"+j;parents="["+parentsString+"]"}else parents="["+ctx+"]";var dynamicHelper=void 0;if(0===block.helperName.indexOf("[")&&(block.helperName=getCompileVar(block.helperName.replace(/[[\]]/g,""),ctx,data),dynamicHelper=!0),dynamicHelper||block.helperName in Template7Helpers)compiledArguments=getCompiledArguments(block.contextName,ctx,data),resultString+="r += (Template7Helpers"+(dynamicHelper?"["+block.helperName+"]":"."+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, parents: "+parents+"});";else{if(block.contextName.length>0)throw new Error('Template7: Missing helper: "'+block.helperName+'"');variable=getCompileVar(block.helperName,ctx,data),resultString+="if ("+variable+") {",resultString+="if (isArray("+variable+")) {",resultString+="r += (Template7Helpers.each).call("+ctx+", "+variable+", {hash:"+JSON.stringify(block.hash)+", data: "+data+" || {}, fn: "+getCompileFn(block,depth+1)+", inverse: "+getCompileInverse(block,depth+1)+", root: root, parents: "+parents+"});",resultString+="}else {",resultString+="r += (Template7Helpers.with).call("+ctx+", "+variable+", {hash:"+JSON.stringify(block.hash)+", data: "+data+" || {}, fn: "+getCompileFn(block,depth+1)+", inverse: "+getCompileInverse(block,depth+1)+", root: root, parents: "+parents+"});",resultString+="}}"}}}else resultString+="r +='"+block.content.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/'/g,"\\'")+"';"}return resultString+="\nreturn r;})",1===depth?(t.compiled=eval(resultString),t.compiled):resultString},staticAccessors.options.get=function(){return Template7Options},staticAccessors.partials.get=function(){return Template7Partials},staticAccessors.helpers.get=function(){return Template7Helpers},Object.defineProperties(Template7Class,staticAccessors),Template7.registerHelper=function(e,t){Template7Class.helpers[e]=t},Template7.unregisterHelper=function(e){Template7Class.helpers[e]=void 0,delete Template7Class.helpers[e]},Template7.registerPartial=function(e,t){Template7Class.partials[e]={template:t}},Template7.unregisterPartial=function(e){Template7Class.partials[e]&&(Template7Class.partials[e]=void 0,delete Template7Class.partials[e])},Template7.compile=function(e,t){return new Template7Class(e,t).compile()},Template7.options=Template7Class.options,Template7.helpers=Template7Class.helpers,Template7.partials=Template7Class.partials,Template7}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Template7=t()}(this,function(){"use strict";var t7ctx;t7ctx="undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0;var Template7Context=t7ctx,Template7Utils={quoteSingleRexExp:new RegExp("'","g"),quoteDoubleRexExp:new RegExp('"',"g"),isFunction:function(e){return"function"==typeof e},escape:function(e){return void 0===e&&(e=""),e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},helperToSlices:function(e){var t,i,r,n=Template7Utils.quoteDoubleRexExp,l=Template7Utils.quoteSingleRexExp,a=e.replace(/[{}#}]/g,"").trim().split(" "),s=[];for(i=0;i<a.length;i+=1){var o=a[i],p=void 0,c=void 0;if(0===i)s.push(o);else if(0===o.indexOf('"')||0===o.indexOf("'"))if(p=0===o.indexOf('"')?n:l,c=0===o.indexOf('"')?'"':"'",2===o.match(p).length)s.push(o);else{for(t=0,r=i+1;r<a.length;r+=1)if(o+=" "+a[r],0<=a[r].indexOf(c)){t=r,s.push(o);break}t&&(i=t)}else if(0<o.indexOf("=")){var u=o.split("="),f=u[0],d=u[1];if(p||(p=0===d.indexOf('"')?n:l,c=0===d.indexOf('"')?'"':"'"),2!==d.match(p).length){for(t=0,r=i+1;r<a.length;r+=1)if(d+=" "+a[r],0<=a[r].indexOf(c)){t=r;break}t&&(i=t)}var m=[f,d.replace(p,"")];s.push(m)}else s.push(o)}return s},stringToBlocks:function(e){var t,i,r=[];if(!e)return[];var n=e.split(/({{[^{^}]*}})/);for(t=0;t<n.length;t+=1){var l=n[t];if(""!==l)if(l.indexOf("{{")<0)r.push({type:"plain",content:l});else{if(0<=l.indexOf("{/"))continue;if((l=l.replace(/{{([#/])*([ ])*/,"{{$1").replace(/([ ])*}}/,"}}")).indexOf("{#")<0&&l.indexOf(" ")<0&&l.indexOf("else")<0){r.push({type:"variable",contextName:l.replace(/[{}]/g,"")});continue}var a=Template7Utils.helperToSlices(l),s=a[0],o=">"===s,p=[],c={};for(i=1;i<a.length;i+=1){var u=a[i];Array.isArray(u)?c[u[0]]="false"!==u[1]&&u[1]:p.push(u)}if(0<=l.indexOf("{#")){var f="",d="",m=0,h=void 0,g=!1,x=!1,v=0;for(i=t+1;i<n.length;i+=1)if(0<=n[i].indexOf("{{#")&&(v+=1),0<=n[i].indexOf("{{/")&&(v-=1),0<=n[i].indexOf("{{#"+s))f+=n[i],x&&(d+=n[i]),m+=1;else if(0<=n[i].indexOf("{{/"+s)){if(!(0<m)){h=i,g=!0;break}m-=1,f+=n[i],x&&(d+=n[i])}else 0<=n[i].indexOf("else")&&0===v?x=!0:(x||(f+=n[i]),x&&(d+=n[i]));g&&(h&&(t=h),"raw"===s?r.push({type:"plain",content:f}):r.push({type:"helper",helperName:s,contextName:p,content:f,inverseContent:d,hash:c}))}else 0<l.indexOf(" ")&&(o&&(s="_partial",p[0]&&(0===p[0].indexOf("[")?p[0]=p[0].replace(/[[\]]/g,""):p[0]='"'+p[0].replace(/"|'/g,"")+'"')),r.push({type:"helper",helperName:s,contextName:p,hash:c}))}}return r},parseJsVariable:function(e,r,n){return e.split(/([+ \-*/^()&=|<>!%:?])/g).reduce(function(e,t){if(!t)return e;if(t.indexOf(r)<0)return e.push(t),e;if(!n)return e.push(JSON.stringify("")),e;var i=n;return 0<=t.indexOf(r+".")&&t.split(r+".")[1].split(".").forEach(function(e){i=e in i?i[e]:void 0}),"string"==typeof i&&(i=JSON.stringify(i)),void 0===i&&(i="undefined"),e.push(i),e},[]).join("")},parseJsParents:function(e,n){return e.split(/([+ \-*^()&=|<>!%:?])/g).reduce(function(e,t){if(!t)return e;if(t.indexOf("../")<0)return e.push(t),e;if(!n||0===n.length)return e.push(JSON.stringify("")),e;var i=t.split("../").length-1,r=i>n.length?n[n.length-1]:n[i-1];return t.replace(/..\//g,"").split(".").forEach(function(e){r=void 0!==r[e]?r[e]:"undefined"}),!1===r||!0===r?e.push(JSON.stringify(r)):null===r||"undefined"===r?e.push(JSON.stringify("")):e.push(JSON.stringify(r)),e},[]).join("")},getCompileVar:function(e,t,i){void 0===i&&(i="data_1");var r,n,l=t,a=0;r=0===e.indexOf("../")?(a=e.split("../").length-1,l="ctx_"+(1<=(n=l.split("_")[1]-a)?n:1),e.split("../")[a].split(".")):0===e.indexOf("@global")?(l="Template7.global",e.split("@global.")[1].split(".")):0===e.indexOf("@root")?(l="root",e.split("@root.")[1].split(".")):e.split(".");for(var s=0;s<r.length;s+=1){var o=r[s];if(0===o.indexOf("@")){var p=i.split("_")[1];0<a&&(p=n),0<s?l+="[(data_"+p+" && data_"+p+"."+o.replace("@","")+")]":l="(data_"+p+" && data_"+p+"."+o.replace("@","")+")"}else(Number.isFinite?Number.isFinite(o):Template7Context.isFinite(o))?l+="["+o+"]":"this"===o||0<=o.indexOf("this.")||0<=o.indexOf("this[")||0<=o.indexOf("this(")?l=o.replace("this",t):l+="."+o}return l},getCompiledArguments:function(e,t,i){for(var r=[],n=0;n<e.length;n+=1)/^['"]/.test(e[n])?r.push(e[n]):/^(true|false|\d+)$/.test(e[n])?r.push(e[n]):r.push(Template7Utils.getCompileVar(e[n],t,i));return r.join(", ")}},Template7Helpers={_partial:function(e,t){var i=this,r=Template7Class.partials[e];return!r||r&&!r.template?"":(r.compiled||(r.compiled=new Template7Class(r.template).compile()),Object.keys(t.hash).forEach(function(e){i[e]=t.hash[e]}),r.compiled(i,t.data,t.root))},escape:function(e){if("string"!=typeof e)throw new Error('Template7: Passed context to "escape" helper should be a string');return Template7Utils.escape(e)},if:function(e,t){var i=e;return Template7Utils.isFunction(i)&&(i=i.call(this)),i?t.fn(this,t.data):t.inverse(this,t.data)},unless:function(e,t){var i=e;return Template7Utils.isFunction(i)&&(i=i.call(this)),i?t.inverse(this,t.data):t.fn(this,t.data)},each:function(e,t){var i=e,r="",n=0;if(Template7Utils.isFunction(i)&&(i=i.call(this)),Array.isArray(i)){for(t.hash.reverse&&(i=i.reverse()),n=0;n<i.length;n+=1)r+=t.fn(i[n],{first:0===n,last:n===i.length-1,index:n});t.hash.reverse&&(i=i.reverse())}else for(var l in i)n+=1,r+=t.fn(i[l],{key:l});return 0<n?r:t.inverse(this)},with:function(e,t){var i=e;return Template7Utils.isFunction(i)&&(i=e.call(this)),t.fn(i)},join:function(e,t){var i=e;return Template7Utils.isFunction(i)&&(i=i.call(this)),i.join(t.hash.delimiter||t.hash.delimeter)},js:function js(expression,options){var data=options.data,func,execute=expression;return"index first last key".split(" ").forEach(function(e){if(void 0!==data[e]){var t=new RegExp("this.@"+e,"g"),i=new RegExp("@"+e,"g");execute=execute.replace(t,JSON.stringify(data[e])).replace(i,JSON.stringify(data[e]))}}),options.root&&0<=execute.indexOf("@root")&&(execute=Template7Utils.parseJsVariable(execute,"@root",options.root)),0<=execute.indexOf("@global")&&(execute=Template7Utils.parseJsVariable(execute,"@global",Template7Context.Template7.global)),0<=execute.indexOf("../")&&(execute=Template7Utils.parseJsParents(execute,options.parents)),func=0<=execute.indexOf("return")?"(function(){"+execute+"})":"(function(){return ("+execute+")})",eval(func).call(this)},js_if:function js_if(expression,options){var data=options.data,func,execute=expression;"index first last key".split(" ").forEach(function(e){if(void 0!==data[e]){var t=new RegExp("this.@"+e,"g"),i=new RegExp("@"+e,"g");execute=execute.replace(t,JSON.stringify(data[e])).replace(i,JSON.stringify(data[e]))}}),options.root&&0<=execute.indexOf("@root")&&(execute=Template7Utils.parseJsVariable(execute,"@root",options.root)),0<=execute.indexOf("@global")&&(execute=Template7Utils.parseJsVariable(execute,"@global",Template7Context.Template7.global)),0<=execute.indexOf("../")&&(execute=Template7Utils.parseJsParents(execute,options.parents)),func=0<=execute.indexOf("return")?"(function(){"+execute+"})":"(function(){return ("+execute+")})";var condition=eval(func).call(this);return condition?options.fn(this,options.data):options.inverse(this,options.data)}};Template7Helpers.js_compare=Template7Helpers.js_if;var Template7Options={},Template7Partials={},Template7Class=function(e){this.template=e},staticAccessors={options:{configurable:!0},partials:{configurable:!0},helpers:{configurable:!0}};function Template7(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var i=e[0],r=e[1];if(2!==e.length)return new Template7Class(i);var n=new Template7Class(i),l=n.compile()(r);return n=null,l}return Template7Class.prototype.compile=function compile(template,depth){void 0===template&&(template=this.template),void 0===depth&&(depth=1);var t=this;if(t.compiled)return t.compiled;if("string"!=typeof template)throw new Error("Template7: Template must be a string");var stringToBlocks=Template7Utils.stringToBlocks,getCompileVar=Template7Utils.getCompileVar,getCompiledArguments=Template7Utils.getCompiledArguments,blocks=stringToBlocks(template),ctx="ctx_"+depth,data="data_"+depth;if(0===blocks.length)return function(){return""};function getCompileFn(e,i){return e.content?t.compile(e.content,i):function(){return""}}function getCompileInverse(e,i){return e.inverseContent?t.compile(e.inverseContent,i):function(){return""}}var resultString="",i;for(resultString+=1===depth?"(function ("+ctx+", "+data+", root) {\n":"(function ("+ctx+", "+data+") {\n",1===depth&&(resultString+="function isArray(arr){return Array.isArray(arr);}\n",resultString+="function isFunction(func){return (typeof func === 'function');}\n",resultString+='function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n',resultString+="root = root || ctx_1 || {};\n"),resultString+="var r = '';\n",i=0;i<blocks.length;i+=1){var block=blocks[i];if("plain"!==block.type){var variable=void 0,compiledArguments=void 0;if("variable"===block.type&&(variable=getCompileVar(block.contextName,ctx,data),resultString+="r += c("+variable+", "+ctx+");"),"helper"===block.type){var parents=void 0;if("ctx_1"!==ctx){for(var level=ctx.split("_")[1],parentsString="ctx_"+(level-1),j=level-2;1<=j;j-=1)parentsString+=", ctx_"+j;parents="["+parentsString+"]"}else parents="["+ctx+"]";var dynamicHelper=void 0;if(0===block.helperName.indexOf("[")&&(block.helperName=getCompileVar(block.helperName.replace(/[[\]]/g,""),ctx,data),dynamicHelper=!0),dynamicHelper||block.helperName in Template7Helpers)compiledArguments=getCompiledArguments(block.contextName,ctx,data),resultString+="r += (Template7Helpers"+(dynamicHelper?"["+block.helperName+"]":"."+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, parents: "+parents+"});";else{if(0<block.contextName.length)throw new Error('Template7: Missing helper: "'+block.helperName+'"');variable=getCompileVar(block.helperName,ctx,data),resultString+="if ("+variable+") {",resultString+="if (isArray("+variable+")) {",resultString+="r += (Template7Helpers.each).call("+ctx+", "+variable+", {hash:"+JSON.stringify(block.hash)+", data: "+data+" || {}, fn: "+getCompileFn(block,depth+1)+", inverse: "+getCompileInverse(block,depth+1)+", root: root, parents: "+parents+"});",resultString+="}else {",resultString+="r += (Template7Helpers.with).call("+ctx+", "+variable+", {hash:"+JSON.stringify(block.hash)+", data: "+data+" || {}, fn: "+getCompileFn(block,depth+1)+", inverse: "+getCompileInverse(block,depth+1)+", root: root, parents: "+parents+"});",resultString+="}}"}}}else resultString+="r +='"+block.content.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/'/g,"\\'")+"';"}return resultString+="\nreturn r;})",1===depth?(t.compiled=eval(resultString),t.compiled):resultString},staticAccessors.options.get=function(){return Template7Options},staticAccessors.partials.get=function(){return Template7Partials},staticAccessors.helpers.get=function(){return Template7Helpers},Object.defineProperties(Template7Class,staticAccessors),Template7.registerHelper=function(e,t){Template7Class.helpers[e]=t},Template7.unregisterHelper=function(e){Template7Class.helpers[e]=void 0,delete Template7Class.helpers[e]},Template7.registerPartial=function(e,t){Template7Class.partials[e]={template:t}},Template7.unregisterPartial=function(e){Template7Class.partials[e]&&(Template7Class.partials[e]=void 0,delete Template7Class.partials[e])},Template7.compile=function(e,t){return new Template7Class(e,t).compile()},Template7.options=Template7Class.options,Template7.helpers=Template7Class.helpers,Template7.partials=Template7Class.partials,Template7}); | ||
//# sourceMappingURL=template7.min.js.map |
138
gulpfile.js
@@ -9,6 +9,4 @@ const fs = require('fs'); | ||
const sourcemaps = require('gulp-sourcemaps'); | ||
const rollup = require('rollup-stream'); | ||
const rollup = require('rollup'); | ||
const buble = require('rollup-plugin-buble'); | ||
const source = require('vinyl-source-stream'); | ||
const buffer = require('vinyl-buffer'); | ||
const pkg = require('./package.json'); | ||
@@ -23,2 +21,9 @@ | ||
}; | ||
const date = { | ||
year: new Date().getFullYear(), | ||
month: ('January February March April May June July August September October November December').split(' ')[new Date().getMonth()], | ||
day: new Date().getDate(), | ||
}; | ||
const t7 = { | ||
@@ -29,96 +34,79 @@ filename: 'template7', | ||
'/**', | ||
' * Template7 <%= pkg.version %>', | ||
' * <%= pkg.description %>', | ||
` * Template7 ${pkg.version}`, | ||
` * ${pkg.description}`, | ||
' * ', | ||
' * <%= pkg.homepage %>', | ||
` * ${pkg.homepage}`, | ||
' * ', | ||
' * Copyright <%= date.year %>, <%= pkg.author %>', | ||
` * Copyright ${date.year}, ${pkg.author}`, | ||
' * The iDangero.us', | ||
' * http://www.idangero.us/', | ||
' * ', | ||
' * Licensed under <%= pkg.license %>', | ||
` * Licensed under ${pkg.license}`, | ||
' * ', | ||
' * Released on: <%= date.month %> <%= date.day %>, <%= date.year %>', | ||
` * Released on: ${date.month} ${date.day}, ${date.year}`, | ||
' */', | ||
''].join('\n'), | ||
date: { | ||
year: new Date().getFullYear(), | ||
month: ('January February March April May June July August September October November December').split(' ')[new Date().getMonth()], | ||
day: new Date().getDate(), | ||
}, | ||
}; | ||
// Build | ||
// Build | ||
gulp.task('build', (cb) => { | ||
fs.copyFileSync('./src/template7.d.ts', './build/template7.d.ts'); | ||
rollup({ | ||
rollup.rollup({ | ||
input: './src/template7.js', | ||
plugins: [buble()], | ||
format: 'umd', | ||
name: 'Template7', | ||
strict: true, | ||
sourcemap: true, | ||
}) | ||
.pipe(source('template7.js', './src')) | ||
.pipe(buffer()) | ||
.pipe(sourcemaps.init({ loadMaps: true })) | ||
.pipe(sourcemaps.write('./')) | ||
.pipe(gulp.dest('./build/')) | ||
.on('end', () => { | ||
cb(); | ||
}).then((bundle) => { // eslint-disable-line | ||
return bundle.write({ | ||
strict: true, | ||
file: './build/template7.js', | ||
format: 'umd', | ||
name: 'Template7', | ||
sourcemap: true, | ||
sourcemapFile: './build/template7.js.map', | ||
}); | ||
}).then(() => { | ||
cb(); | ||
}); | ||
}); | ||
function umd(cb) { | ||
rollup({ | ||
rollup.rollup({ | ||
input: './src/template7.js', | ||
plugins: [buble()], | ||
format: 'umd', | ||
name: 'Template7', | ||
strict: true, | ||
sourcemap: true, | ||
}) | ||
.pipe(source('template7.js', './src')) | ||
.pipe(buffer()) | ||
.pipe(sourcemaps.init({ loadMaps: true })) | ||
.pipe(header(t7.banner, { | ||
pkg: t7.pkg, | ||
date: t7.date, | ||
})) | ||
.pipe(sourcemaps.write('./')) | ||
.pipe(gulp.dest('./dist/')) | ||
.on('end', () => { | ||
gulp.src('./dist/template7.js') | ||
.pipe(sourcemaps.init()) | ||
.pipe(uglify()) | ||
.pipe(header(t7.banner, { | ||
pkg: t7.pkg, | ||
date: t7.date, | ||
})) | ||
.pipe(rename('template7.min.js')) | ||
.pipe(sourcemaps.write('./')) | ||
.pipe(gulp.dest('./dist/')) | ||
.on('end', () => { | ||
if (cb) cb(); | ||
}); | ||
}).then((bundle) => { // eslint-disable-line | ||
return bundle.write({ | ||
strict: true, | ||
file: './dist/template7.js', | ||
format: 'umd', | ||
name: 'Template7', | ||
sourcemap: true, | ||
sourcemapFile: './dist/template7.js.map', | ||
banner: t7.banner, | ||
}); | ||
}).then(() => { | ||
gulp.src('./dist/template7.js') | ||
.pipe(sourcemaps.init()) | ||
.pipe(uglify()) | ||
.pipe(header(t7.banner)) | ||
.pipe(rename('template7.min.js')) | ||
.pipe(sourcemaps.write('./')) | ||
.pipe(gulp.dest('./dist/')) | ||
.on('end', () => { | ||
if (cb) cb(); | ||
}); | ||
}); | ||
} | ||
function es(cb) { | ||
rollup({ | ||
rollup.rollup({ | ||
input: './src/template7.js', | ||
format: 'es', | ||
name: 'Template7', | ||
strict: true, | ||
}) | ||
.pipe(source('template7.js', './src')) | ||
.pipe(buffer()) | ||
.pipe(header(t7.banner, { | ||
pkg: t7.pkg, | ||
date: t7.date, | ||
})) | ||
.pipe(rename('template7.esm.js')) | ||
.pipe(gulp.dest('./dist/')) | ||
.on('end', () => { | ||
if (cb) cb(); | ||
}).then((bundle) => { // eslint-disable-line | ||
return bundle.write({ | ||
strict: true, | ||
file: './dist/template7.esm.js', | ||
format: 'es', | ||
name: 'Template7', | ||
banner: t7.banner, | ||
}); | ||
}).then(() => { | ||
cb(); | ||
}); | ||
} | ||
@@ -140,3 +128,3 @@ // Dist | ||
gulp.task('watch', () => { | ||
gulp.watch('./src/*.js', ['build']); | ||
gulp.watch('./src/*.js', gulp.series(['build'])); | ||
}); | ||
@@ -152,4 +140,4 @@ | ||
gulp.task('server', ['watch', 'connect', 'open']); | ||
gulp.task('server', gulp.parallel(['watch', 'connect', 'open'])); | ||
gulp.task('default', ['server']); | ||
gulp.task('default', gulp.series(['server'])); |
{ | ||
"name": "template7", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Mobile-first HTML template engine", | ||
@@ -47,14 +47,12 @@ "main": "dist/template7.js", | ||
"eslint-plugin-react": "^7.4.0", | ||
"gulp": "^3.9.1", | ||
"gulp-connect": "^5.0.0", | ||
"gulp-header": "^1.8.9", | ||
"gulp-open": "^2.0.0", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-sourcemaps": "^2.6.1", | ||
"gulp-uglify": "^3.0.0", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-stream": "^1.24.1", | ||
"vinyl-buffer": "^1.0.1", | ||
"vinyl-source-stream": "^2.0.0" | ||
"gulp": "^4.0.0", | ||
"gulp-connect": "^5.7.0", | ||
"gulp-header": "^2.0.7", | ||
"gulp-open": "^3.0.1", | ||
"gulp-rename": "^1.4.0", | ||
"gulp-sourcemaps": "^2.6.4", | ||
"gulp-uglify": "^3.0.1", | ||
"rollup": "^1.1.2", | ||
"rollup-plugin-buble": "^0.19.6" | ||
} | ||
} |
@@ -9,10 +9,9 @@ import Template7Context from './context'; | ||
}, | ||
escape(string) { | ||
return (typeof Template7Context !== 'undefined' && Template7Context.escape) ? | ||
Template7Context.escape(string) : | ||
string | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
escape(string = '') { | ||
return string | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
}, | ||
@@ -200,5 +199,15 @@ helperToSlices(string) { | ||
parseJsVariable(expression, replace, object) { | ||
return expression.split(/([+ \-*/^])/g).map((part) => { | ||
if (part.indexOf(replace) < 0) return part; | ||
if (!object) return JSON.stringify(''); | ||
return expression.split(/([+ \-*/^()&=|<>!%:?])/g).reduce((arr, part) => { | ||
if (!part) { | ||
return arr; | ||
} | ||
if (part.indexOf(replace) < 0) { | ||
arr.push(part); | ||
return arr; | ||
} | ||
if (!object) { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
let variable = object; | ||
@@ -215,9 +224,23 @@ if (part.indexOf(`${replace}.`) >= 0) { | ||
if (variable === undefined) variable = 'undefined'; | ||
return variable; | ||
}).join(''); | ||
arr.push(variable); | ||
return arr; | ||
}, []).join(''); | ||
}, | ||
parseJsParents(expression, parents) { | ||
return expression.split(/([+ \-*^])/g).map((part) => { | ||
if (part.indexOf('../') < 0) return part; | ||
if (!parents || parents.length === 0) return JSON.stringify(''); | ||
return expression.split(/([+ \-*^()&=|<>!%:?])/g).reduce((arr, part) => { | ||
if (!part) { | ||
return arr; | ||
} | ||
if (part.indexOf('../') < 0) { | ||
arr.push(part); | ||
return arr; | ||
} | ||
if (!parents || parents.length === 0) { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
const levelsUp = part.split('../').length - 1; | ||
@@ -229,7 +252,16 @@ const parentData = levelsUp > parents.length ? parents[parents.length - 1] : parents[levelsUp - 1]; | ||
parentPart.split('.').forEach((partName) => { | ||
if (variable[partName]) variable = variable[partName]; | ||
if (typeof variable[partName] !== 'undefined') variable = variable[partName]; | ||
else variable = 'undefined'; | ||
}); | ||
return JSON.stringify(variable); | ||
}).join(''); | ||
if (variable === false || variable === true) { | ||
arr.push(JSON.stringify(variable)); | ||
return arr; | ||
} | ||
if (variable === null || variable === 'undefined') { | ||
arr.push(JSON.stringify('')); | ||
return arr; | ||
} | ||
arr.push(JSON.stringify(variable)); | ||
return arr; | ||
}, []).join(''); | ||
}, | ||
@@ -236,0 +268,0 @@ getCompileVar(name, ctx, data = 'data_1') { |
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
176007
15
2114