Socket
Socket
Sign inDemoInstall

template7

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

template7 - npm Package Compare versions

Comparing version 1.1.4 to 1.2.0

.editorconfig

23

bower.json

@@ -8,15 +8,15 @@ {

"description": "Mobile-first JavaScript template engine",
"version": "1.1.2",
"version": "1.2.0",
"author": "Vladimir Kharlampidi",
"homepage": "http://www.idangero.us/template7/",
"keywords": [
"mobile",
"template",
"javascript",
"ios7",
"ios8",
"ios 8",
"iphone",
"ipad",
"phonegap",
"mobile",
"template",
"javascript",
"ios7",
"ios8",
"ios 8",
"iphone",
"ipad",
"phonegap",
"framework7",

@@ -31,4 +31,3 @@ "handlebars",

"main": [
"dist/template7.js",
"dist/template7.css"
"dist/template7.js"
],

@@ -35,0 +34,0 @@ "license": ["MIT"],

# Change Log
## Template7 v1.2.0 - Released on April 15, 2017
* Added support for node.js and commonjs
## Template7 v1.1.4 - Released on December 12, 2016

@@ -21,3 +24,3 @@ * Fixed issue with quotes being added to helpers hash content

* `>` helper to include partials like `{{> list}}`
* New `escape` helper for escaping strings
* New `escape` helper for escaping strings

@@ -40,2 +43,2 @@ ## Template7 v1.0.5 - Released on March 28, 2015

## Template7 v1.0.0 - Released on September 12, 2014
## Template7 v1.0.0 - Released on September 12, 2014
/**
* Template7 1.1.2
* Template7 1.2.0
* Mobile-first JavaScript template engine

@@ -7,3 +7,3 @@ *

*
* Copyright 2016, Vladimir Kharlampidi
* Copyright 2017, Vladimir Kharlampidi
* The iDangero.us

@@ -14,478 +14,469 @@ * http://www.idangero.us/

*
* Released on: December 12, 2016
* Released on: April 15, 2017
*/
window.Template7 = (function () {
'use strict';
function isArray(arr) {
return Object.prototype.toString.apply(arr) === '[object Array]';
(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';
var template7Context;
if (typeof window !== 'undefined') {
template7Context = window;
} else if (typeof global !== 'undefined') {
template7Context = global;
} else {
template7Context = undefined;
}
function isArray(arr) {
return Array.isArray ? Array.isArray(arr) : Object.prototype.toString.apply(arr) === '[object Array]';
}
function isFunction(func) {
return typeof func === 'function';
}
function escape(string) {
return (typeof template7Context !== 'undefined' && template7Context.escape ? template7Context.escape(string) : string)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
var quoteSingleRexExp = new RegExp('\'', 'g');
var quoteDoubleRexExp = new RegExp('"', 'g');
function helperToSlices(string) {
var helperParts = string.replace(/[{}#}]/g, '').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; }
}
} 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; }
}
var hash = [hashName, hashContent.replace(blockQuoteRegExp, '')];
slices.push(hash);
} else {
// Plain variable
slices.push(part);
}
function isObject(obj) {
return obj instanceof Object;
}
return slices;
}
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;
}
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 = 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 (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;
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 {
if (!foundElse) { helperContent += stringBlocks[j]; }
if (foundElse) { elseContent += stringBlocks[j]; }
}
}
if (foundClosed) {
if (shiftIndex) { i = shiftIndex; }
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]) { helperContext[0] = "\"" + (helperContext[0].replace(/"|'/g, '')) + "\""; }
}
blocks.push({
type: 'helper',
helperName: helperName,
contextName: helperContext,
hash: helperHash,
});
}
}
function isFunction(func) {
return typeof func === 'function';
}
return blocks;
}
var Template7 = function Template7(template) {
var t = this;
t.template = template;
function getCompileVar(name, ctx) {
var variable = ctx;
var parts;
var levelsUp = 0;
if (name.indexOf('../') === 0) {
var newDepth = variable.split('_')[1] - levelsUp;
levelsUp = name.split('../').length - 1;
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('.');
}
function _escape(string) {
return typeof window !== 'undefined' && window.escape ? window.escape(string) : string
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
var cache = {};
var quoteSingleRexExp = new RegExp('\'', 'g');
var quoteDoubleRexExp = new RegExp('"', 'g');
function helperToSlices(string) {
var helperParts = string.replace(/[{}#}]/g, '').split(' ');
var slices = [];
var shiftIndex, i, j;
for (i = 0; i < helperParts.length; i++) {
var part = helperParts[i];
var blockQuoteRegExp, openingQuote;
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++) {
part += ' ' + helperParts[j];
if (helperParts[j].indexOf(openingQuote) >= 0) {
shiftIndex = j;
slices.push(part);
break;
}
}
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++) {
hashContent += ' ' + helperParts[j];
if (helperParts[j].indexOf(openingQuote) >= 0) {
shiftIndex = j;
break;
}
}
if (shiftIndex) i = shiftIndex;
}
var hash = [hashName, hashContent.replace(blockQuoteRegExp,'')];
slices.push(hash);
}
else {
// Plain variable
slices.push(part);
}
}
}
for (var i = 0; i < parts.length; i += 1) {
var part = parts[i];
if (part.indexOf('@') === 0) {
if (i > 0) {
variable += "[(data && data." + (part.replace('@', '')) + ")]";
} else {
variable = "(data && data." + (name.replace('@', '')) + ")";
}
return slices;
} else if (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;
}
}
function stringToBlocks(string) {
var blocks = [], i, j, k;
if (!string) return [];
var _blocks = string.split(/({{[^{^}]*}})/);
for (i = 0; i < _blocks.length; i++) {
var block = _blocks[i];
if (block === '') continue;
if (block.indexOf('{{') < 0) {
blocks.push({
type: 'plain',
content: block
});
}
else {
if (block.indexOf('{/') >= 0) {
continue;
}
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 = helperToSlices(block);
var helperName = helperSlices[0];
var isPartial = helperName === '>';
var helperContext = [];
var helperHash = {};
for (j = 1; j < helperSlices.length; j++) {
var slice = helperSlices[j];
if (isArray(slice)) {
// Hash
helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1];
}
else {
helperContext.push(slice);
}
}
if (block.indexOf('{#') >= 0) {
// Condition/Helper
var helperStartIndex = i;
var helperContent = '';
var elseContent = '';
var toSkip = 0;
var shiftIndex;
var foundClosed = false, foundElse = false, foundClosedElse = false, depth = 0;
for (j = i + 1; j < _blocks.length; j++) {
if (_blocks[j].indexOf('{{#') >= 0) {
depth ++;
}
if (_blocks[j].indexOf('{{/') >= 0) {
depth --;
}
if (_blocks[j].indexOf('{{#' + helperName) >= 0) {
helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
toSkip ++;
}
else if (_blocks[j].indexOf('{{/' + helperName) >= 0) {
if (toSkip > 0) {
toSkip--;
helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
}
else {
shiftIndex = j;
foundClosed = true;
break;
}
}
else if (_blocks[j].indexOf('else') >= 0 && depth === 0) {
foundElse = true;
}
else {
if (!foundElse) helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
}
return variable;
}
function getCompiledArguments(contextArray, ctx) {
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(getCompileVar(contextArray[i], ctx));
}
}
}
if (foundClosed) {
if (shiftIndex) i = shiftIndex;
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]) helperContext[0] = '"' + helperContext[0].replace(/"|'/g, '') + '"';
}
blocks.push({
type: 'helper',
helperName: helperName,
contextName: helperContext,
hash: helperHash
});
}
}
}
return blocks;
return arr.join(', ');
}
function compile(template, depth) {
if ( template === void 0 ) template = t.template;
if ( depth === void 0 ) depth = 1;
if (typeof template !== 'string') {
throw new Error('Template7: Template must be a string');
}
var Template7 = function (template, options) {
var t = this;
t.template = template;
var blocks = stringToBlocks(template);
var ctx = "ctx_" + depth;
if (blocks.length === 0) {
return function empty() { return ''; };
}
function getCompileFn(block, depth) {
if (block.content) return compile(block.content, depth);
else return function () {return ''; };
}
function getCompileInverse(block, depth) {
if (block.inverseContent) return compile(block.inverseContent, depth);
else return function () {return ''; };
}
function getCompileVar(name, ctx) {
var variable, parts, levelsUp = 0, initialCtx = ctx;
if (name.indexOf('../') === 0) {
levelsUp = name.split('../').length - 1;
var newDepth = ctx.split('_')[1] - levelsUp;
ctx = 'ctx_' + (newDepth >= 1 ? newDepth : 1);
parts = name.split('../')[levelsUp].split('.');
}
else if (name.indexOf('@global') === 0) {
ctx = 'Template7.global';
parts = name.split('@global.')[1].split('.');
}
else if (name.indexOf('@root') === 0) {
ctx = 'root';
parts = name.split('@root.')[1].split('.');
}
else {
parts = name.split('.');
}
variable = ctx;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
if (part.indexOf('@') === 0) {
if (i > 0) {
variable += '[(data && data.' + part.replace('@', '') + ')]';
}
else {
variable = '(data && data.' + name.replace('@', '') + ')';
}
}
else {
if (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;
}
}
}
}
function getCompileFn(block, newDepth) {
if (block.content) { return compile(block.content, newDepth); }
return function empty() { return ''; };
}
function getCompileInverse(block, newDepth) {
if (block.inverseContent) { return compile(block.inverseContent, newDepth); }
return function empty() { return ''; };
}
return variable;
}
function getCompiledArguments(contextArray, ctx) {
var arr = [];
for (var i = 0; i < contextArray.length; i++) {
if (/^['"]/.test(contextArray[i])) arr.push(contextArray[i]);
else if (/^(true|false|\d+)$/.test(contextArray[i])) arr.push(contextArray[i]);
else {
arr.push(getCompileVar(contextArray[i], ctx));
}
}
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 Object.prototype.toString.apply(arr) === \'[object Array]\';}\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') {
resultString += "r +='" + ((block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'')) + "';";
continue;
}
var variable = (void 0);
var compiledArguments = (void 0);
// Variable block
if (block.type === 'variable') {
variable = getCompileVar(block.contextName, ctx);
resultString += "r += c(" + variable + ", " + ctx + ");";
}
// Helpers block
if (block.type === 'helper') {
if (block.helperName in t.helpers) {
compiledArguments = getCompiledArguments(block.contextName, ctx);
return arr.join(', ');
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});";
} else if (block.contextName.length > 0) {
throw new Error(("Template7: Missing helper: \"" + (block.helperName) + "\""));
} else {
variable = getCompileVar(block.helperName, ctx);
resultString += "if (" + variable + ") {";
resultString += "if (isArray(" + variable + ")) {";
resultString += "r += (Template7.helpers.each).call(" + ctx + ", " + variable + ", {hash:" + (JSON.stringify(block.hash)) + ", data: data || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root});";
resultString += '}else {';
resultString += "r += (Template7.helpers.with).call(" + ctx + ", " + variable + ", {hash:" + (JSON.stringify(block.hash)) + ", data: data || {}, fn: " + (getCompileFn(block, depth + 1)) + ", inverse: " + (getCompileInverse(block, depth + 1)) + ", root: root});";
resultString += '}}';
}
function compile(template, depth) {
depth = depth || 1;
template = template || t.template;
if (typeof template !== 'string') {
throw new Error('Template7: Template must be a string');
}
var blocks = stringToBlocks(template);
if (blocks.length === 0) {
return function () { return ''; };
}
var ctx = 'ctx_' + depth;
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 Object.prototype.toString.apply(arr) === \'[object Array]\';}\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, j, context;
for (i = 0; i < blocks.length; i++) {
var block = blocks[i];
// Plain block
if (block.type === 'plain') {
resultString += 'r +=\'' + (block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'') + '\';';
continue;
}
var variable, compiledArguments;
// Variable block
if (block.type === 'variable') {
variable = getCompileVar(block.contextName, ctx);
resultString += 'r += c(' + variable + ', ' + ctx + ');';
}
// Helpers block
if (block.type === 'helper') {
if (block.helperName in t.helpers) {
compiledArguments = getCompiledArguments(block.contextName, ctx);
}
}
resultString += '\nreturn r;})';
return eval.call(template7Context, resultString);
}
t.compile = function _compile(template) {
if (!t.compiled) {
t.compiled = compile(template);
}
return t.compiled;
};
};
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});';
Template7.prototype = {
options: {},
partials: {},
helpers: {
_partial: function _partial(partialName, options) {
var p = Template7.prototype.partials[partialName];
if (!p || (p && !p.template)) { return ''; }
if (!p.compiled) {
p.compiled = new Template7(p.template).compile();
}
var ctx = this;
for (var hashName in options.hash) {
ctx[hashName] = options.hash[hashName];
}
return p.compiled(ctx, options.data, options.root);
},
escape: function escape$1(context, options) {
if (typeof context !== 'string') {
throw new Error('Template7: Passed context to "escape" helper should be a string');
}
return escape(context);
},
if: function if$1(context, options) {
var ctx = context;
if (isFunction(ctx)) { ctx = ctx.call(this); }
if (ctx) {
return options.fn(this, options.data);
}
}
else {
if (block.contextName.length > 0) {
throw new Error('Template7: Missing helper: "' + block.helperName + '"');
}
else {
variable = getCompileVar(block.helperName, ctx);
resultString += 'if (' + variable + ') {';
resultString += 'if (isArray(' + variable + ')) {';
resultString += 'r += (Template7.helpers.each).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: root});';
resultString += '}else {';
resultString += 'r += (Template7.helpers.with).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: root});';
resultString += '}}';
}
}
}
}
resultString += '\nreturn r;})';
return eval.call(window, resultString);
return options.inverse(this, options.data);
},
unless: function unless(context, options) {
var ctx = context;
if (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 (isFunction(ctx)) { ctx = ctx.call(this); }
if (isArray(ctx)) {
if (options.hash.reverse) {
ctx = ctx.reverse();
}
t.compile = function (template) {
if (!t.compiled) {
t.compiled = compile(template);
}
return t.compiled;
};
};
Template7.prototype = {
options: {},
partials: {},
helpers: {
'_partial' : function (partialName, options) {
var p = Template7.prototype.partials[partialName];
if (!p || (p && !p.template)) return '';
if (!p.compiled) {
p.compiled = new Template7(p.template).compile();
}
var ctx = this;
for (var hashName in options.hash) {
ctx[hashName] = options.hash[hashName];
}
return p.compiled(ctx, options.data, options.root);
},
'escape': function (context, options) {
if (typeof context !== 'string') {
throw new Error('Template7: Passed context to "escape" helper should be a string');
}
return _escape(context);
},
'if': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
if (context) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
},
'unless': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
if (!context) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
},
'each': function (context, options) {
var ret = '', i = 0;
if (isFunction(context)) { context = context.call(this); }
if (isArray(context)) {
if (options.hash.reverse) {
context = context.reverse();
}
for (i = 0; i < context.length; i++) {
ret += options.fn(context[i], {first: i === 0, last: i === context.length - 1, index: i});
}
if (options.hash.reverse) {
context = context.reverse();
}
}
else {
for (var key in context) {
i++;
ret += options.fn(context[key], {key: key});
}
}
if (i > 0) return ret;
else return options.inverse(this);
},
'with': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
return options.fn(context);
},
'join': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
return context.join(options.hash.delimiter || options.hash.delimeter);
},
'js': function (expression, options) {
var func;
if (expression.indexOf('return')>=0) {
func = '(function(){'+expression+'})';
}
else {
func = '(function(){return ('+expression+')})';
}
return eval.call(this, func).call(this);
},
'js_compare': function (expression, options) {
var func;
if (expression.indexOf('return')>=0) {
func = '(function(){'+expression+'})';
}
else {
func = '(function(){return ('+expression+')})';
}
var condition = eval.call(this, func).call(this);
if (condition) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
}
for (i = 0; i < ctx.length; i += 1) {
ret += options.fn(ctx[i], { first: i === 0, last: i === ctx.length - 1, index: i });
}
};
var t7 = function (template, data) {
if (arguments.length === 2) {
var instance = new Template7(template);
var rendered = instance.compile()(data);
instance = null;
return (rendered);
if (options.hash.reverse) {
ctx = ctx.reverse();
}
else return new Template7(template);
};
t7.registerHelper = function (name, fn) {
Template7.prototype.helpers[name] = fn;
};
t7.unregisterHelper = function (name) {
Template7.prototype.helpers[name] = undefined;
delete Template7.prototype.helpers[name];
};
t7.registerPartial = function (name, template) {
Template7.prototype.partials[name] = {template: template};
};
t7.unregisterPartial = function (name, template) {
if (Template7.prototype.partials[name]) {
Template7.prototype.partials[name] = undefined;
delete Template7.prototype.partials[name];
} else {
for (var key in ctx) {
i += 1;
ret += options.fn(ctx[key], { key: key });
}
};
t7.compile = function (template, options) {
var instance = new Template7(template, options);
return instance.compile();
};
}
if (i > 0) { return ret; }
return options.inverse(this);
},
with: function with$1(context, options) {
var ctx = context;
if (isFunction(ctx)) { ctx = context.call(this); }
return options.fn(ctx);
},
join: function join(context, options) {
var ctx = context;
if (isFunction(ctx)) { ctx = ctx.call(this); }
return ctx.join(options.hash.delimiter || options.hash.delimeter);
},
js: function js(expression, options) {
var func;
if (expression.indexOf('return') >= 0) {
func = "(function(){" + expression + "})";
} else {
func = "(function(){return (" + expression + ")})";
}
return eval.call(this, func).call(this);
},
js_compare: function js_compare(expression, options) {
var func;
if (expression.indexOf('return') >= 0) {
func = "(function(){" + expression + "})";
} else {
func = "(function(){return (" + expression + ")})";
}
var condition = eval.call(this, func).call(this);
if (condition) {
return options.fn(this, options.data);
}
t7.options = Template7.prototype.options;
t7.helpers = Template7.prototype.helpers;
t7.partials = Template7.prototype.partials;
return t7;
})();
return options.inverse(this, options.data);
},
},
};
function t7(template, data) {
if (arguments.length === 2) {
var instance = new Template7(template);
var rendered = instance.compile()(data);
instance = null;
return (rendered);
}
return new Template7(template);
}
t7.registerHelper = function registerHelper(name, fn) {
Template7.prototype.helpers[name] = fn;
};
t7.unregisterHelper = function unregisterHelper(name) {
Template7.prototype.helpers[name] = undefined;
delete Template7.prototype.helpers[name];
};
t7.registerPartial = function registerPartial(name, template) {
Template7.prototype.partials[name] = { template: template };
};
t7.unregisterPartial = function unregisterPartial(name) {
if (Template7.prototype.partials[name]) {
Template7.prototype.partials[name] = undefined;
delete Template7.prototype.partials[name];
}
};
t7.compile = function compile(template, options) {
var instance = new Template7(template, options);
return instance.compile();
};
t7.options = Template7.prototype.options;
t7.helpers = Template7.prototype.helpers;
t7.partials = Template7.prototype.partials;
return t7;
})));
//# sourceMappingURL=template7.js.map
/**
* Template7 1.1.2
* Template7 1.2.0
* Mobile-first JavaScript template engine

@@ -7,3 +7,3 @@ *

*
* Copyright 2016, Vladimir Kharlampidi
* Copyright 2017, Vladimir Kharlampidi
* The iDangero.us

@@ -14,5 +14,5 @@ * http://www.idangero.us/

*
* Released on: December 12, 2016
* Released on: April 15, 2017
*/
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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}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(p||(p=0===h.indexOf('"')?l:a,s=0===h.indexOf('"')?'"':"'"),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="",x=0,m=!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]),x++;else if(l[i].indexOf("{{/"+s)>=0){if(!(x>0)){d=i,m=!0;break}x--,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]));m&&(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}();
!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 e(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.apply(e)}function t(e){return"function"==typeof e}function r(e){return(void 0!==o&&o.escape?o.escape(e):e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function n(e){var t,r,n,i=e.replace(/[{}#}]/g,"").split(" "),a=[];for(r=0;r<i.length;r+=1){var o=i[r],s=void 0,f=void 0;if(0===r)a.push(o);else if(0===o.indexOf('"')||0===o.indexOf("'"))if(s=0===o.indexOf('"')?p:l,f=0===o.indexOf('"')?'"':"'",2===o.match(s).length)a.push(o);else{for(t=0,n=r+1;n<i.length;n+=1)if(o+=" "+i[n],i[n].indexOf(f)>=0){t=n,a.push(o);break}t&&(r=t)}else if(o.indexOf("=")>0){var c=o.split("="),u=c[0],h=c[1];if(s||(s=0===h.indexOf('"')?p:l,f=0===h.indexOf('"')?'"':"'"),2!==h.match(s).length){for(t=0,n=r+1;n<i.length;n+=1)if(h+=" "+i[n],i[n].indexOf(f)>=0){t=n;break}t&&(r=t)}var d=[u,h.replace(s,"")];a.push(d)}else a.push(o)}return a}function i(t){var r,i,a=[];if(!t)return[];var o=t.split(/({{[^{^}]*}})/);for(r=0;r<o.length;r+=1){var l=o[r];if(""!==l)if(l.indexOf("{{")<0)a.push({type:"plain",content:l});else{if(l.indexOf("{/")>=0)continue;if(l.indexOf("{#")<0&&l.indexOf(" ")<0&&l.indexOf("else")<0){a.push({type:"variable",contextName:l.replace(/[{}]/g,"")});continue}var p=n(l),s=p[0],f=">"===s,c=[],u={};for(i=1;i<p.length;i+=1){var h=p[i];e(h)?u[h[0]]="false"!==h[1]&&h[1]:c.push(h)}if(l.indexOf("{#")>=0){var d="",v="",g=0,m=void 0,x=!1,y=!1,O=0;for(i=r+1;i<o.length;i+=1)if(o[i].indexOf("{{#")>=0&&(O+=1),o[i].indexOf("{{/")>=0&&(O-=1),o[i].indexOf("{{#"+s)>=0)d+=o[i],y&&(v+=o[i]),g+=1;else if(o[i].indexOf("{{/"+s)>=0){if(!(g>0)){m=i,x=!0;break}g-=1,d+=o[i],y&&(v+=o[i])}else o[i].indexOf("else")>=0&&0===O?y=!0:(y||(d+=o[i]),y&&(v+=o[i]));x&&(m&&(r=m),a.push({type:"helper",helperName:s,contextName:c,content:d,inverseContent:v,hash:u}))}else l.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}function a(e,t){if(2===arguments.length){var r=new s(e),n=r.compile()(t);return r=null,n}return new s(e)}var o;o="undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0;var l=new RegExp("'","g"),p=new RegExp('"',"g"),s=function(e){function t(e,t){var r,n=t,i=0;if(0===e.indexOf("../")){var a=n.split("_")[1]-i;i=e.split("../").length-1,n="ctx_"+(a>=1?a:1),r=e.split("../")[i].split(".")}else 0===e.indexOf("@global")?(n="Template7.global",r=e.split("@global.")[1].split(".")):0===e.indexOf("@root")?(n="root",r=e.split("@root.")[1].split(".")):r=e.split(".");for(var o=0;o<r.length;o+=1){var l=r[o];0===l.indexOf("@")?o>0?n+="[(data && data."+l.replace("@","")+")]":n="(data && data."+e.replace("@","")+")":isFinite(l)?n+="["+l+"]":"this"===l||l.indexOf("this.")>=0||l.indexOf("this[")>=0||l.indexOf("this(")>=0?n=l.replace("this",t):n+="."+l}return n}function r(e,r){for(var n=[],i=0;i<e.length;i+=1)/^['"]/.test(e[i])?n.push(e[i]):/^(true|false|\d+)$/.test(e[i])?n.push(e[i]):n.push(t(e[i],r));return n.join(", ")}function n(e,l){function p(e,t){return e.content?n(e.content,t):function(){return""}}function s(e,t){return e.inverseContent?n(e.inverseContent,t):function(){return""}}if(void 0===e&&(e=a.template),void 0===l&&(l=1),"string"!=typeof e)throw new Error("Template7: Template must be a string");var f=i(e),c="ctx_"+l;if(0===f.length)return function(){return""};var u="";u+=1===l?"(function ("+c+", data, root) {\n":"(function ("+c+", data) {\n",1===l&&(u+="function isArray(arr){return Object.prototype.toString.apply(arr) === '[object Array]';}\n",u+="function isFunction(func){return (typeof func === 'function');}\n",u+='function c(val, ctx) {if (typeof val !== "undefined" && val !== null) {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n',u+="root = root || ctx_1 || {};\n"),u+="var r = '';\n";var h;for(h=0;h<f.length;h+=1){var d=f[h];if("plain"!==d.type){var v=void 0,g=void 0;if("variable"===d.type&&(v=t(d.contextName,c),u+="r += c("+v+", "+c+");"),"helper"===d.type)if(d.helperName in a.helpers)g=r(d.contextName,c),u+="r += (Template7.helpers."+d.helperName+").call("+c+", "+(g&&g+", ")+"{hash:"+JSON.stringify(d.hash)+", data: data || {}, fn: "+p(d,l+1)+", inverse: "+s(d,l+1)+", root: root});";else{if(d.contextName.length>0)throw new Error('Template7: Missing helper: "'+d.helperName+'"');v=t(d.helperName,c),u+="if ("+v+") {",u+="if (isArray("+v+")) {",u+="r += (Template7.helpers.each).call("+c+", "+v+", {hash:"+JSON.stringify(d.hash)+", data: data || {}, fn: "+p(d,l+1)+", inverse: "+s(d,l+1)+", root: root});",u+="}else {",u+="r += (Template7.helpers.with).call("+c+", "+v+", {hash:"+JSON.stringify(d.hash)+", data: data || {}, fn: "+p(d,l+1)+", inverse: "+s(d,l+1)+", root: root});",u+="}}"}}else u+="r +='"+d.content.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/'/g,"\\'")+"';"}return u+="\nreturn r;})",eval.call(o,u)}var a=this;a.template=e,a.compile=function(e){return a.compiled||(a.compiled=n(e)),a.compiled}};return s.prototype={options:{},partials:{},helpers:{_partial:function(e,t){var r=s.prototype.partials[e];if(!r||r&&!r.template)return"";r.compiled||(r.compiled=new s(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){var n=e;return t(n)&&(n=n.call(this)),n?r.fn(this,r.data):r.inverse(this,r.data)},unless:function(e,r){var n=e;return t(n)&&(n=n.call(this)),n?r.inverse(this,r.data):r.fn(this,r.data)},each:function(r,n){var i=r,a="",o=0;if(t(i)&&(i=i.call(this)),e(i)){for(n.hash.reverse&&(i=i.reverse()),o=0;o<i.length;o+=1)a+=n.fn(i[o],{first:0===o,last:o===i.length-1,index:o});n.hash.reverse&&(i=i.reverse())}else for(var l in i)o+=1,a+=n.fn(i[l],{key:l});return o>0?a:n.inverse(this)},with:function(e,r){var n=e;return t(n)&&(n=e.call(this)),r.fn(n)},join:function(e,r){var n=e;return t(n)&&(n=n.call(this)),n.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;return r=e.indexOf("return")>=0?"(function(){"+e+"})":"(function(){return ("+e+")})",eval.call(this,r).call(this)?t.fn(this,t.data):t.inverse(this,t.data)}}},a.registerHelper=function(e,t){s.prototype.helpers[e]=t},a.unregisterHelper=function(e){s.prototype.helpers[e]=void 0,delete s.prototype.helpers[e]},a.registerPartial=function(e,t){s.prototype.partials[e]={template:t}},a.unregisterPartial=function(e){s.prototype.partials[e]&&(s.prototype.partials[e]=void 0,delete s.prototype.partials[e])},a.compile=function(e,t){return new s(e,t).compile()},a.options=s.prototype.options,a.helpers=s.prototype.helpers,a.partials=s.prototype.partials,a});
//# sourceMappingURL=template7.min.js.map

@@ -5,2 +5,3 @@ (function(){

connect = require('gulp-connect'),
eslint = require('gulp-eslint'),
open = require('gulp-open'),

@@ -12,4 +13,6 @@ rename = require('gulp-rename'),

sourcemaps = require('gulp-sourcemaps'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
rollup = require('rollup-stream'),
buble = require('rollup-plugin-buble'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
paths = {

@@ -48,4 +51,2 @@ root: './',

gulp.task('build', function (cb) {

@@ -63,17 +64,56 @@ gulp.src(paths.source + 'template7.js')

gulp.task('dist', function () {
gulp.src(paths.build + 'template7.js')
.pipe(gulp.dest(paths.dist))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(header(t7.banner, { pkg : t7.pkg, date: t7.date }))
.pipe(rename(function(path) {
path.basename = t7.filename + '.min';
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.dist));
gulp.src(paths.build + 'template7.js.map')
.pipe(gulp.dest(paths.dist));
gulp.task('build', function (cb) {
rollup({
entry: './src/template7.js',
plugins: [buble()],
format: 'umd',
moduleName: 'Template7',
useStrict: true,
sourceMap: true
})
.pipe(source('template7.js', './src'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build/'))
.on('end', function () {
cb();
});
});
gulp.task('dist', function (cb) {
rollup({
entry: './src/template7.js',
plugins: [buble()],
format: 'umd',
moduleName: 'Template7',
useStrict: 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', function () {
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', function () {
cb();
});
});
});
gulp.task('watch', function () {

@@ -80,0 +120,0 @@ gulp.watch(paths.source + 'template7.js', [ 'build' ]);

{
"name": "template7",
"version": "1.1.4",
"version": "1.2.0",
"description": "Mobile-first HTML template engine",
"main": "dist/",
"main": "dist/template7.js",
"repository": {

@@ -11,11 +11,11 @@ "type": "git",

"keywords": [
"mobile",
"template",
"javascript",
"ios7",
"ios8",
"ios 8",
"iphone",
"ipad",
"phonegap",
"mobile",
"template",
"javascript",
"ios7",
"ios8",
"ios 8",
"iphone",
"ipad",
"phonegap",
"framework7",

@@ -37,16 +37,21 @@ "handlebars",

"devDependencies": {
"jshint": "~2.9.3",
"gulp": "~3.9.0",
"gulp-connect": "~5.0.0",
"gulp-open": "~1.0.0",
"gulp-uglify": "~2.0.0",
"gulp-sourcemaps": "~1.6.0",
"gulp-jshint": "~2.0.1",
"gulp-rename": "~1.2.2",
"gulp-header": "~1.8.8",
"jshint-stylish": "~2.2.1"
},
"scripts": {
"test": "grunt test"
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-config-airbnb-base": "^11.1.3",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"gulp": "^3.9.1",
"gulp-connect": "^5.0.0",
"gulp-eslint": "^3.0.1",
"gulp-header": "^1.8.8",
"gulp-open": "^2.0.0",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.6.0",
"gulp-uglify": "^2.1.2",
"rollup-plugin-buble": "^0.15.0",
"rollup-stream": "^1.19.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
}
}

@@ -0,1 +1,2 @@

<a href="https://www.patreon.com/vladimirkharlampidi"><img src="https://cdn.framework7.io/i/support-badge.png" height="20"></a>
[![devDependency Status](https://david-dm.org/nolimits4web/template7/dev-status.svg)](https://david-dm.org/nolimits4web/template7#info=devDependencies)

@@ -6,3 +7,3 @@

JavaScript template engine with syntax similar to Handlebars.
JavaScript template engine with syntax similar to Handlebars.

@@ -9,0 +10,0 @@ Template7 is the default template engine in [Framework7](http://idangero.us/framework7/), but also can be used separately.

@@ -1,474 +0,455 @@

window.Template7 = (function () {
'use strict';
function isArray(arr) {
return Object.prototype.toString.apply(arr) === '[object Array]';
let template7Context;
if (typeof window !== 'undefined') {
template7Context = window;
} else if (typeof global !== 'undefined') {
template7Context = global;
} else {
template7Context = this;
}
function isArray(arr) {
return Array.isArray ? Array.isArray(arr) : Object.prototype.toString.apply(arr) === '[object Array]';
}
function isFunction(func) {
return typeof func === 'function';
}
function escape(string) {
return (typeof template7Context !== 'undefined' && template7Context.escape ? template7Context.escape(string) : string)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
const quoteSingleRexExp = new RegExp('\'', 'g');
const quoteDoubleRexExp = new RegExp('"', 'g');
function helperToSlices(string) {
const helperParts = string.replace(/[{}#}]/g, '').split(' ');
const slices = [];
let shiftIndex;
let i;
let j;
for (i = 0; i < helperParts.length; i += 1) {
let part = helperParts[i];
let blockQuoteRegExp;
let openingQuote;
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;
}
} else if (part.indexOf('=') > 0) {
// Hash
const hashParts = part.split('=');
const hashName = hashParts[0];
let 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;
}
const hash = [hashName, hashContent.replace(blockQuoteRegExp, '')];
slices.push(hash);
} else {
// Plain variable
slices.push(part);
}
function isObject(obj) {
return obj instanceof Object;
}
function isFunction(func) {
return typeof func === 'function';
}
function _escape(string) {
return typeof window !== 'undefined' && window.escape ? window.escape(string) : string
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
var cache = {};
var quoteSingleRexExp = new RegExp('\'', 'g');
var quoteDoubleRexExp = new RegExp('"', 'g');
function helperToSlices(string) {
var helperParts = string.replace(/[{}#}]/g, '').split(' ');
var slices = [];
var shiftIndex, i, j;
for (i = 0; i < helperParts.length; i++) {
var part = helperParts[i];
var blockQuoteRegExp, openingQuote;
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++) {
part += ' ' + helperParts[j];
if (helperParts[j].indexOf(openingQuote) >= 0) {
shiftIndex = j;
slices.push(part);
break;
}
}
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++) {
hashContent += ' ' + helperParts[j];
if (helperParts[j].indexOf(openingQuote) >= 0) {
shiftIndex = j;
break;
}
}
if (shiftIndex) i = shiftIndex;
}
var hash = [hashName, hashContent.replace(blockQuoteRegExp,'')];
slices.push(hash);
}
else {
// Plain variable
slices.push(part);
}
}
}
return slices;
}
function stringToBlocks(string) {
const blocks = [];
let i;
let j;
if (!string) return [];
const stringBlocks = string.split(/({{[^{^}]*}})/);
for (i = 0; i < stringBlocks.length; i += 1) {
const block = stringBlocks[i];
if (block === '') continue;
if (block.indexOf('{{') < 0) {
blocks.push({
type: 'plain',
content: block,
});
} else {
if (block.indexOf('{/') >= 0) {
continue;
}
if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) {
// Simple variable
blocks.push({
type: 'variable',
contextName: block.replace(/[{}]/g, ''),
});
continue;
}
// Helpers
const helperSlices = helperToSlices(block);
let helperName = helperSlices[0];
const isPartial = helperName === '>';
const helperContext = [];
const helperHash = {};
for (j = 1; j < helperSlices.length; j += 1) {
const slice = helperSlices[j];
if (isArray(slice)) {
// Hash
helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1];
} else {
helperContext.push(slice);
}
}
if (block.indexOf('{#') >= 0) {
// Condition/Helper
let helperContent = '';
let elseContent = '';
let toSkip = 0;
let shiftIndex;
let foundClosed = false;
let foundElse = false;
let 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 {
if (!foundElse) helperContent += stringBlocks[j];
if (foundElse) elseContent += stringBlocks[j];
}
}
return slices;
if (foundClosed) {
if (shiftIndex) i = shiftIndex;
blocks.push({
type: 'helper',
helperName,
contextName: helperContext,
content: helperContent,
inverseContent: elseContent,
hash: helperHash,
});
}
} else if (block.indexOf(' ') > 0) {
if (isPartial) {
helperName = '_partial';
if (helperContext[0]) helperContext[0] = `"${helperContext[0].replace(/"|'/g, '')}"`;
}
blocks.push({
type: 'helper',
helperName,
contextName: helperContext,
hash: helperHash,
});
}
}
function stringToBlocks(string) {
var blocks = [], i, j, k;
if (!string) return [];
var _blocks = string.split(/({{[^{^}]*}})/);
for (i = 0; i < _blocks.length; i++) {
var block = _blocks[i];
if (block === '') continue;
if (block.indexOf('{{') < 0) {
blocks.push({
type: 'plain',
content: block
});
}
else {
if (block.indexOf('{/') >= 0) {
continue;
}
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 = helperToSlices(block);
var helperName = helperSlices[0];
var isPartial = helperName === '>';
var helperContext = [];
var helperHash = {};
for (j = 1; j < helperSlices.length; j++) {
var slice = helperSlices[j];
if (isArray(slice)) {
// Hash
helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1];
}
else {
helperContext.push(slice);
}
}
}
return blocks;
}
class Template7 {
constructor(template) {
const t = this;
t.template = template;
if (block.indexOf('{#') >= 0) {
// Condition/Helper
var helperStartIndex = i;
var helperContent = '';
var elseContent = '';
var toSkip = 0;
var shiftIndex;
var foundClosed = false, foundElse = false, foundClosedElse = false, depth = 0;
for (j = i + 1; j < _blocks.length; j++) {
if (_blocks[j].indexOf('{{#') >= 0) {
depth ++;
}
if (_blocks[j].indexOf('{{/') >= 0) {
depth --;
}
if (_blocks[j].indexOf('{{#' + helperName) >= 0) {
helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
toSkip ++;
}
else if (_blocks[j].indexOf('{{/' + helperName) >= 0) {
if (toSkip > 0) {
toSkip--;
helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
}
else {
shiftIndex = j;
foundClosed = true;
break;
}
}
else if (_blocks[j].indexOf('else') >= 0 && depth === 0) {
foundElse = true;
}
else {
if (!foundElse) helperContent += _blocks[j];
if (foundElse) elseContent += _blocks[j];
}
function getCompileVar(name, ctx) {
let variable = ctx;
let parts;
let levelsUp = 0;
if (name.indexOf('../') === 0) {
const newDepth = variable.split('_')[1] - levelsUp;
levelsUp = name.split('../').length - 1;
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 (let i = 0; i < parts.length; i += 1) {
const part = parts[i];
if (part.indexOf('@') === 0) {
if (i > 0) {
variable += `[(data && data.${part.replace('@', '')})]`;
} else {
variable = `(data && data.${name.replace('@', '')})`;
}
} else if (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 (foundClosed) {
if (shiftIndex) i = shiftIndex;
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]) helperContext[0] = '"' + helperContext[0].replace(/"|'/g, '') + '"';
}
blocks.push({
type: 'helper',
helperName: helperName,
contextName: helperContext,
hash: helperHash
});
}
}
return variable;
}
function getCompiledArguments(contextArray, ctx) {
const arr = [];
for (let 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(getCompileVar(contextArray[i], ctx));
}
return blocks;
}
return arr.join(', ');
}
var Template7 = function (template, options) {
var t = this;
t.template = template;
function compile(template = t.template, depth = 1) {
if (typeof template !== 'string') {
throw new Error('Template7: Template must be a string');
}
const blocks = stringToBlocks(template);
const ctx = `ctx_${depth}`;
if (blocks.length === 0) {
return function empty() { return ''; };
}
function getCompileFn(block, depth) {
if (block.content) return compile(block.content, depth);
else return function () {return ''; };
function getCompileFn(block, newDepth) {
if (block.content) return compile(block.content, newDepth);
return function empty() { return ''; };
}
function getCompileInverse(block, newDepth) {
if (block.inverseContent) return compile(block.inverseContent, newDepth);
return function empty() { return ''; };
}
let resultString = '';
if (depth === 1) {
resultString += `(function (${ctx}, data, root) {\n`;
} else {
resultString += `(function (${ctx}, data) {\n`;
}
if (depth === 1) {
resultString += 'function isArray(arr){return Object.prototype.toString.apply(arr) === \'[object Array]\';}\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';
let i;
for (i = 0; i < blocks.length; i += 1) {
const block = blocks[i];
// Plain block
if (block.type === 'plain') {
resultString += `r +='${(block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'')}';`;
continue;
}
function getCompileInverse(block, depth) {
if (block.inverseContent) return compile(block.inverseContent, depth);
else return function () {return ''; };
let variable;
let compiledArguments;
// Variable block
if (block.type === 'variable') {
variable = getCompileVar(block.contextName, ctx);
resultString += `r += c(${variable}, ${ctx});`;
}
function getCompileVar(name, ctx) {
var variable, parts, levelsUp = 0, initialCtx = ctx;
if (name.indexOf('../') === 0) {
levelsUp = name.split('../').length - 1;
var newDepth = ctx.split('_')[1] - levelsUp;
ctx = 'ctx_' + (newDepth >= 1 ? newDepth : 1);
parts = name.split('../')[levelsUp].split('.');
}
else if (name.indexOf('@global') === 0) {
ctx = 'Template7.global';
parts = name.split('@global.')[1].split('.');
}
else if (name.indexOf('@root') === 0) {
ctx = 'root';
parts = name.split('@root.')[1].split('.');
}
else {
parts = name.split('.');
}
variable = ctx;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
if (part.indexOf('@') === 0) {
if (i > 0) {
variable += '[(data && data.' + part.replace('@', '') + ')]';
}
else {
variable = '(data && data.' + name.replace('@', '') + ')';
}
}
else {
if (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;
}
}
}
}
// Helpers block
if (block.type === 'helper') {
if (block.helperName in t.helpers) {
compiledArguments = getCompiledArguments(block.contextName, ctx);
return variable;
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});`;
} else if (block.contextName.length > 0) {
throw new Error(`Template7: Missing helper: "${block.helperName}"`);
} else {
variable = getCompileVar(block.helperName, ctx);
resultString += `if (${variable}) {`;
resultString += `if (isArray(${variable})) {`;
resultString += `r += (Template7.helpers.each).call(${ctx}, ${variable}, {hash:${JSON.stringify(block.hash)}, data: data || {}, fn: ${getCompileFn(block, depth + 1)}, inverse: ${getCompileInverse(block, depth + 1)}, root: root});`;
resultString += '}else {';
resultString += `r += (Template7.helpers.with).call(${ctx}, ${variable}, {hash:${JSON.stringify(block.hash)}, data: data || {}, fn: ${getCompileFn(block, depth + 1)}, inverse: ${getCompileInverse(block, depth + 1)}, root: root});`;
resultString += '}}';
}
}
function getCompiledArguments(contextArray, ctx) {
var arr = [];
for (var i = 0; i < contextArray.length; i++) {
if (/^['"]/.test(contextArray[i])) arr.push(contextArray[i]);
else if (/^(true|false|\d+)$/.test(contextArray[i])) arr.push(contextArray[i]);
else {
arr.push(getCompileVar(contextArray[i], ctx));
}
}
}
resultString += '\nreturn r;})';
return eval.call(template7Context, resultString);
}
t.compile = function _compile(template) {
if (!t.compiled) {
t.compiled = compile(template);
}
return t.compiled;
};
}
}
return arr.join(', ');
}
function compile(template, depth) {
depth = depth || 1;
template = template || t.template;
if (typeof template !== 'string') {
throw new Error('Template7: Template must be a string');
}
var blocks = stringToBlocks(template);
if (blocks.length === 0) {
return function () { return ''; };
}
var ctx = 'ctx_' + depth;
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 Object.prototype.toString.apply(arr) === \'[object Array]\';}\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, j, context;
for (i = 0; i < blocks.length; i++) {
var block = blocks[i];
// Plain block
if (block.type === 'plain') {
resultString += 'r +=\'' + (block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'') + '\';';
continue;
}
var variable, compiledArguments;
// Variable block
if (block.type === 'variable') {
variable = getCompileVar(block.contextName, ctx);
resultString += 'r += c(' + variable + ', ' + ctx + ');';
}
// Helpers block
if (block.type === 'helper') {
if (block.helperName in t.helpers) {
compiledArguments = getCompiledArguments(block.contextName, ctx);
Template7.prototype = {
options: {},
partials: {},
helpers: {
_partial(partialName, options) {
const p = Template7.prototype.partials[partialName];
if (!p || (p && !p.template)) return '';
if (!p.compiled) {
p.compiled = new Template7(p.template).compile();
}
const ctx = this;
for (const hashName in options.hash) {
ctx[hashName] = options.hash[hashName];
}
return p.compiled(ctx, options.data, options.root);
},
escape(context, options) {
if (typeof context !== 'string') {
throw new Error('Template7: Passed context to "escape" helper should be a string');
}
return escape(context);
},
if(context, options) {
let ctx = context;
if (isFunction(ctx)) { ctx = ctx.call(this); }
if (ctx) {
return options.fn(this, options.data);
}
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});';
return options.inverse(this, options.data);
},
unless(context, options) {
let ctx = context;
if (isFunction(ctx)) { ctx = ctx.call(this); }
if (!ctx) {
return options.fn(this, options.data);
}
}
else {
if (block.contextName.length > 0) {
throw new Error('Template7: Missing helper: "' + block.helperName + '"');
}
else {
variable = getCompileVar(block.helperName, ctx);
resultString += 'if (' + variable + ') {';
resultString += 'if (isArray(' + variable + ')) {';
resultString += 'r += (Template7.helpers.each).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: root});';
resultString += '}else {';
resultString += 'r += (Template7.helpers.with).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: root});';
resultString += '}}';
}
}
}
}
resultString += '\nreturn r;})';
return eval.call(window, resultString);
return options.inverse(this, options.data);
},
each(context, options) {
let ctx = context;
let ret = '';
let i = 0;
if (isFunction(ctx)) { ctx = ctx.call(this); }
if (isArray(ctx)) {
if (options.hash.reverse) {
ctx = ctx.reverse();
}
t.compile = function (template) {
if (!t.compiled) {
t.compiled = compile(template);
}
return t.compiled;
};
};
Template7.prototype = {
options: {},
partials: {},
helpers: {
'_partial' : function (partialName, options) {
var p = Template7.prototype.partials[partialName];
if (!p || (p && !p.template)) return '';
if (!p.compiled) {
p.compiled = new Template7(p.template).compile();
}
var ctx = this;
for (var hashName in options.hash) {
ctx[hashName] = options.hash[hashName];
}
return p.compiled(ctx, options.data, options.root);
},
'escape': function (context, options) {
if (typeof context !== 'string') {
throw new Error('Template7: Passed context to "escape" helper should be a string');
}
return _escape(context);
},
'if': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
if (context) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
},
'unless': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
if (!context) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
},
'each': function (context, options) {
var ret = '', i = 0;
if (isFunction(context)) { context = context.call(this); }
if (isArray(context)) {
if (options.hash.reverse) {
context = context.reverse();
}
for (i = 0; i < context.length; i++) {
ret += options.fn(context[i], {first: i === 0, last: i === context.length - 1, index: i});
}
if (options.hash.reverse) {
context = context.reverse();
}
}
else {
for (var key in context) {
i++;
ret += options.fn(context[key], {key: key});
}
}
if (i > 0) return ret;
else return options.inverse(this);
},
'with': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
return options.fn(context);
},
'join': function (context, options) {
if (isFunction(context)) { context = context.call(this); }
return context.join(options.hash.delimiter || options.hash.delimeter);
},
'js': function (expression, options) {
var func;
if (expression.indexOf('return')>=0) {
func = '(function(){'+expression+'})';
}
else {
func = '(function(){return ('+expression+')})';
}
return eval.call(this, func).call(this);
},
'js_compare': function (expression, options) {
var func;
if (expression.indexOf('return')>=0) {
func = '(function(){'+expression+'})';
}
else {
func = '(function(){return ('+expression+')})';
}
var condition = eval.call(this, func).call(this);
if (condition) {
return options.fn(this, options.data);
}
else {
return options.inverse(this, options.data);
}
}
for (i = 0; i < ctx.length; i += 1) {
ret += options.fn(ctx[i], { first: i === 0, last: i === ctx.length - 1, index: i });
}
};
var t7 = function (template, data) {
if (arguments.length === 2) {
var instance = new Template7(template);
var rendered = instance.compile()(data);
instance = null;
return (rendered);
if (options.hash.reverse) {
ctx = ctx.reverse();
}
else return new Template7(template);
};
t7.registerHelper = function (name, fn) {
Template7.prototype.helpers[name] = fn;
};
t7.unregisterHelper = function (name) {
Template7.prototype.helpers[name] = undefined;
delete Template7.prototype.helpers[name];
};
t7.registerPartial = function (name, template) {
Template7.prototype.partials[name] = {template: template};
};
t7.unregisterPartial = function (name, template) {
if (Template7.prototype.partials[name]) {
Template7.prototype.partials[name] = undefined;
delete Template7.prototype.partials[name];
} else {
for (const key in ctx) {
i += 1;
ret += options.fn(ctx[key], { key });
}
};
t7.compile = function (template, options) {
var instance = new Template7(template, options);
return instance.compile();
};
}
if (i > 0) return ret;
return options.inverse(this);
},
with(context, options) {
let ctx = context;
if (isFunction(ctx)) { ctx = context.call(this); }
return options.fn(ctx);
},
join(context, options) {
let ctx = context;
if (isFunction(ctx)) { ctx = ctx.call(this); }
return ctx.join(options.hash.delimiter || options.hash.delimeter);
},
js(expression, options) {
let func;
if (expression.indexOf('return') >= 0) {
func = `(function(){${expression}})`;
} else {
func = `(function(){return (${expression})})`;
}
return eval.call(this, func).call(this);
},
js_compare(expression, options) {
let func;
if (expression.indexOf('return') >= 0) {
func = `(function(){${expression}})`;
} else {
func = `(function(){return (${expression})})`;
}
const condition = eval.call(this, func).call(this);
if (condition) {
return options.fn(this, options.data);
}
t7.options = Template7.prototype.options;
t7.helpers = Template7.prototype.helpers;
t7.partials = Template7.prototype.partials;
return t7;
})();
return options.inverse(this, options.data);
},
},
};
function t7(template, data) {
if (arguments.length === 2) {
let instance = new Template7(template);
const rendered = instance.compile()(data);
instance = null;
return (rendered);
}
return new Template7(template);
}
t7.registerHelper = function registerHelper(name, fn) {
Template7.prototype.helpers[name] = fn;
};
t7.unregisterHelper = function unregisterHelper(name) {
Template7.prototype.helpers[name] = undefined;
delete Template7.prototype.helpers[name];
};
t7.registerPartial = function registerPartial(name, template) {
Template7.prototype.partials[name] = { template };
};
t7.unregisterPartial = function unregisterPartial(name) {
if (Template7.prototype.partials[name]) {
Template7.prototype.partials[name] = undefined;
delete Template7.prototype.partials[name];
}
};
t7.compile = function compile(template, options) {
const instance = new Template7(template, options);
return instance.compile();
};
t7.options = Template7.prototype.options;
t7.helpers = Template7.prototype.helpers;
t7.partials = Template7.prototype.partials;
export default t7;

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc