New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

Templ8

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Templ8 - npm Package Compare versions

Comparing version 0.9.7 to 0.9.8

src/_begin.js

5

build.js

@@ -41,3 +41,3 @@ // require modules

src += Templ8.format( '\n/* file: {0} */\n{1}\n', file.substring( file.lastIndexOf( '/' ) + 1 ), fs.readFileSync( file, params.encoding ) );
src += Templ8.format( '\n{0}', fs.readFileSync( file, params.encoding ) );
} );

@@ -50,3 +50,4 @@

fs.writeFileSync( out_file, pro.gen_code( src_ast, { beautify : true, space_colon : true } ), params.encoding );
fs.writeFileSync( out_file, src, params.encoding );
// fs.writeFileSync( out_file, pro.gen_code( src_ast, { beautify : true, space_colon : true } ), params.encoding );

@@ -53,0 +54,0 @@ if ( params.out.min ) {

2

build.json

@@ -8,4 +8,4 @@ {

"dir" : "./src",
"files" : [".begin", "Templ8", "Tag", "Statement", "Filter", ".end"]
"files" : ["_begin", "Templ8", "Tag", "Statement", "Filter", "_end"]
}
}

@@ -30,3 +30,3 @@ {

},
"version" : "0.9.7"
"version" : "0.9.8"
}

@@ -1,9 +0,9 @@

Templ8.Filter.add( {
__Class__.Filter.add( {
capitalize : function( str ) {
str = Templ8.stringify( str );
str = __Class__.stringify( str );
return str.charAt( 0 ).toUpperCase() + str.substring( 1 ).toLowerCase();
},
count : function( o ) { return m8.len( o ) || 0; },
count : function( o ) { return util.len( o ) || 0; },
crop : function( str, i ) {
str = Templ8.stringify( str );
str = __Class__.stringify( str );
i = parseInt( i, 10 ) || 50;

@@ -14,3 +14,3 @@ return str.length > i ? str.substring( 0, i / 2 ) + '...' + str.substring( str.length - ( i / 2 ) ) : str;

first : function( o ) {
switch ( m8.nativeType( o ) ) {
switch ( util.nativeType( o ) ) {
case 'array' : return o[0];

@@ -20,5 +20,5 @@ case 'string' : return o.charAt( 0 );

},
join : function( o, s ) { return m8.got( o, 'join' ) && typeof o.join == 'function' ? o.join( s ) : o; },
join : function( o, s ) { return util.got( o, 'join' ) && typeof o.join == 'function' ? o.join( s ) : o; },
last : function( o ) {
switch ( m8.nativeType( o ) ) {
switch ( util.nativeType( o ) ) {
case 'array' : return o[o.length-1];

@@ -28,12 +28,12 @@ case 'string' : return o.charAt( o.length - 1 );

},
lowercase : function( str ) { return Templ8.stringify( str ).toLowerCase(); },
lowercase : function( str ) { return __Class__.stringify( str ).toLowerCase(); },
prefix : function( str1, str2 ) { return str2 + str1; },
suffix : function( str1, str2 ) { return str1 + str2; },
truncate : function( str, i ) {
str = Templ8.stringify( str );
str = __Class__.stringify( str );
i = parseInt( i, 10 ) || 50;
return str.length > i ? str.substring( 0, i ) + '...' : str;
},
uppercase : function( str ) { return Templ8.stringify( str ).toUpperCase(); },
uppercase : function( str ) { return __Class__.stringify( str ).toUpperCase(); },
wrap : function( str, start, end ) { return start + str + ( end || start ); }
} );
typeof document == 'undefined'
|| m8.tostr( document.createElement( 'div' ) ) == '[object HTMLDivElement]'
|| ( Templ8.type = function() {
|| util.tostr( document.createElement( 'div' ) ) == '[object HTMLDivElement]'
|| ( __Class__.type = function() {
var U, re_global = /global|window/;
return function type( o ) {
if ( o === U || o === null ) return !1;
var t = m8.tostr( o ).split( ' ' )[1].toLowerCase();
var t = util.tostr( o ).split( ' ' )[1].toLowerCase();
t = t.substring( 0, t.length - 1 );
switch ( t ) {
case 'object' :
if ( m8.global.attachEvent ) { // handle IE coz it can has stupidz
if ( util.global.attachEvent ) { // handle IE coz it can has stupidz
return o.nodeName && o.nodeType == 1
? 'htmlelement' : !isNaN( o.length ) && is_fn( o.item )
? 'htmlcollection' : o === m8.global.document
? 'htmldocument' : o === m8.global
? 'htmlcollection' : o === util.global.document
? 'htmldocument' : o === util.global
? 'global' : t;

@@ -17,0 +17,0 @@ }

@@ -54,3 +54,3 @@ ( function() {

sub_tpl = new Templ8( '', m8.copy( { debug : ctx.debug, fallback : ctx.fallback, id : id }, ctx.filters ) );
sub_tpl = new __Class__( '', util.copy( { debug : ctx.debug, fallback : ctx.fallback, id : id }, ctx.filters ) );
// the parts have already been split, for efficiency we can skip a call to createTemplate() and the more costly splitStr()

@@ -72,4 +72,4 @@ sub_tpl.currentIterKeys = [];

Templ8.Statement.add( _statements );
Templ8.Statement.add( 'elsif', _statements.elseif );
__Class__.Statement.add( _statements );
__Class__.Statement.add( 'elsif', _statements.elseif );
}() );

@@ -6,3 +6,3 @@ var _tags = [ {

if ( str == '' ) throw new SyntaxError( 'Templ8 missing key in value declaration.' );
if ( str == '' ) throw new SyntaxError( Name + ' missing key in value declaration.' );

@@ -19,3 +19,3 @@ // 1st re_one_liner_simple used to be re_one_liner, but fails in V8!!!

if ( !tag || !statement ) throw new SyntaxError( 'Templ8 missing tag or statement in one liner value declaration.' );
if ( !tag || !statement ) throw new SyntaxError( Name + ' missing tag or statement in one liner value declaration.' );

@@ -27,3 +27,3 @@ return tag( internals, ctx, statement, tpl_parts ) + internals.wrap( val ) + getStatement( 'endif' );

emit : function( internals, ctx, str, tpl_parts ) {
if ( str == '' ) throw new SyntaxError( 'Templ8 missing key in statement declaration.' );
if ( str == '' ) throw new SyntaxError( Name + ' missing key in statement declaration.' );

@@ -40,6 +40,11 @@ var parts, statement, tag;

if ( !tag || !statement ) throw new SyntaxError( 'Templ8 missing tag or statement in statement declaration.' );
if ( !tag || !statement ) {
parts = [];
tag || parts.push( 'tag' );
statement || parts.push( 'statement' );
throw new SyntaxError( Name + ' missing ' + parts.join( ' and ' ) + ' in statement declaration.' );
}
}
if ( !tag ) throw new SyntaxError( format( 'Templ8 tag: {0} does not exist.', tag ) );
if ( !tag ) throw new SyntaxError( format( Name + ' tag: {0} does not exist.', tag ) );

@@ -80,3 +85,3 @@ return typeof tag == 'function' ? tag( internals, ctx, statement, tpl_parts ) : tag;

dummy_arr = [],
getStatement = Templ8.Statement.get,
getStatement = __Class__.Statement.get,
re_comma_spacing = /\s*(,)\s*/g,

@@ -89,4 +94,4 @@ re_comprehension_split = /^\(\s*(.*?)(?:\bin\b){0,1}(.*?)\s*\)\s*(if|unless){0,1}\s*(.*)$/i,

_tags.forEach( function( tag ) { Templ8.Tag.create( tag, true ); } );
_tags.forEach( function( tag ) { __Class__.Tag.create( tag, true ); } );
Templ8.Tag.compileRegExp();
__Class__.Tag.compileRegExp();
var U, RESERVED = '__ASSERT__ __CONTEXT__ __FILTER_ __OUTPUT__ __UTIL__ $_ document false global instanceof null true typeof undefined window'.split( ' ' ).reduce( function( o, k ) {
o[k] = true; return o;
}, m8.obj() ),
}, util.obj() ),
RE_GSUB = /\$?\{([^\}\s]+)\}/g,
ba = {
blank : function( o ) { return m8.empty( o ) || ( typeof o == 'string' && !o.trim() ); },
blank : function( o ) { return util.empty( o ) || ( typeof o == 'string' && !o.trim() ); },
contains : contains,

@@ -13,5 +13,5 @@ endsWith : function( s, str ) {

},
empty : m8.empty,
empty : util.empty,
equals : function( o, v ) { return o == v },
exists : m8.exists,
exists : util.exists,
is : function( o, v ) { return o === v },

@@ -21,3 +21,3 @@ isEven : function( i ) { return !( parseInt( i, 10 ) & 1 ); },

isTPL : function( id ) { return !!( getTPL( format( tpl_sub, this.id, id ) ) || getTPL( id ) ); },
iterable : function( o ) { return m8.iter( o ); },
iterable : function( o ) { return util.iter( o ); },
notEmpty : not_empty,

@@ -28,15 +28,10 @@ startsWith : function( s, str ) { return String( s ).indexOf( str ) === 0; }

objectify : function( v, k ) { var o = {}; o[k] = v; return o; },
parse : function( o, id, mixins ) { // todo: pass in the parent ContextStack
id = String( id ).trim(); // todo: so the sub template can reference all dictionary values
var t = getTPL( format( tpl_sub, this.id, id ) ) || getTPL( id );
parse : function( o, id, tpl ) {
id = String( id ).trim();
if ( is_obj( o ) && mixins !== this.__dict__ ) {
switch( m8.nativeType( mixins ) ) {
case 'object' : break;
case 'null' : case 'undefined' : mixins = {}; break;
default : mixins = { __MIXINS__ : mixins };
}
o = m8.copy( mixins, o, true );
}
var d = [tpl[fn_var.dict], o],
t = getTPL( format( tpl_sub, this.id, id ) ) || getTPL( id );
d[fn_var.dict] = true;
return t ? t.parse( o ) : this.fallback;

@@ -46,3 +41,3 @@ },

stringify : stringify,
type : function( o ) { return m8.type( o ); }
type : function( o ) { return util.type( o ); }
},

@@ -53,5 +48,5 @@ cache_key = '__tpl_cs_cached_keys', cache_stack = '__tpl_cs_stack',

fn_var = { assert : '__ASSERT__', dict : '__CONTEXT__', filter : '__FILTER__', output : '__OUTPUT__', util : '__UTIL__' },
fn_var = { assert : '__ASSERT__', ctx : '__CONTEXT__', dict : '__dict__', filter : '__FILTER__', output : '__OUTPUT__', util : '__UTIL__' },
fn_end = format( 'return {0};\n ', fn_var.output ),
fn_start = '\n"use strict";\n' + format( 'var $C = new ContextStack( {0}, this.fallback, this.dict ), $_ = $C.current(), iter = new Iter( null ), {1} = "", U;', fn_var.dict, fn_var.output ),
fn_start = '\n"use strict";\n' + format( 'var $C = new ContextStack( {0}, this.fallback, this.dict ), $_ = $C.current(), iter = new Iter( null ), {1} = "", U;', fn_var.ctx, fn_var.output ),

@@ -67,3 +62,3 @@ id_count = 999, internals, logger = 'console', // <= gets around jsLint

split_token = '<__SPLIT__TEMPL8__HERE__>', split_replace = ['', '$1', '$2', ''].join( split_token ),
split_token = '<__SPLIT__TEMPLATE__HERE__>', split_replace = ['', '$1', '$2', ''].join( split_token ),

@@ -73,3 +68,3 @@ tpl = {}, tpl_id = 't8-anon-{0}', tpl_statement = '{0}["{1}"].call( this, {2}{3}, {4} )', tpl_sub = '{0}.{1}';

/*** START: Utility Functions ***/
function contains( o, k ) { return ( typeof o.indexOf == 'function' && !!~o.indexOf( k ) ) || m8.got( o, k ) ; }
function contains( o, k ) { return ( typeof o.indexOf == 'function' && !!~o.indexOf( k ) ) || util.got( o, k ) ; }

@@ -87,3 +82,3 @@ function escapeRE( s ) { return String( s ).replace( esc_chars, esc_val ); }

function mapc( a, fn, ctx ) {
fn || ( fn = m8 ); ctx || ( ctx = a );
fn || ( fn = util ); ctx || ( ctx = a );
var i = -1, l = a.length, res = [], v;

@@ -97,3 +92,3 @@ while ( ++i < l ) {

case 'number' : isNaN( v ) || res.push( v ); break;
default : ( !m8.iter( v ) || m8.len( v ) ) || res.push( v ); break;
default : ( !util.iter( v ) || util.len( v ) ) || res.push( v ); break;
}

@@ -105,13 +100,10 @@ }

function not_empty( o ) { return !m8.empty( o ); }
function not_empty( o ) { return !util.empty( o ); }
/*** END: Utility Functions ***/
/*** START: Classes used by compiled templates ***/
function ContextStack( dict, fallback, base ) {
function ContextStack( dict, fallback ) {
this[cache_stack] = [];
this.push( m8.global );
// if ( base ) switch ( m8.nativeType( base ) ) { // todo: analyse performance impace of this before implementing
// case 'object' : this.push( base ); break;
// case 'array' : base.forEach( this.push, this ); break;
// }
this.push( util.global );
if ( fallback !== U ) {

@@ -121,3 +113,11 @@ this.hasFallback = true;

}
!m8.exists( dict ) || this.push( dict );
switch( util.nativeType( dict ) ) {
case 'object' : this.push( dict );
break;
case 'array' : dict[fn_var.dict]
? dict.map( this.push, this ) : this.push( dict );
break;
default : !util.exists( dict ) || this.push( dict );
}
}

@@ -142,3 +142,3 @@ ContextStack.prototype = {

push : function ContextStack_push( dict ) {
this[cache_stack].push( this.top = { cache : m8.obj(), dict : dict } );
this[cache_stack].push( this.top = { cache : util.obj(), dict : dict } );
return this;

@@ -154,3 +154,3 @@ }

m8.tostr( iter ) == '[object Object]' || ( keys = keys.map( Number ) );
util.tostr( iter ) == '[object Object]' || ( keys = keys.map( Number ) );

@@ -192,3 +192,3 @@ this.empty = false;

m8.defs( Iter.prototype, { // todo: these aren't tested yet!
util.defs( Iter.prototype, { // todo: these aren't tested yet!
first : { get : function() { return this._[this.keys[this.firstKey]]; } },

@@ -219,3 +219,3 @@ last : { get : function() { return this._[this.keys[this.lastKey]]; } },

function aggregatetNonEmpty( res, str ) {
m8.empty( str ) || res.push( str );
util.empty( str ) || res.push( str );
return res;

@@ -234,3 +234,3 @@ }

!args || ( args = ', ' + args.split( ',' ).map( function( o ) { return wrapGetter( this, o ); }, ctx ).join( ', ' ) );
return format( tpl_statement, getFnParent( fn ), fn, wrapGetter( ctx, res ), args, fn_var.dict );
return format( tpl_statement, getFnParent( fn ), fn, wrapGetter( ctx, res ), args, fn_var.ctx );
}, '' );

@@ -252,7 +252,7 @@ }

function compileTemplate( ctx, fn ) {
if ( ctx.debug && typeof m8.global[logger] != 'undefined' ) {
m8.global[logger].info( 'Templ8: ', ctx.id, ', source: ' ); m8.global[logger].log( fn );
if ( ctx.debug && typeof util.global[logger] != 'undefined' ) {
util.global[logger].info( Name + ': ', ctx.id, ', source: ' ); util.global[logger].log( fn );
}
var func = ( new Function( 'root', 'ContextStack', 'Iter', fn_var.filter, fn_var.assert, fn_var.util, fn_var.dict, fn ) ).bind( ctx, m8.global, ContextStack, Iter, m8.copy( ctx.filters, Templ8.Filter.all(), true ), ba, bu );
m8.def( func, 'src', m8.describe( fn, 'r' ) );
var func = ( new Function( 'root', 'ContextStack', 'Iter', fn_var.filter, fn_var.assert, fn_var.util, fn_var.ctx, fn ) ).bind( ctx, util.global, ContextStack, Iter, util.copy( ctx.filters, __Class__.Filter.all(), true ), ba, bu );
util.def( func, 'src', util.describe( fn, 'r' ) );
return func;

@@ -270,3 +270,3 @@ }

var tag;
if ( tag = Templ8.Tag.get( part ) ) {
if ( tag = __Class__.Tag.get( part ) ) {
part = parts.shift();

@@ -300,3 +300,3 @@ return tag.emit( internals, ctx, part, parts );

case 'boolean' : case 'number' : case 'string' : return String( o );
default : switch ( m8.nativeType( o ) ) {
default : switch ( util.nativeType( o ) ) {
case 'date' : return o.toDateString();

@@ -307,3 +307,3 @@ case 'array' : return mapc( o, stringify ).join( ', ' );

? str : mapc( Object.values( o ), stringify ).join( ', ' );
default : switch ( m8.type( o ) ) { // todo: should this return outerHTML instead? might be nicer.
default : switch ( util.type( o ) ) {
case 'htmlelement' : return o.outerHTML; //o.textContent || o.text || o.innerText;

@@ -343,3 +343,3 @@ case 'htmlcollection' : return mapc( Array.coerce( o ), function( el ) { return stringify( el ); } ).join( '\n' );

/*** START: Templ8 constructor and prototype ***/
function Templ8() {
function __Class__() {
var a = Array.coerce( arguments ),

@@ -349,3 +349,3 @@ f = is_obj( a[a.length - 1] ) ? a.pop() : is_obj( a[0] ) ? a.shift() : null;

// take care of peeps who are too lazy or too ©ººL to use the "new" constructor...
if ( !( this instanceof Templ8 ) ) return is_obj( f ) ? new Templ8( a.join( '' ), f ) : new Templ8( a.join( '' ) );
if ( !( this instanceof __Class__ ) ) return is_obj( f ) ? new __Class__( a.join( '' ), f ) : new __Class__( a.join( '' ) );

@@ -383,9 +383,9 @@ !f || defaults.forEach( function( k ) {

this.compiled || compile( this );
this.__dict__ = dict;
this[fn_var.dict] = dict;
var s = this._parse( dict );
delete this.__dict__;
delete this[fn_var.dict];
return s;
}
Templ8.prototype = {
__Class__.prototype = {
compiled : false, debug : false, dict : null, fallback : '',

@@ -398,4 +398,4 @@ parse : parse

// exposed for general usage
m8.defs( Templ8, { // store a reference to m8 in Templ8 so we can do fun stuff in commonjs
m8 : { value : m8 }, // modules without having to re-request m8 as well as Templ8 each time.
util.defs( __Class__, { // store a reference to m8 in Templ8 so we can do fun stuff in commonjs
m8 : { value : util }, // modules without having to re-request m8 as well as Templ8 each time.
escapeRE : escapeRE, format : format, get : getTPL,

@@ -408,3 +408,3 @@ gsub : gsub, stringify : stringify

!is_obj( o ) || m8.copy( cache, o );
!is_obj( o ) || util.copy( cache, o );

@@ -419,3 +419,3 @@ function _add( id, fn, replace ) { ( !replace && id in cache ) || ( cache[id] = fn ); }

this.all = function() { return m8.copy( cache ); };
this.all = function() { return util.copy( cache ); };
this.add = function() { return add.call( this, false, arguments[0], arguments[1] ); };

@@ -426,6 +426,6 @@ this.get = function( id ) { return cache[id]; };

Templ8.Assert = new Mgr( ba );
Templ8.Filter = new Mgr( bf );
Templ8.Statement = new Mgr;
Templ8.Tag = new function() {
__Class__.Assert = new Mgr( ba );
__Class__.Filter = new Mgr( bf );
__Class__.Statement = new Mgr;
__Class__.Tag = new function() {
var KEYS = 'emit end start'.split( ' ' ),

@@ -441,9 +441,9 @@ ERRORS = {

KEYS.forEach( assert_exists, config );
m8.copy( this, config );
util.copy( this, config );
tag[this.start] = this;
}
function assert_exists( k ) { if ( !( k in this ) ) { throw new TypeError( format( 'A Templ8 Tag requires an {0}', ERRORS[k] ) ); } }
function assert_exists( k ) { if ( !( k in this ) ) { throw new TypeError( format( 'A ' + Name + ' Tag requires an {0}', ERRORS[k] ) ); } }
this.all = function() { return m8.copy( tag ); };
this.all = function() { return util.copy( tag ); };

@@ -450,0 +450,0 @@ this.compileRegExp = function() {

@@ -1,687 +0,657 @@

!function(m8) {
"use strict";
var U, RESERVED = "__ASSERT__ __CONTEXT__ __FILTER_ __OUTPUT__ __UTIL__ $_ document false global instanceof null true typeof undefined window".split(" ").reduce(function(o, k) {
o[k] = true;
return o;
}, m8.obj()), RE_GSUB = /\$?\{([^\}\s]+)\}/g, ba = {
blank : function(o) {
return m8.empty(o) || typeof o == "string" && !o.trim();
},
contains : contains,
endsWith : function(s, str) {
s = String(s);
var n = s.length - str.length;
return n >= 0 && s.lastIndexOf(str) == n;
},
empty : m8.empty,
equals : function(o, v) {
return o == v;
},
exists : m8.exists,
is : function(o, v) {
return o === v;
},
isEven : function(i) {
return !(parseInt(i, 10) & 1);
},
isOdd : function(i) {
return !(parseInt(i, 10) & 1);
},
isTPL : function(id) {
return !!(getTPL(format(tpl_sub, this.id, id)) || getTPL(id));
},
iterable : function(o) {
return m8.iter(o);
},
notEmpty : not_empty,
startsWith : function(s, str) {
return String(s).indexOf(str) === 0;
}
}, bf = {}, bu = {
objectify : function(v, k) {
var o = {};
o[k] = v;
return o;
},
parse : function(o, id, mixins) {
id = String(id).trim();
var t = getTPL(format(tpl_sub, this.id, id)) || getTPL(id);
if (is_obj(o) && mixins !== this.__dict__) {
switch (m8.nativeType(mixins)) {
case "object":
break;
case "null":
case "undefined":
mixins = {};
break;
default:
mixins = {
__MIXINS__ : mixins
};
}
o = m8.copy(mixins, o, true);
}
return t ? t.parse(o) : this.fallback;
},
stop : function(iter) {
iter.stop();
},
stringify : stringify,
type : function(o) {
return m8.type(o);
}
}, cache_key = "__tpl_cs_cached_keys", cache_stack = "__tpl_cs_stack", defaults = "compiled debug dict fallback id".split(" "), delim = "<~>", esc_chars = /([-\*\+\?\.\|\^\$\/\\\(\)[\]\{\}])/g, esc_val = "\\$1", fn_var = {
assert : "__ASSERT__",
dict : "__CONTEXT__",
filter : "__FILTER__",
output : "__OUTPUT__",
util : "__UTIL__"
}, fn_end = format("return {0};\n ", fn_var.output), fn_start = '\n"use strict";\n' + format('var $C = new ContextStack( {0}, this.fallback, this.dict ), $_ = $C.current(), iter = new Iter( null ), {1} = "", U;', fn_var.dict, fn_var.output), id_count = 999, internals, logger = "console", re_br = /[\n\r]/gm, re_esc = /(['"])/g, re_format_delim = new RegExp(delim, "gm"), re_new_line = /[\r\n]+/g, re_space = /\s+/g, re_special_char = /[\(\)\[\]\{\}\?\*\+\/<>%&=!-]/, re_split_tpl, re_statement_fix = /\.(\d+)(\.?)/g, re_statement_replacer = "['$1']$2", re_statement_split = new RegExp("\\s*([^\\|]+(?:\\|[^\\|]+?)){0,}" + delim, "g"), split_token = "<__SPLIT__TEMPL8__HERE__>", split_replace = [ "", "$1", "$2", "" ].join(split_token), tpl = {}, tpl_id = "t8-anon-{0}", tpl_statement = '{0}["{1}"].call( this, {2}{3}, {4} )', tpl_sub = "{0}.{1}";
function contains(o, k) {
return typeof o.indexOf == "function" && !!~o.indexOf(k) || m8.got(o, k);
}
function escapeRE(s) {
return String(s).replace(esc_chars, esc_val);
}
function format(s) {
return gsub(s, Array.coerce(arguments, 1));
}
function getTPL(id) {
return tpl[id] || null;
}
function gsub(s, o, pattern) {
return String(s).replace(pattern || RE_GSUB, function(m, p) {
return o[p] || "";
});
}
function is_obj(o) {
return typeof o == "object" && (o.constructor === Object || o.constructor === U);
}
function mapc(a, fn, ctx) {
fn || (fn = m8);
ctx || (ctx = a);
var i = -1, l = a.length, res = [], v;
while (++i < l) {
v = fn.call(ctx, a[i], i, a);
switch (v) {
case null:
case U:
break;
default:
switch (typeof v) {
case "string":
v.trim() === "" || res.push(v);
break;
case "number":
isNaN(v) || res.push(v);
break;
default:
!m8.iter(v) || m8.len(v) || res.push(v);
break;
}
}
}
return res;
}
function not_empty(o) {
return !m8.empty(o);
}
function ContextStack(dict, fallback, base) {
this[cache_stack] = [];
this.push(m8.global);
if (fallback !== U) {
this.hasFallback = true;
this.fallback = fallback;
}
!m8.exists(dict) || this.push(dict);
}
ContextStack.prototype = {
current : function ContextStack_current() {
return (this.top || this[cache_stack][0]).dict;
},
get : function ContextStack_get(key) {
var ctx, stack = this[cache_stack], l = stack.length, val;
while (l--) {
ctx = stack[l];
if (key in ctx.cache) return ctx.cache[key];
if ((val = ctx.dict[key]) !== U || (val = Object.value(ctx.dict, key)) !== U) return ctx.cache[key] = val;
}
return this.hasFallback ? this.fallback : U;
},
pop : function ContextStack_pop() {
var dict = this[cache_stack].pop().dict;
this.top = this[cache_stack][this[cache_stack].length - 1];
return dict;
},
push : function ContextStack_push(dict) {
this[cache_stack].push(this.top = {
cache : m8.obj(),
dict : dict
});
return this;
}
};
function Iter(iter, parent, start, count) {
var keys = Object.keys(iter = this._ = Object(iter)), len = keys.length;
if (!len) return this.stop();
m8.tostr(iter) == "[object Object]" || (keys = keys.map(Number));
this.empty = false;
this.count = isNaN(count) ? len : count < 0 ? len + count : count > len ? len : count;
if (start == 0 || isNaN(start)) {
this.firstIndex = 0;
this.index = -1;
} else {
this.firstIndex = start;
this.index = start - 2;
}
this.index1 = this.index + 1;
this.lastIndex = this.count === len ? this.count - 1 : this.count;
this.keys = keys;
!(parent instanceof Iter) || (this.parent = parent);
}
Iter.prototype = {
empty : true,
hasNext : function Iter_hasNext() {
if (this.stopped || this.empty) return false;
++this.index < this.lastIndex || (this.stop().isLast = true);
this.key = this.keys[this.index1++];
this.current = this.val = this._[this.key];
return this;
},
stop : function Iter_stop() {
this.stopped = true;
return this;
}
};
m8.defs(Iter.prototype, {
first : {
get : function() {
return this._[this.keys[this.firstKey]];
}
},
last : {
get : function() {
return this._[this.keys[this.lastKey]];
}
},
next : {
get : function() {
return this._[this.keys[this.nextKey]];
}
},
prev : {
get : function() {
return this._[this.keys[this.prevKey]];
}
},
nextIndex : {
get : function() {
var i = this.index + 1;
return i <= this.lastIndex ? i : U;
}
},
prevIndex : {
get : function() {
var i = this.index - 1;
return i >= this.firstIndex ? i : U;
}
},
firstKey : {
get : function() {
return this.keys[this.firstIndex];
}
},
lastKey : {
get : function() {
return this.keys[this.lastIndex];
}
},
nextKey : {
get : function() {
return this.keys[this.nextIndex];
}
},
prevKey : {
get : function() {
return this.keys[this.prevIndex];
}
}
}, "r");
function aggregatetNonEmpty(res, str) {
m8.empty(str) || res.push(str);
return res;
}
function aggregateStatement(ctx, s) {
return s.reduce(function(res, v, i, parts) {
if (i == 0) return wrapGetter(ctx, v);
var args = "", fn, j = v.indexOf(":");
if (!!~j) {
fn = v.substring(0, j);
args = v.substring(j + 1);
} else fn = v;
!args || (args = ", " + args.split(",").map(function(o) {
return wrapGetter(this, o);
}, ctx).join(", "));
return format(tpl_statement, getFnParent(fn), fn, wrapGetter(ctx, res), args, fn_var.dict);
}, "");
}
function assembleParts(ctx, parts) {
var fn = [ fn_start ], part;
while (part = parts.shift()) fn.push(emitTag(ctx, part, parts));
fn.push(fn_end);
return fn.join("\r\n");
}
function clean(str) {
return str.replace(re_format_delim, "").replace(re_new_line, "\n").replace(re_space, " ").trim();
}
function compileTemplate(ctx, fn) {
if (ctx.debug && typeof m8.global[logger] != "undefined") {
m8.global[logger].info("Templ8: ", ctx.id, ", source: ");
m8.global[logger].log(fn);
}
var func = (new Function("root", "ContextStack", "Iter", fn_var.filter, fn_var.assert, fn_var.util, fn_var.dict, fn)).bind(ctx, m8.global, ContextStack, Iter, m8.copy(ctx.filters, Templ8.Filter.all(), true), ba, bu);
m8.def(func, "src", m8.describe(fn, "r"));
return func;
}
function createTemplate(ctx) {
ctx.currentIterKeys = [];
var fn = compileTemplate(ctx, assembleParts(ctx, splitStr(ctx.__tpl__)));
delete ctx.currentIterKeys;
return fn;
}
function emitTag(ctx, part, parts) {
var tag;
if (tag = Templ8.Tag.get(part)) {
part = parts.shift();
return tag.emit(internals, ctx, part, parts);
}
return wrapStr(format('"{0}"', part.replace(re_esc, "\\$1")));
}
function formatStatement(ctx, str) {
str = clean(str);
switch (str) {
case "AND":
return " && ";
case "OR":
return " || ";
}
return contains(str, "|") || contains(str, delim) ? (" " + str + delim).replace(re_statement_split, function(m) {
return ba.blank(m) || m == delim ? "" : aggregateStatement(ctx, clean(m).split("|"));
}) : wrapGetter(ctx, str);
}
function getFnParent(fn) {
return ba[fn] ? fn_var.assert : bu[fn] ? fn_var.util : fn_var.filter;
}
function splitStr(str) {
return str.replace(re_split_tpl, split_replace).split(split_token).reduce(aggregatetNonEmpty, []);
}
function stringify(o, str) {
switch (typeof o) {
case "boolean":
case "number":
case "string":
return String(o);
default:
switch (m8.nativeType(o)) {
case "date":
return o.toDateString();
case "array":
return mapc(o, stringify).join(", ");
case "object":
return cache_key in o ? stringify(o.dict) : (str = o.toString()) != "[object Object]" ? str : mapc(Object.values(o), stringify).join(", ");
default:
switch (m8.type(o)) {
case "htmlelement":
return o.outerHTML;
case "htmlcollection":
return mapc(Array.coerce(o), function(el) {
return stringify(el);
}).join("\n");
}
}
}
return "";
}
function usingIterKey(key) {
return this == key || ba.startsWith(this, key + ".");
}
function usingIterKeys(keys, o) {
return keys.length ? keys.some(function(k) {
return k.some(usingIterKey, o);
}) : 0;
}
function wrapGetter(ctx, o) {
var k = ctx.currentIterKeys || [];
o = clean(o);
return contains(o, ".call(") || re_special_char.test(o) || ba.startsWith(o, '"') && ba.endsWith(o, '"') || ba.startsWith(o, "'") && ba.endsWith(o, "'") || !isNaN(o) ? o : ba.startsWith(o, "$_.") || ba.startsWith(o, "iter.") || k.length && usingIterKeys(k, o) || o in RESERVED ? o.replace(re_statement_fix, re_statement_replacer) : format('$C.get( "{0}" )', o);
}
function wrapStr(str) {
return format("{0} += {1};", fn_var.output, str.replace(re_br, "\\n"));
}
internals = {
assembleparts : assembleParts,
clean : clean,
compiletpl : compileTemplate,
createtpl : createTemplate,
emittag : emitTag,
fnvar : fn_var,
formatstatement : formatStatement,
get : wrapGetter,
util : bu,
wrap : wrapStr
};
function Templ8() {
var a = Array.coerce(arguments), f = is_obj(a[a.length - 1]) ? a.pop() : is_obj(a[0]) ? a.shift() : null;
if (!(this instanceof Templ8)) return is_obj(f) ? new Templ8(a.join(""), f) : new Templ8(a.join(""));
!f || defaults.forEach(function(k) {
if (k in f) {
this[k] = f[k];
delete f[k];
}
}, this);
this.filters = f || {};
this.__tpl__ = a.join("");
tpl[$id(this)] = this;
if (this.compiled) {
this.compiled = false;
compile(this);
}
}
function $id(ctx) {
ctx.id || (ctx.id = format(tpl_id, ++id_count));
return ctx.id;
}
function compile(ctx) {
if (!ctx.compiled) {
ctx.compiled = true;
ctx._parse = createTemplate(ctx);
}
return ctx;
}
function parse(dict) {
this.compiled || compile(this);
this.__dict__ = dict;
var s = this._parse(dict);
delete this.__dict__;
return s;
}
Templ8.prototype = {
compiled : false,
debug : false,
dict : null,
fallback : "",
parse : parse
};
m8.defs(Templ8, {
m8 : {
value : m8
},
escapeRE : escapeRE,
format : format,
get : getTPL,
gsub : gsub,
stringify : stringify
}, "r");
function Mgr(o) {
var cache = {};
!is_obj(o) || m8.copy(cache, o);
function _add(id, fn, replace) {
!replace && id in cache || (cache[id] = fn);
}
function add(replace, o) {
switch (typeof o) {
case "string":
_add(o, arguments[2], replace);
break;
case "object":
for (var k in o) _add(k, o[k], replace);
break;
}
return this;
}
this.all = function() {
return m8.copy(cache);
};
this.add = function() {
return add.call(this, false, arguments[0], arguments[1]);
};
this.get = function(id) {
return cache[id];
};
this.replace = function() {
return add.call(this, true, arguments[0], arguments[1]);
};
}
Templ8.Assert = new Mgr(ba);
Templ8.Filter = new Mgr(bf);
Templ8.Statement = new Mgr;
Templ8.Tag = new function() {
var KEYS = "emit end start".split(" "), ERRORS = {
emit : "emit function",
end : "end tag definition",
start : "start tag definition"
}, tag = {};
function Tag(config) {
KEYS.forEach(assert_exists, config);
m8.copy(this, config);
tag[this.start] = this;
}
function assert_exists(k) {
if (!(k in this)) {
throw new TypeError(format("A Templ8 Tag requires an {0}", ERRORS[k]));
}
}
this.all = function() {
return m8.copy(tag);
};
this.compileRegExp = function() {
var end = [], start = [], t;
for (t in tag) {
end.push(escapeRE(tag[t].end.substring(0, 1)));
start.push(escapeRE(tag[t].start.substring(1)));
}
return re_split_tpl = new RegExp("(\\{[" + start.join("") + "])\\s*(.+?)\\s*([" + end.join("") + "]\\})", "gm");
};
this.create = function(o, dont_compile) {
new Tag(o);
dont_compile === true || this.compileRegExp();
return this;
};
this.get = function(id) {
return tag[id];
};
};
var _tags = [ {
start : "{{",
end : "}}",
emit : function(internals, ctx, str, tpl_parts) {
var parts, statement, tag, val;
if (str == "") throw new SyntaxError("Templ8 missing key in value declaration.");
!re_one_liner_test.test(str) || (parts = contains(str, "|") ? (str.match(re_one_liner_simple) || dummy_arr).filter(not_empty) : str.match(re_one_liner_simple));
if (!parts || parts.length <= 2) return internals.wrap(internals.formatstatement(ctx, str));
parts.shift();
val = internals.formatstatement(ctx, parts.shift());
tag = getStatement(parts.shift().toLowerCase());
statement = parts.join(" ");
if (!tag || !statement) throw new SyntaxError("Templ8 missing tag or statement in one liner value declaration.");
return tag(internals, ctx, statement, tpl_parts) + internals.wrap(val) + getStatement("endif");
}
}, {
start : "{%",
end : "%}",
emit : function(internals, ctx, str, tpl_parts) {
if (str == "") throw new SyntaxError("Templ8 missing key in statement declaration.");
var parts, statement, tag;
if (!(tag = getStatement(str.toLowerCase()))) {
parts = str.split(" ");
tag = getStatement(parts.shift().toLowerCase());
if (parts.length == 0 && typeof tag == "string") return tag;
statement = parts.join(" ");
if (!tag || !statement) throw new SyntaxError("Templ8 missing tag or statement in statement declaration.");
}
if (!tag) throw new SyntaxError(format("Templ8 tag: {0} does not exist.", tag));
return typeof tag == "function" ? tag(internals, ctx, statement, tpl_parts) : tag;
}
}, {
start : "{[",
end : "]}",
emit : function(internals, ctx, str, tpl_parts) {
str = str.replace(re_comma_spacing, "$1").split("for each");
var expr, expr_type, iter, keys, statement = internals.clean(str.shift()), parts = internals.clean(str.pop()).match(re_comprehension_split);
str = [];
parts.shift();
keys = parts.shift();
iter = parts.shift();
if (parts.length >= 2) {
expr_type = parts.shift();
expr = parts.shift();
}
str.push(getStatement("for")(internals, ctx, (not_empty(keys) ? keys.match(re_keys, "$1").join(",") + " in " : "") + iter, tpl_parts));
!expr || str.push(getStatement(expr_type || "if")(internals, ctx, expr, tpl_parts));
str.push(internals.wrap(statement.split(" ").map(function(s) {
return internals.formatstatement(ctx, s);
}).join(" ")));
!expr || str.push(getStatement("endif"));
str.push(getStatement("endfor")(internals, ctx));
return str.join("");
}
}, {
start : "{:",
end : ":}",
emit : function(internals, ctx, str) {
return internals.formatstatement(ctx, str) + ";";
}
}, {
start : "{#",
end : "#}",
emit : function(internals, ctx, str) {
return [ "\n/*", str, "*/\n" ].join(" ");
}
} ], dummy_arr = [], getStatement = Templ8.Statement.get, re_comma_spacing = /\s*(,)\s*/g, re_comprehension_split = /^\(\s*(.*?)(?:\bin\b){0,1}(.*?)\s*\)\s*(if|unless){0,1}\s*(.*)$/i, re_keys = /(\w+)/g, re_one_liner_simple = /^(.*?)\s+(if|unless)\s+(.*)|$/i, re_one_liner_test = /\s+(if|unless)\s+/i;
_tags.forEach(function(tag) {
Templ8.Tag.create(tag, true);
});
Templ8.Tag.compileRegExp();
(function() {
var _statements = {
"for" : function(internals, ctx, statement) {
var undef = "U", count = undef, iter, keys, parts = internals.clean(statement).match(re_for_split), start = undef, str = [];
if (parts === null) iter = statement; else {
parts.shift();
count = parts.pop() || undef;
start = parts.pop() || undef;
iter = parts.pop() || parts.pop();
keys = (parts.pop() || "").match(re_keys);
}
iter = internals.formatstatement(ctx, iter);
str.push(format([ "", "iter = new Iter( {0}, iter, {1}, {2} );", "while ( iter.hasNext() ) {", "$_ = iter.current;" ].join("\n\r"), iter, start, count));
if (keys && keys.length > 0) {
ctx.currentIterKeys.unshift(keys);
if (keys.length < 2) str.push(format("var {0} = iter.current;\n\r", keys[0])); else if (keys.length >= 2) str.push(format("var {0} = iter.key, {1} = iter.current;\n\r", keys[0], keys[1]));
}
return str.join("");
},
forempty : "\n\r}\n\rif ( iter.empty ) {\n\r",
endfor : function(internals, ctx) {
ctx.currentIterKeys.shift();
return format([ "\n\r}", "iter = iter.parent || new Iter( null );", "$_ = iter.current || $C.current(); \n\r" ].join("\n\r"), internals.fnvar.util);
},
"if" : function(internals, ctx, statement) {
return format("if ( {0} ) { ", formatStatement(ctx, internals.formatstatement, statement));
},
elseif : function(internals, ctx, statement) {
return format(" } else if ( {0} ) { ", formatStatement(ctx, internals.formatstatement, statement));
},
"else" : " } else { ",
endif : " }",
sub : function(internals, ctx, statement, tpl_parts) {
var end = "endsub", i, id = statement.trim(), parts, sub_tpl;
i = tpl_parts.indexOf([ end, id ].join(" "));
i > -1 || (i = tpl_parts.indexOf(end));
parts = tpl_parts.splice(0, i + 1);
parts.splice(parts.length - 2, parts.length);
id = format("{0}.{1}", ctx.id, id);
sub_tpl = new Templ8("", m8.copy({
debug : ctx.debug,
fallback : ctx.fallback,
id : id
}, ctx.filters));
sub_tpl.currentIterKeys = [];
sub_tpl.__tpl__ = parts.join("");
sub_tpl._parse = internals.compiletpl(sub_tpl, internals.assembleparts(sub_tpl, parts));
delete sub_tpl.currentIterKeys;
sub_tpl.compiled = true;
return "";
},
unless : function(internals, ctx, statement) {
return format("if ( !( {0} ) ) { ", formatStatement(ctx, internals.formatstatement, statement));
}
}, re_for_split = /^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d+)\.+(\d*)]*\]?){0,1}/i, re_keys = /(\w+)/g;
function formatStatement(ctx, fmt, stmt) {
return stmt.split(" ").map(function(s) {
return fmt(ctx, s);
}).join(" ");
}
Templ8.Statement.add(_statements);
Templ8.Statement.add("elsif", _statements.elseif);
})();
Templ8.Filter.add({
capitalize : function(str) {
str = Templ8.stringify(str);
return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
},
count : function(o) {
return m8.len(o) || 0;
},
crop : function(str, i) {
str = Templ8.stringify(str);
i = parseInt(i, 10) || 50;
return str.length > i ? str.substring(0, i / 2) + "..." + str.substring(str.length - i / 2) : str;
},
def : function(str, def) {
return ba.blank(str) ? def : str;
},
first : function(o) {
switch (m8.nativeType(o)) {
case "array":
return o[0];
case "string":
return o.charAt(0);
}
},
join : function(o, s) {
return m8.got(o, "join") && typeof o.join == "function" ? o.join(s) : o;
},
last : function(o) {
switch (m8.nativeType(o)) {
case "array":
return o[o.length - 1];
case "string":
return o.charAt(o.length - 1);
}
},
lowercase : function(str) {
return Templ8.stringify(str).toLowerCase();
},
prefix : function(str1, str2) {
return str2 + str1;
},
suffix : function(str1, str2) {
return str1 + str2;
},
truncate : function(str, i) {
str = Templ8.stringify(str);
i = parseInt(i, 10) || 50;
return str.length > i ? str.substring(0, i) + "..." : str;
},
uppercase : function(str) {
return Templ8.stringify(str).toUpperCase();
},
wrap : function(str, start, end) {
return start + str + (end || start);
}
});
m8.ENV != "commonjs" ? m8.def(m8.global, "Templ8", m8.describe({
value : Templ8
}, "r")) : module.exports = Templ8;
}(typeof m8 != "undefined" ? m8 : typeof require != "undefined" ? require("m8") : null);
;!function( util, Name, PACKAGE ) {
"use strict";
var U, RESERVED = '__ASSERT__ __CONTEXT__ __FILTER_ __OUTPUT__ __UTIL__ $_ document false global instanceof null true typeof undefined window'.split( ' ' ).reduce( function( o, k ) {
o[k] = true; return o;
}, util.obj() ),
RE_GSUB = /\$?\{([^\}\s]+)\}/g,
ba = {
blank : function( o ) { return util.empty( o ) || ( typeof o == 'string' && !o.trim() ); },
contains : contains,
endsWith : function( s, str ) {
s = String( s );
var n = s.length - str.length;
return n >= 0 && s.lastIndexOf( str ) == n;
},
empty : util.empty,
equals : function( o, v ) { return o == v },
exists : util.exists,
is : function( o, v ) { return o === v },
isEven : function( i ) { return !( parseInt( i, 10 ) & 1 ); },
isOdd : function( i ) { return !( parseInt( i, 10 ) & 1 ); },
isTPL : function( id ) { return !!( getTPL( format( tpl_sub, this.id, id ) ) || getTPL( id ) ); },
iterable : function( o ) { return util.iter( o ); },
notEmpty : not_empty,
startsWith : function( s, str ) { return String( s ).indexOf( str ) === 0; }
},
bf = {}, bu = {
objectify : function( v, k ) { var o = {}; o[k] = v; return o; },
parse : function( o, id, tpl ) {
id = String( id ).trim();
var d = [tpl[fn_var.dict], o],
t = getTPL( format( tpl_sub, this.id, id ) ) || getTPL( id );
d[fn_var.dict] = true;
return t ? t.parse( o ) : this.fallback;
},
stop : function( iter ) { iter.stop(); },
stringify : stringify,
type : function( o ) { return util.type( o ); }
},
cache_key = '__tpl_cs_cached_keys', cache_stack = '__tpl_cs_stack',
defaults = 'compiled debug dict fallback id'.split( ' ' ), delim = '<~>',
esc_chars = /([-\*\+\?\.\|\^\$\/\\\(\)[\]\{\}])/g, esc_val = '\\$1',
fn_var = { assert : '__ASSERT__', ctx : '__CONTEXT__', dict : '__dict__', filter : '__FILTER__', output : '__OUTPUT__', util : '__UTIL__' },
fn_end = format( 'return {0};\n ', fn_var.output ),
fn_start = '\n"use strict";\n' + format( 'var $C = new ContextStack( {0}, this.fallback, this.dict ), $_ = $C.current(), iter = new Iter( null ), {1} = "", U;', fn_var.ctx, fn_var.output ),
id_count = 999, internals, logger = 'console', // <= gets around jsLint
re_br = /[\n\r]/gm,
re_esc = /(['"])/g, re_format_delim = new RegExp( delim, 'gm' ),
re_new_line = /[\r\n]+/g, re_space = /\s+/g,
re_special_char = /[\(\)\[\]\{\}\?\*\+\/<>%&=!-]/, re_split_tpl,
re_statement_fix = /\.(\d+)(\.?)/g, re_statement_replacer = '[\'$1\']$2',
re_statement_split = new RegExp( '\\s*([^\\|]+(?:\\|[^\\|]+?)){0,}' + delim, 'g' ),
split_token = '<__SPLIT__TEMPLATE__HERE__>', split_replace = ['', '$1', '$2', ''].join( split_token ),
tpl = {}, tpl_id = 't8-anon-{0}', tpl_statement = '{0}["{1}"].call( this, {2}{3}, {4} )', tpl_sub = '{0}.{1}';
/*** START: Utility Functions ***/
function contains( o, k ) { return ( typeof o.indexOf == 'function' && !!~o.indexOf( k ) ) || util.got( o, k ) ; }
function escapeRE( s ) { return String( s ).replace( esc_chars, esc_val ); }
function format( s ) { return gsub( s, Array.coerce( arguments, 1 ) ); }
function getTPL( id ) { return tpl[id] || null; }
function gsub( s, o, pattern ) { return String( s ).replace( ( pattern || RE_GSUB ), function( m, p ) { return o[p] || ''; } ); }
function is_obj( o ) { return typeof o == 'object' && ( o.constructor === Object || o.constructor === U ); }
function mapc( a, fn, ctx ) {
fn || ( fn = util ); ctx || ( ctx = a );
var i = -1, l = a.length, res = [], v;
while ( ++i < l ) {
v = fn.call( ctx, a[i], i, a );
switch ( v ) {
case null : case U : break;
default : switch ( typeof v ) {
case 'string' : v.trim() === '' || res.push( v ); break;
case 'number' : isNaN( v ) || res.push( v ); break;
default : ( !util.iter( v ) || util.len( v ) ) || res.push( v ); break;
}
}
}
return res;
}
function not_empty( o ) { return !util.empty( o ); }
/*** END: Utility Functions ***/
/*** START: Classes used by compiled templates ***/
function ContextStack( dict, fallback ) {
this[cache_stack] = [];
this.push( util.global );
if ( fallback !== U ) {
this.hasFallback = true;
this.fallback = fallback;
}
switch( util.nativeType( dict ) ) {
case 'object' : this.push( dict );
break;
case 'array' : dict[fn_var.dict]
? dict.map( this.push, this ) : this.push( dict );
break;
default : !util.exists( dict ) || this.push( dict );
}
}
ContextStack.prototype = {
current : function ContextStack_current() { return ( this.top || this[cache_stack][0] ).dict; },
get : function ContextStack_get( key ) {
var ctx, stack = this[cache_stack], l = stack.length, val;
while ( l-- ) {
ctx = stack[l];
if ( key in ctx.cache ) return ctx.cache[key];
if ( ( val = ctx.dict[key] ) !== U || ( val = Object.value( ctx.dict, key ) ) !== U )
return ctx.cache[key] = val;
}
return this.hasFallback ? this.fallback : U;
},
pop : function ContextStack_pop() {
var dict = this[cache_stack].pop().dict;
this.top = this[cache_stack][this[cache_stack].length - 1];
return dict;
},
push : function ContextStack_push( dict ) {
this[cache_stack].push( this.top = { cache : util.obj(), dict : dict } );
return this;
}
};
function Iter( iter, parent, start, count ) {
var keys = Object.keys( iter = this._ = Object( iter ) ),
len = keys.length;
if ( !len ) return this.stop();
util.tostr( iter ) == '[object Object]' || ( keys = keys.map( Number ) );
this.empty = false;
this.count = isNaN( count ) ? len : count < 0 ? len + count : count > len ? len : count;
if ( start == 0 || isNaN( start ) ) {
this.firstIndex = 0;
this.index = -1;
}
else {
this.firstIndex = start;
this.index = start - 2;
}
this.index1 = this.index + 1;
this.lastIndex = this.count === len ? this.count - 1 : this.count;
this.keys = keys;
!( parent instanceof Iter ) || ( this.parent = parent );
}
Iter.prototype = {
empty : true,
hasNext : function Iter_hasNext() {
if ( this.stopped || this.empty ) return false;
++this.index < this.lastIndex || ( this.stop().isLast = true );
this.key = this.keys[this.index1++];
this.current = this.val = this._[this.key];
return this;
},
stop : function Iter_stop() {
this.stopped = true;
return this;
}
};
util.defs( Iter.prototype, { // todo: these aren't tested yet!
first : { get : function() { return this._[this.keys[this.firstKey]]; } },
last : { get : function() { return this._[this.keys[this.lastKey]]; } },
next : { get : function() { return this._[this.keys[this.nextKey]]; } },
prev : { get : function() { return this._[this.keys[this.prevKey]]; } },
nextIndex : { get : function() {
var i = this.index + 1;
return i <= this.lastIndex ? i : U;
} },
prevIndex : { get : function() {
var i = this.index - 1;
return i >= this.firstIndex ? i : U;
} },
firstKey : { get : function() { return this.keys[this.firstIndex]; } },
lastKey : { get : function() { return this.keys[this.lastIndex]; } },
nextKey : { get : function() { return this.keys[this.nextIndex]; } },
prevKey : { get : function() { return this.keys[this.prevIndex]; } }
}, 'r' );
/*** END: Classes used by compiled templates ***/
/*** START: create template methods ***/
function aggregatetNonEmpty( res, str ) {
util.empty( str ) || res.push( str );
return res;
}
function aggregateStatement( ctx, s ) {
return s.reduce( function( res, v, i, parts ) {
if ( i == 0 ) return wrapGetter( ctx, v );
var args = '', fn, j = v.indexOf( ':' );
if ( !!~j ) {
fn = v.substring( 0, j );
args = v.substring( j + 1 );
}
else fn = v;
!args || ( args = ', ' + args.split( ',' ).map( function( o ) { return wrapGetter( this, o ); }, ctx ).join( ', ' ) );
return format( tpl_statement, getFnParent( fn ), fn, wrapGetter( ctx, res ), args, fn_var.ctx );
}, '' );
}
function assembleParts( ctx, parts ) {
var fn = [fn_start], part;
while ( part = parts.shift() ) fn.push( emitTag( ctx, part, parts ) );
fn.push( fn_end );
return fn.join( '\r\n' );
}
function clean( str ) { return str.replace( re_format_delim, '' ).replace( re_new_line, '\n' ).replace( re_space, ' ' ).trim(); }
function compileTemplate( ctx, fn ) {
if ( ctx.debug && typeof util.global[logger] != 'undefined' ) {
util.global[logger].info( Name + ': ', ctx.id, ', source: ' ); util.global[logger].log( fn );
}
var func = ( new Function( 'root', 'ContextStack', 'Iter', fn_var.filter, fn_var.assert, fn_var.util, fn_var.ctx, fn ) ).bind( ctx, util.global, ContextStack, Iter, util.copy( ctx.filters, __Class__.Filter.all(), true ), ba, bu );
util.def( func, 'src', util.describe( fn, 'r' ) );
return func;
}
function createTemplate( ctx ) {
ctx.currentIterKeys = [];
var fn = compileTemplate( ctx, assembleParts( ctx, splitStr( ctx.__tpl__ ) ) );
delete ctx.currentIterKeys;
return fn;
}
function emitTag( ctx, part, parts ) {
var tag;
if ( tag = __Class__.Tag.get( part ) ) {
part = parts.shift();
return tag.emit( internals, ctx, part, parts );
}
return wrapStr( format( '"{0}"', part.replace( re_esc, "\\$1" ) ) );
}
function formatStatement( ctx, str ) {
str = clean( str );
switch ( str ) {
case 'AND' : return ' && ';
case 'OR' : return ' || ';
}
return contains( str, '|' ) || contains( str, delim ) ? ( ' ' + str + delim ).replace( re_statement_split, function( m ) {
return ba.blank( m ) || m == delim ? '' : aggregateStatement( ctx, clean( m ).split( '|' ) );
} ) : wrapGetter( ctx, str );
}
function getFnParent( fn ) { return ( ba[fn] ? fn_var.assert : bu[fn] ? fn_var.util : fn_var.filter ); }
function splitStr( str ) {
return str.replace( re_split_tpl, split_replace )
.split( split_token )
.reduce( aggregatetNonEmpty, [] );
}
function stringify( o, str ) {
switch ( typeof o ) {
case 'boolean' : case 'number' : case 'string' : return String( o );
default : switch ( util.nativeType( o ) ) {
case 'date' : return o.toDateString();
case 'array' : return mapc( o, stringify ).join( ', ' );
case 'object' : return cache_key in o
? stringify( o.dict ) : ( ( str = o.toString() ) != '[object Object]' )
? str : mapc( Object.values( o ), stringify ).join( ', ' );
default : switch ( util.type( o ) ) {
case 'htmlelement' : return o.outerHTML; //o.textContent || o.text || o.innerText;
case 'htmlcollection' : return mapc( Array.coerce( o ), function( el ) { return stringify( el ); } ).join( '\n' );
}
}
}
return '';
}
function usingIterKey( key ) { return this == key || ba.startsWith( this, key + '.' ); }
function usingIterKeys( keys, o ) { return keys.length ? keys.some( function( k ) { return k.some( usingIterKey, o ); } ) : 0; }
function wrapGetter( ctx, o ) {
var k = ctx.currentIterKeys || []; o = clean( o );
return ( contains( o, '.call(' )
|| re_special_char.test( o )
|| ( ba.startsWith( o, '"' ) && ba.endsWith( o, '"' ) )
|| ( ba.startsWith( o, "'" ) && ba.endsWith( o, "'" ) )
|| !isNaN( o ) )
? o : ( ba.startsWith( o, '$_.' ) || ba.startsWith( o, 'iter.' ) || ( k.length && usingIterKeys( k, o ) ) || o in RESERVED )
? o.replace( re_statement_fix, re_statement_replacer ) : format( '$C.get( "{0}" )', o );
}
function wrapStr( str ) { return format( '{0} += {1};', fn_var.output, str.replace( re_br, '\\n' ) ); }
// these will be passed to tags & statements for internal usage
internals = {
assembleparts : assembleParts, clean : clean, compiletpl : compileTemplate,
createtpl : createTemplate, emittag : emitTag, fnvar : fn_var,
formatstatement : formatStatement, get : wrapGetter, util : bu,
wrap : wrapStr
};
/*** END: create template methods ***/
/*** START: Templ8 constructor and prototype ***/
function __Class__() {
var a = Array.coerce( arguments ),
f = is_obj( a[a.length - 1] ) ? a.pop() : is_obj( a[0] ) ? a.shift() : null;
// take care of peeps who are too lazy or too ©ººL to use the "new" constructor...
if ( !( this instanceof __Class__ ) ) return is_obj( f ) ? new __Class__( a.join( '' ), f ) : new __Class__( a.join( '' ) );
!f || defaults.forEach( function( k ) {
if ( k in f ) { this[k] = f[k]; delete f[k]; }
}, this );
this.filters = f || {};
this.__tpl__ = a.join( '' );
tpl[$id( this )] = this;
if ( this.compiled ) {
this.compiled = false;
compile( this );
}
}
function $id( ctx ) {
ctx.id || ( ctx.id = format( tpl_id, ++id_count ) );
return ctx.id;
}
function compile( ctx ) {
if ( !ctx.compiled ) {
ctx.compiled = true;
ctx._parse = createTemplate( ctx );
}
return ctx;
}
function parse( dict ) {
this.compiled || compile( this );
this[fn_var.dict] = dict;
var s = this._parse( dict );
delete this[fn_var.dict];
return s;
}
__Class__.prototype = {
compiled : false, debug : false, dict : null, fallback : '',
parse : parse
};
/*** END: Templ8 constructor and prototype ***/
/*** START: Templ8 functionality packages ***/
// exposed for general usage
util.defs( __Class__, { // store a reference to m8 in Templ8 so we can do fun stuff in commonjs
m8 : { value : util }, // modules without having to re-request m8 as well as Templ8 each time.
escapeRE : escapeRE, format : format, get : getTPL,
gsub : gsub, stringify : stringify
}, 'r' );
function Mgr( o ) {
var cache = {};
!is_obj( o ) || util.copy( cache, o );
function _add( id, fn, replace ) { ( !replace && id in cache ) || ( cache[id] = fn ); }
function add( replace, o ) {
switch( typeof o ) {
case 'string' : _add( o, arguments[2], replace ); break;
case 'object' : for ( var k in o ) _add( k, o[k], replace ); break;
} return this;
}
this.all = function() { return util.copy( cache ); };
this.add = function() { return add.call( this, false, arguments[0], arguments[1] ); };
this.get = function( id ) { return cache[id]; };
this.replace = function() { return add.call( this, true, arguments[0], arguments[1] ); };
}
__Class__.Assert = new Mgr( ba );
__Class__.Filter = new Mgr( bf );
__Class__.Statement = new Mgr;
__Class__.Tag = new function() {
var KEYS = 'emit end start'.split( ' ' ),
ERRORS = {
emit : 'emit function',
end : 'end tag definition',
start : 'start tag definition'
},
tag = {};
function Tag( config ) {
KEYS.forEach( assert_exists, config );
util.copy( this, config );
tag[this.start] = this;
}
function assert_exists( k ) { if ( !( k in this ) ) { throw new TypeError( format( 'A ' + Name + ' Tag requires an {0}', ERRORS[k] ) ); } }
this.all = function() { return util.copy( tag ); };
this.compileRegExp = function() {
var end = [], start = [], t;
for ( t in tag ) {
end.push( escapeRE( tag[t].end.substring( 0, 1 ) ) );
start.push( escapeRE( tag[t].start.substring( 1 ) ) );
}
return ( re_split_tpl = new RegExp( '(\\{[' + start.join( '' ) + '])\\s*(.+?)\\s*([' + end.join( '' ) + ']\\})', 'gm' ) );
};
this.create = function( o, dont_compile ) {
new Tag( o ); dont_compile === true || this.compileRegExp();
return this;
};
this.get = function( id ) { return tag[id]; };
};
/*** END: Templ8 functionality packages ***/
var _tags = [ {
start : '{{', end : '}}',
emit : function( internals, ctx, str, tpl_parts ) {
var parts, statement, tag, val;
if ( str == '' ) throw new SyntaxError( Name + ' missing key in value declaration.' );
// 1st re_one_liner_simple used to be re_one_liner, but fails in V8!!!
!re_one_liner_test.test( str ) || ( parts = contains( str, '|' ) ? ( str.match( re_one_liner_simple ) || dummy_arr ).filter( not_empty ) : str.match( re_one_liner_simple ) );
if ( !parts || parts.length <= 2 ) return internals.wrap( internals.formatstatement( ctx, str ) );
parts.shift(); // the original string
val = internals.formatstatement( ctx, parts.shift() );
tag = getStatement( parts.shift().toLowerCase() );
statement = parts.join( ' ' );
if ( !tag || !statement ) throw new SyntaxError( Name + ' missing tag or statement in one liner value declaration.' );
return tag( internals, ctx, statement, tpl_parts ) + internals.wrap( val ) + getStatement( 'endif' );
}
}, {
start : '{%', end : '%}',
emit : function( internals, ctx, str, tpl_parts ) {
if ( str == '' ) throw new SyntaxError( Name + ' missing key in statement declaration.' );
var parts, statement, tag;
if ( !( tag = getStatement( str.toLowerCase() ) ) ) {
parts = str.split( ' ' );
tag = getStatement( parts.shift().toLowerCase() );
if ( parts.length == 0 && typeof tag == 'string' ) return tag;
statement = parts.join( ' ' );
if ( !tag || !statement ) {
parts = [];
tag || parts.push( 'tag' );
statement || parts.push( 'statement' );
throw new SyntaxError( Name + ' missing ' + parts.join( ' and ' ) + ' in statement declaration.' );
}
}
if ( !tag ) throw new SyntaxError( format( Name + ' tag: {0} does not exist.', tag ) );
return typeof tag == 'function' ? tag( internals, ctx, statement, tpl_parts ) : tag;
}
}, {
start : '{[', end : ']}',
emit : function( internals, ctx, str, tpl_parts ) {
str = str.replace( re_comma_spacing, '$1' ).split( 'for each' );
var expr, expr_type, iter, keys,
statement = internals.clean( str.shift() ),
parts = internals.clean( str.pop() ).match( re_comprehension_split );
str = []; parts.shift(); // original s(tr)in(g)
keys = parts.shift(); iter = parts.shift();
if ( parts.length >= 2 ) {
expr_type = parts.shift();
expr = parts.shift();
}
str.push( getStatement( 'for' )( internals, ctx, ( ( not_empty( keys ) ? keys.match( re_keys, '$1' ).join( ',' ) + ' in ' : '' ) + iter ), tpl_parts ) );
!expr || str.push( getStatement( expr_type || 'if' )( internals, ctx, expr, tpl_parts ) );
str.push( internals.wrap( statement.split( ' ' ).map( function( s ) { return internals.formatstatement( ctx, s ); } ).join( ' ' ) ) );
!expr || str.push( getStatement( 'endif' ) );
str.push( getStatement( 'endfor' )( internals, ctx ) );
return str.join( '' );
}
}, {
start : '{:', end : ':}',
emit : function( internals, ctx, str ) { return internals.formatstatement( ctx, str ) + ';'; }
}, {
start : '{#', end : '#}',
emit : function( internals, ctx, str ) { return ['\n\/*', str, '*\/\n'].join( ' ' ); }
} ],
dummy_arr = [],
getStatement = __Class__.Statement.get,
re_comma_spacing = /\s*(,)\s*/g,
re_comprehension_split = /^\(\s*(.*?)(?:\bin\b){0,1}(.*?)\s*\)\s*(if|unless){0,1}\s*(.*)$/i,
re_keys = /(\w+)/g,
// re_one_liner = /^(\$_|[^\|]+(?:\|[^\|]+?){0,}|"[^"]+"|[\w\.\[\]"]+)(?:\s+(if|unless)\s+(.*)){0,1}$/i,
re_one_liner_simple = /^(.*?)\s+(if|unless)\s+(.*)|$/i,
re_one_liner_test = /\s+(if|unless)\s+/i;
_tags.forEach( function( tag ) { __Class__.Tag.create( tag, true ); } );
__Class__.Tag.compileRegExp();
( function() {
var _statements = {
'for' : function( internals, ctx, statement ) {
var undef = 'U', count = undef, iter, keys,
parts = internals.clean( statement ).match( re_for_split ),
start = undef, str = [];
if ( parts === null ) iter = statement;
else {
parts.shift();
count = parts.pop() || undef;
start = parts.pop() || undef;
iter = parts.pop() || parts.pop();
keys = ( parts.pop() || '' ).match( re_keys );
}
iter = internals.formatstatement( ctx, iter );
str.push( format( ['',
'iter = new Iter( {0}, iter, {1}, {2} );',
'while ( iter.hasNext() ) {',
'$_ = iter.current;'].join( '\n\r' ), iter, start, count ) );
if ( keys && keys.length > 0 ) {
ctx.currentIterKeys.unshift( keys );
if ( keys.length < 2 ) str.push( format( 'var {0} = iter.current;\n\r', keys[0] ) );
else if ( keys.length >= 2 ) str.push( format( 'var {0} = iter.key, {1} = iter.current;\n\r', keys[0], keys[1] ) );
}
return str.join( '' );
},
'forempty' : '\n\r}\n\rif ( iter.empty ) {\n\r',
'endfor' : function( internals, ctx ) {
ctx.currentIterKeys.shift();
return format( ['\n\r}',
'iter = iter.parent || new Iter( null );',
'$_ = iter.current || $C.current(); \n\r'].join( '\n\r' ), internals.fnvar.util );
},
'if' : function( internals, ctx, statement ) { return format( 'if ( {0} ) { ', formatStatement( ctx, internals.formatstatement, statement ) ); },
'elseif' : function( internals, ctx, statement ) { return format( ' } else if ( {0} ) { ', formatStatement( ctx, internals.formatstatement, statement ) ); },
'else' : ' } else { ',
'endif' : ' }',
'sub' : function( internals, ctx, statement, tpl_parts ) {
var end = 'endsub', i, id = statement.trim(), parts, sub_tpl;
i = tpl_parts.indexOf( [end, id].join( ' ' ) );
i > -1 || ( i = tpl_parts.indexOf( end ) );
parts = tpl_parts.splice( 0, i + 1 );
parts.splice( parts.length - 2, parts.length );
id = format( '{0}.{1}', ctx.id, id );
sub_tpl = new __Class__( '', util.copy( { debug : ctx.debug, fallback : ctx.fallback, id : id }, ctx.filters ) );
// the parts have already been split, for efficiency we can skip a call to createTemplate() and the more costly splitStr()
sub_tpl.currentIterKeys = [];
sub_tpl.__tpl__ = parts.join( '' );
sub_tpl._parse = internals.compiletpl( sub_tpl, internals.assembleparts( sub_tpl, parts ) );
delete sub_tpl.currentIterKeys;
sub_tpl.compiled = true;
return '';
},
'unless' : function( internals, ctx, statement ) { return format( 'if ( !( {0} ) ) { ', formatStatement( ctx, internals.formatstatement, statement ) ); }
},
re_for_split = /^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d+)\.+(\d*)]*\]?){0,1}/i,
re_keys = /(\w+)/g;
function formatStatement( ctx, fmt, stmt ) { return stmt.split( ' ' ).map( function( s ) { return fmt( ctx, s ); } ).join( ' ' ); }
__Class__.Statement.add( _statements );
__Class__.Statement.add( 'elsif', _statements.elseif );
}() );
__Class__.Filter.add( {
capitalize : function( str ) {
str = __Class__.stringify( str );
return str.charAt( 0 ).toUpperCase() + str.substring( 1 ).toLowerCase();
},
count : function( o ) { return util.len( o ) || 0; },
crop : function( str, i ) {
str = __Class__.stringify( str );
i = parseInt( i, 10 ) || 50;
return str.length > i ? str.substring( 0, i / 2 ) + '...' + str.substring( str.length - ( i / 2 ) ) : str;
},
def : function( str, def ) { return ba.blank( str ) ? def : str; },
first : function( o ) {
switch ( util.nativeType( o ) ) {
case 'array' : return o[0];
case 'string' : return o.charAt( 0 );
}
},
join : function( o, s ) { return util.got( o, 'join' ) && typeof o.join == 'function' ? o.join( s ) : o; },
last : function( o ) {
switch ( util.nativeType( o ) ) {
case 'array' : return o[o.length-1];
case 'string' : return o.charAt( o.length - 1 );
}
},
lowercase : function( str ) { return __Class__.stringify( str ).toLowerCase(); },
prefix : function( str1, str2 ) { return str2 + str1; },
suffix : function( str1, str2 ) { return str1 + str2; },
truncate : function( str, i ) {
str = __Class__.stringify( str );
i = parseInt( i, 10 ) || 50;
return str.length > i ? str.substring( 0, i ) + '...' : str;
},
uppercase : function( str ) { return __Class__.stringify( str ).toUpperCase(); },
wrap : function( str, start, end ) { return start + str + ( end || start ); }
} );
util.iter( PACKAGE ) || ( PACKAGE = util.ENV == 'commonjs' ? module : util.global );
// expose Templ8
__Class__ = util.expose( __Class__, Name, PACKAGE );
util.expose( util, __Class__ ); // store a reference to m8 on Templ8
// at this point we don't know if m8 is available or not, and as such do not know what environment we are in.
// so, we check and do what is required.
}( typeof m8 != 'undefined' ? m8 : typeof require != 'undefined' ? require( 'm8' ) : null, 'Templ8' );

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

!function(a){function J(b,c){return typeof b.indexOf=="function"&&!!~b.indexOf(c)||a.got(b,c)}function K(a){return String(a).replace(l,m)}function L(a){return N(a,Array.coerce(arguments,1))}function M(a){return F[a]||null}function N(a,b,c){return String(a).replace(c||d,function(a,c){return b[c]||""})}function O(a){return typeof a=="object"&&(a.constructor===Object||a.constructor===b)}function P(c,d,e){d||(d=a),e||(e=c);var f=-1,g=c.length,h=[],i;while(++f<g){i=d.call(e,c[f],f,c);switch(i){case null:case b:break;default:switch(typeof i){case"string":i.trim()===""||h.push(i);break;case"number":isNaN(i)||h.push(i);break;default:!a.iter(i)||a.len(i)||h.push(i)}}}return h}function Q(b){return!a.empty(b)}function R(c,d,e){this[i]=[],this.push(a.global),d!==b&&(this.hasFallback=!0,this.fallback=d),!a.exists(c)||this.push(c)}function S(b,c,d,e){var f=Object.keys(b=this._=Object(b)),g=f.length;if(!g)return this.stop();a.tostr(b)=="[object Object]"||(f=f.map(Number)),this.empty=!1,this.count=isNaN(e)?g:e<0?g+e:e>g?g:e,d==0||isNaN(d)?(this.firstIndex=0,this.index=-1):(this.firstIndex=d,this.index=d-2),this.index1=this.index+1,this.lastIndex=this.count===g?this.count-1:this.count,this.keys=f,!(c instanceof S)||(this.parent=c)}function T(b,c){return a.empty(c)||b.push(c),b}function U(a,b){return b.reduce(function(b,c,d,e){if(d==0)return be(a,c);var f="",g,h=c.indexOf(":");return~h?(g=c.substring(0,h),f=c.substring(h+1)):g=c,!f||(f=", "+f.split(",").map(function(a){return be(this,a)},a).join(", ")),L(H,_(g),g,be(a,b),f,n.dict)},"")}function V(a,b){var c=[p],d;while(d=b.shift())c.push(Z(a,d,b));return c.push(o),c.join("\r\n")}function W(a){return a.replace(v,"").replace(w,"\n").replace(x," ").trim()}function X(b,c){b.debug&&typeof a.global[s]!="undefined"&&(a.global[s].info("Templ8: ",b.id,", source: "),a.global[s].log(c));var d=(new Function("root","ContextStack","Iter",n.filter,n.assert,n.util,n.dict,c)).bind(b,a.global,R,S,a.copy(b.filters,bg.Filter.all(),!0),e,g);return a.def(d,"src",a.describe(c,"r")),d}function Y(a){a.currentIterKeys=[];var b=X(a,V(a,ba(a.__tpl__)));return delete a.currentIterKeys,b}function Z(a,b,c){var d;return(d=bg.Tag.get(b))?(b=c.shift(),d.emit(r,a,b,c)):bf(L('"{0}"',b.replace(u,"\\$1")))}function $(a,b){b=W(b);switch(b){case"AND":return" && ";case"OR":return" || "}return J(b,"|")||J(b,k)?(" "+b+k).replace(C,function(b){return e.blank(b)||b==k?"":U(a,W(b).split("|"))}):be(a,b)}function _(a){return e[a]?n.assert:g[a]?n.util:n.filter}function ba(a){return a.replace(z,E).split(D).reduce(T,[])}function bb(b,c){switch(typeof b){case"boolean":case"number":case"string":return String(b);default:switch(a.nativeType(b)){case"date":return b.toDateString();case"array":return P(b,bb).join(", ");case"object":return h in b?bb(b.dict):(c=b.toString())!="[object Object]"?c:P(Object.values(b),bb).join(", ");default:switch(a.type(b)){case"htmlelement":return b.outerHTML;case"htmlcollection":return P(Array.coerce(b),function(a){return bb(a)}).join("\n")}}}return""}function bc(a){return this==a||e.startsWith(this,a+".")}function bd(a,b){return a.length?a.some(function(a){return a.some(bc,b)}):0}function be(a,b){var d=a.currentIterKeys||[];return b=W(b),J(b,".call(")||y.test(b)||e.startsWith(b,'"')&&e.endsWith(b,'"')||e.startsWith(b,"'")&&e.endsWith(b,"'")||!isNaN(b)?b:e.startsWith(b,"$_.")||e.startsWith(b,"iter.")||d.length&&bd(d,b)||b in c?b.replace(A,B):L('$C.get( "{0}" )',b)}function bf(a){return L("{0} += {1};",n.output,a.replace(t,"\\n"))}function bg(){var a=Array.coerce(arguments),b=O(a[a.length-1])?a.pop():O(a[0])?a.shift():null;if(!(this instanceof bg))return O(b)?new bg(a.join(""),b):new bg(a.join(""));!b||j.forEach(function(a){a in b&&(this[a]=b[a],delete b[a])},this),this.filters=b||{},this.__tpl__=a.join(""),F[bh(this)]=this,this.compiled&&(this.compiled=!1,bi(this))}function bh(a){return a.id||(a.id=L(G,++q)),a.id}function bi(a){return a.compiled||(a.compiled=!0,a._parse=Y(a)),a}function bj(a){this.compiled||bi(this),this.__dict__=a;var b=this._parse(a);return delete this.__dict__,b}function bk(b){function d(a,b,d){!d&&a in c||(c[a]=b)}function e(a,b){switch(typeof b){case"string":d(b,arguments[2],a);break;case"object":for(var c in b)d(c,b[c],a)}return this}var c={};!O(b)||a.copy(c,b),this.all=function(){return a.copy(c)},this.add=function(){return e.call(this,!1,arguments[0],arguments[1])},this.get=function(a){return c[a]},this.replace=function(){return e.call(this,!0,arguments[0],arguments[1])}}"use strict";var b,c="__ASSERT__ __CONTEXT__ __FILTER_ __OUTPUT__ __UTIL__ $_ document false global instanceof null true typeof undefined window".split(" ").reduce(function(a,b){return a[b]=!0,a},a.obj()),d=/\$?\{([^\}\s]+)\}/g,e={blank:function(b){return a.empty(b)||typeof b=="string"&&!b.trim()},contains:J,endsWith:function(a,b){a=String(a);var c=a.length-b.length;return c>=0&&a.lastIndexOf(b)==c},empty:a.empty,equals:function(a,b){return a==b},exists:a.exists,is:function(a,b){return a===b},isEven:function(a){return!(parseInt(a,10)&1)},isOdd:function(a){return!(parseInt(a,10)&1)},isTPL:function(a){return!!M(L(I,this.id,a))||!!M(a)},iterable:function(b){return a.iter(b)},notEmpty:Q,startsWith:function(a,b){return String(a).indexOf(b)===0}},f={},g={objectify:function(a,b){var c={};return c[b]=a,c},parse:function(b,c,d){c=String(c).trim();var e=M(L(I,this.id,c))||M(c);if(O(b)&&d!==this.__dict__){switch(a.nativeType(d)){case"object":break;case"null":case"undefined":d={};break;default:d={__MIXINS__:d}}b=a.copy(d,b,!0)}return e?e.parse(b):this.fallback},stop:function(a){a.stop()},stringify:bb,type:function(b){return a.type(b)}},h="__tpl_cs_cached_keys",i="__tpl_cs_stack",j="compiled debug dict fallback id".split(" "),k="<~>",l=/([-\*\+\?\.\|\^\$\/\\\(\)[\]\{\}])/g,m="\\$1",n={assert:"__ASSERT__",dict:"__CONTEXT__",filter:"__FILTER__",output:"__OUTPUT__",util:"__UTIL__"},o=L("return {0};\n ",n.output),p='\n"use strict";\n'+L('var $C = new ContextStack( {0}, this.fallback, this.dict ), $_ = $C.current(), iter = new Iter( null ), {1} = "", U;',n.dict,n.output),q=999,r,s="console",t=/[\n\r]/gm,u=/(['"])/g,v=new RegExp(k,"gm"),w=/[\r\n]+/g,x=/\s+/g,y=/[\(\)\[\]\{\}\?\*\+\/<>%&=!-]/,z,A=/\.(\d+)(\.?)/g,B="['$1']$2",C=new RegExp("\\s*([^\\|]+(?:\\|[^\\|]+?)){0,}"+k,"g"),D="<__SPLIT__TEMPL8__HERE__>",E=["","$1","$2",""].join(D),F={},G="t8-anon-{0}",H='{0}["{1}"].call( this, {2}{3}, {4} )',I="{0}.{1}";R.prototype={current:function(){return(this.top||this[i][0]).dict},get:function(c){var d,e=this[i],f=e.length,g;while(f--){d=e[f];if(c in d.cache)return d.cache[c];if((g=d.dict[c])!==b||(g=Object.value(d.dict,c))!==b)return d.cache[c]=g}return this.hasFallback?this.fallback:b},pop:function(){var b=this[i].pop().dict;return this.top=this[i][this[i].length-1],b},push:function(c){return this[i].push(this.top={cache:a.obj(),dict:c}),this}},S.prototype={empty:!0,hasNext:function(){return this.stopped||this.empty?!1:(++this.index<this.lastIndex||(this.stop().isLast=!0),this.key=this.keys[this.index1++],this.current=this.val=this._[this.key],this)},stop:function(){return this.stopped=!0,this}},a.defs(S.prototype,{first:{get:function(){return this._[this.keys[this.firstKey]]}},last:{get:function(){return this._[this.keys[this.lastKey]]}},next:{get:function(){return this._[this.keys[this.nextKey]]}},prev:{get:function(){return this._[this.keys[this.prevKey]]}},nextIndex:{get:function(){var a=this.index+1;return a<=this.lastIndex?a:b}},prevIndex:{get:function(){var a=this.index-1;return a>=this.firstIndex?a:b}},firstKey:{get:function(){return this.keys[this.firstIndex]}},lastKey:{get:function(){return this.keys[this.lastIndex]}},nextKey:{get:function(){return this.keys[this.nextIndex]}},prevKey:{get:function(){return this.keys[this.prevIndex]}}},"r"),r={assembleparts:V,clean:W,compiletpl:X,createtpl:Y,emittag:Z,fnvar:n,formatstatement:$,get:be,util:g,wrap:bf},bg.prototype={compiled:!1,debug:!1,dict:null,fallback:"",parse:bj},a.defs(bg,{m8:{value:a},escapeRE:K,format:L,get:M,gsub:N,stringify:bb},"r"),bg.Assert=new bk(e),bg.Filter=new bk(f),bg.Statement=new bk,bg.Tag=new function(){function e(c){b.forEach(f,c),a.copy(this,c),d[this.start]=this}function f(a){if(!(a in this))throw new TypeError(L("A Templ8 Tag requires an {0}",c[a]))}var b="emit end start".split(" "),c={emit:"emit function",end:"end tag definition",start:"start tag definition"},d={};this.all=function(){return a.copy(d)},this.compileRegExp=function(){var a=[],b=[],c;for(c in d)a.push(K(d[c].end.substring(0,1))),b.push(K(d[c].start.substring(1)));return z=new RegExp("(\\{["+b.join("")+"])\\s*(.+?)\\s*(["+a.join("")+"]\\})","gm")},this.create=function(a,b){return new e(a),b===!0||this.compileRegExp(),this},this.get=function(a){return d[a]}};var bl=[{start:"{{",end:"}}",emit:function(a,b,c,d){var e,f,g,h;if(c=="")throw new SyntaxError("Templ8 missing key in value declaration.");!bs.test(c)||(e=J(c,"|")?(c.match(br)||bm).filter(Q):c.match(br));if(!e||e.length<=2)return a.wrap(a.formatstatement(b,c));e.shift(),h=a.formatstatement(b,e.shift()),g=bn(e.shift().toLowerCase()),f=e.join(" ");if(!g||!f)throw new SyntaxError("Templ8 missing tag or statement in one liner value declaration.");return g(a,b,f,d)+a.wrap(h)+bn("endif")}},{start:"{%",end:"%}",emit:function(a,b,c,d){if(c=="")throw new SyntaxError("Templ8 missing key in statement declaration.");var e,f,g;if(!(g=bn(c.toLowerCase()))){e=c.split(" "),g=bn(e.shift().toLowerCase());if(e.length==0&&typeof g=="string")return g;f=e.join(" ");if(!g||!f)throw new SyntaxError("Templ8 missing tag or statement in statement declaration.")}if(!g)throw new SyntaxError(L("Templ8 tag: {0} does not exist.",g));return typeof g=="function"?g(a,b,f,d):g}},{start:"{[",end:"]}",emit:function(a,b,c,d){c=c.replace(bo,"$1").split("for each");var e,f,g,h,i=a.clean(c.shift()),j=a.clean(c.pop()).match(bp);return c=[],j.shift(),h=j.shift(),g=j.shift(),j.length>=2&&(f=j.shift(),e=j.shift()),c.push(bn("for")(a,b,(Q(h)?h.match(bq,"$1").join(",")+" in ":"")+g,d)),!e||c.push(bn(f||"if")(a,b,e,d)),c.push(a.wrap(i.split(" ").map(function(c){return a.formatstatement(b,c)}).join(" "))),!e||c.push(bn("endif")),c.push(bn("endfor")(a,b)),c.join("")}},{start:"{:",end:":}",emit:function(a,b,c){return a.formatstatement(b,c)+";"}},{start:"{#",end:"#}",emit:function(a,b,c){return["\n/*",c,"*/\n"].join(" ")}}],bm=[],bn=bg.Statement.get,bo=/\s*(,)\s*/g,bp=/^\(\s*(.*?)(?:\bin\b){0,1}(.*?)\s*\)\s*(if|unless){0,1}\s*(.*)$/i,bq=/(\w+)/g,br=/^(.*?)\s+(if|unless)\s+(.*)|$/i,bs=/\s+(if|unless)\s+/i;bl.forEach(function(a){bg.Tag.create(a,!0)}),bg.Tag.compileRegExp(),function(){function e(a,b,c){return c.split(" ").map(function(c){return b(a,c)}).join(" ")}var b={"for":function(a,b,e){var f="U",g=f,h,i,j=a.clean(e).match(c),k=f,l=[];return j===null?h=e:(j.shift(),g=j.pop()||f,k=j.pop()||f,h=j.pop()||j.pop(),i=(j.pop()||"").match(d)),h=a.formatstatement(b,h),l.push(L(["","iter = new Iter( {0}, iter, {1}, {2} );","while ( iter.hasNext() ) {","$_ = iter.current;"].join("\n\r"),h,k,g)),i&&i.length>0&&(b.currentIterKeys.unshift(i),i.length<2?l.push(L("var {0} = iter.current;\n\r",i[0])):i.length>=2&&l.push(L("var {0} = iter.key, {1} = iter.current;\n\r",i[0],i[1]))),l.join("")},forempty:"\n\r}\n\rif ( iter.empty ) {\n\r",endfor:function(a,b){return b.currentIterKeys.shift(),L(["\n\r}","iter = iter.parent || new Iter( null );","$_ = iter.current || $C.current(); \n\r"].join("\n\r"),a.fnvar.util)},"if":function(a,b,c){return L("if ( {0} ) { ",e(b,a.formatstatement,c))},elseif:function(a,b,c){return L(" } else if ( {0} ) { ",e(b,a.formatstatement,c))},"else":" } else { ",endif:" }",sub:function(b,c,d,e){var f="endsub",g,h=d.trim(),i,j;return g=e.indexOf([f,h].join(" ")),g>-1||(g=e.indexOf(f)),i=e.splice(0,g+1),i.splice(i.length-2,i.length),h=L("{0}.{1}",c.id,h),j=new bg("",a.copy({debug:c.debug,fallback:c.fallback,id:h},c.filters)),j.currentIterKeys=[],j.__tpl__=i.join(""),j._parse=b.compiletpl(j,b.assembleparts(j,i)),delete j.currentIterKeys,j.compiled=!0,""},unless:function(a,b,c){return L("if ( !( {0} ) ) { ",e(b,a.formatstatement,c))}},c=/^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d+)\.+(\d*)]*\]?){0,1}/i,d=/(\w+)/g;bg.Statement.add(b),bg.Statement.add("elsif",b.elseif)}(),bg.Filter.add({capitalize:function(a){return a=bg.stringify(a),a.charAt(0).toUpperCase()+a.substring(1).toLowerCase()},count:function(b){return a.len(b)||0},crop:function(a,b){return a=bg.stringify(a),b=parseInt(b,10)||50,a.length>b?a.substring(0,b/2)+"..."+a.substring(a.length-b/2):a},def:function(a,b){return e.blank(a)?b:a},first:function(b){switch(a.nativeType(b)){case"array":return b[0];case"string":return b.charAt(0)}},join:function(b,c){return a.got(b,"join")&&typeof b.join=="function"?b.join(c):b},last:function(b){switch(a.nativeType(b)){case"array":return b[b.length-1];case"string":return b.charAt(b.length-1)}},lowercase:function(a){return bg.stringify(a).toLowerCase()},prefix:function(a,b){return b+a},suffix:function(a,b){return a+b},truncate:function(a,b){return a=bg.stringify(a),b=parseInt(b,10)||50,a.length>b?a.substring(0,b)+"...":a},uppercase:function(a){return bg.stringify(a).toUpperCase()},wrap:function(a,b,c){return b+a+(c||b)}}),a.ENV!="commonjs"?a.def(a.global,"Templ8",a.describe({value:bg},"r")):module.exports=bg}(typeof m8!="undefined"?m8:typeof require!="undefined"?require("m8"):null)
!function(e,t,n){"use strict";function j(t,n){return typeof t.indexOf=="function"&&!!~t.indexOf(n)||e.got(t,n)}function F(e){return String(e).replace(p,d)}function I(e){return R(e,Array.coerce(arguments,1))}function q(e){return D[e]||null}function R(e,t,n){return String(e).replace(n||s,function(e,n){return t[n]||""})}function U(e){return typeof e=="object"&&(e.constructor===Object||e.constructor===r)}function z(t,n,i){n||(n=e),i||(i=t);var s=-1,o=t.length,u=[],a;while(++s<o){a=n.call(i,t[s],s,t);switch(a){case null:case r:break;default:switch(typeof a){case"string":a.trim()===""||u.push(a);break;case"number":isNaN(a)||u.push(a);break;default:!e.iter(a)||e.len(a)||u.push(a)}}}return u}function W(t){return!e.empty(t)}function X(t,n){this[l]=[],this.push(e.global),n!==r&&(this.hasFallback=!0,this.fallback=n);switch(e.nativeType(t)){case"object":this.push(t);break;case"array":t[v.dict]?t.map(this.push,this):this.push(t);break;default:!e.exists(t)||this.push(t)}}function V(t,n,r,i){var s=Object.keys(t=this._=Object(t)),o=s.length;if(!o)return this.stop();e.tostr(t)=="[object Object]"||(s=s.map(Number)),this.empty=!1,this.count=isNaN(i)?o:i<0?o+i:i>o?o:i,r==0||isNaN(r)?(this.firstIndex=0,this.index=-1):(this.firstIndex=r,this.index=r-2),this.index1=this.index+1,this.lastIndex=this.count===o?this.count-1:this.count,this.keys=s,!(n instanceof V)||(this.parent=n)}function $(t,n){return e.empty(n)||t.push(n),t}function J(e,t){return t.reduce(function(t,n,r,i){if(r==0)return ot(e,n);var s="",o,u=n.indexOf(":");return~u?(o=n.substring(0,u),s=n.substring(u+1)):o=n,!s||(s=", "+s.split(",").map(function(e){return ot(this,e)},e).join(", ")),I(H,tt(o),o,ot(e,t),s,v.ctx)},"")}function K(e,t){var n=[g],r;while(r=t.shift())n.push(Z(e,r,t));return n.push(m),n.join("\r\n")}function Q(e){return e.replace(x,"").replace(T,"\n").replace(N," ").trim()}function G(n,r){n.debug&&typeof e.global[w]!="undefined"&&(e.global[w].info(t+": ",n.id,", source: "),e.global[w].log(r));var i=(new Function("root","ContextStack","Iter",v.filter,v.assert,v.util,v.ctx,r)).bind(n,e.global,X,V,e.copy(n.filters,at.Filter.all(),!0),o,a);return e.def(i,"src",e.describe(r,"r")),i}function Y(e){e.currentIterKeys=[];var t=G(e,K(e,nt(e.__tpl__)));return delete e.currentIterKeys,t}function Z(e,t,n){var r;return(r=at.Tag.get(t))?(t=n.shift(),r.emit(b,e,t,n)):ut(I('"{0}"',t.replace(S,"\\$1")))}function et(e,t){t=Q(t);switch(t){case"AND":return" && ";case"OR":return" || "}return j(t,"|")||j(t,h)?(" "+t+h).replace(O,function(t){return o.blank(t)||t==h?"":J(e,Q(t).split("|"))}):ot(e,t)}function tt(e){return o[e]?v.assert:a[e]?v.util:v.filter}function nt(e){return e.replace(k,_).split(M).reduce($,[])}function rt(t,n){switch(typeof t){case"boolean":case"number":case"string":return String(t);default:switch(e.nativeType(t)){case"date":return t.toDateString();case"array":return z(t,rt).join(", ");case"object":return f in t?rt(t.dict):(n=t.toString())!="[object Object]"?n:z(Object.values(t),rt).join(", ");default:switch(e.type(t)){case"htmlelement":return t.outerHTML;case"htmlcollection":return z(Array.coerce(t),function(e){return rt(e)}).join("\n")}}}return""}function it(e){return this==e||o.startsWith(this,e+".")}function st(e,t){return e.length?e.some(function(e){return e.some(it,t)}):0}function ot(e,t){var n=e.currentIterKeys||[];return t=Q(t),j(t,".call(")||C.test(t)||o.startsWith(t,'"')&&o.endsWith(t,'"')||o.startsWith(t,"'")&&o.endsWith(t,"'")||!isNaN(t)?t:o.startsWith(t,"$_.")||o.startsWith(t,"iter.")||n.length&&st(n,t)||t in i?t.replace(L,A):I('$C.get( "{0}" )',t)}function ut(e){return I("{0} += {1};",v.output,e.replace(E,"\\n"))}function at(){var e=Array.coerce(arguments),t=U(e[e.length-1])?e.pop():U(e[0])?e.shift():null;if(!(this instanceof at))return U(t)?new at(e.join(""),t):new at(e.join(""));!t||c.forEach(function(e){e in t&&(this[e]=t[e],delete t[e])},this),this.filters=t||{},this.__tpl__=e.join(""),D[ft(this)]=this,this.compiled&&(this.compiled=!1,lt(this))}function ft(e){return e.id||(e.id=I(P,++y)),e.id}function lt(e){return e.compiled||(e.compiled=!0,e._parse=Y(e)),e}function ct(e){this.compiled||lt(this),this[v.dict]=e;var t=this._parse(e);return delete this[v.dict],t}function ht(t){function r(e,t,r){!r&&e in n||(n[e]=t)}function i(e,t){switch(typeof t){case"string":r(t,arguments[2],e);break;case"object":for(var n in t)r(n,t[n],e)}return this}var n={};!U(t)||e.copy(n,t),this.all=function(){return e.copy(n)},this.add=function(){return i.call(this,!1,arguments[0],arguments[1])},this.get=function(e){return n[e]},this.replace=function(){return i.call(this,!0,arguments[0],arguments[1])}}var r,i="__ASSERT__ __CONTEXT__ __FILTER_ __OUTPUT__ __UTIL__ $_ document false global instanceof null true typeof undefined window".split(" ").reduce(function(e,t){return e[t]=!0,e},e.obj()),s=/\$?\{([^\}\s]+)\}/g,o={blank:function(t){return e.empty(t)||typeof t=="string"&&!t.trim()},contains:j,endsWith:function(e,t){e=String(e);var n=e.length-t.length;return n>=0&&e.lastIndexOf(t)==n},empty:e.empty,equals:function(e,t){return e==t},exists:e.exists,is:function(e,t){return e===t},isEven:function(e){return!(parseInt(e,10)&1)},isOdd:function(e){return!(parseInt(e,10)&1)},isTPL:function(e){return!!q(I(B,this.id,e))||!!q(e)},iterable:function(t){return e.iter(t)},notEmpty:W,startsWith:function(e,t){return String(e).indexOf(t)===0}},u={},a={objectify:function(e,t){var n={};return n[t]=e,n},parse:function(e,t,n){t=String(t).trim();var r=[n[v.dict],e],i=q(I(B,this.id,t))||q(t);return r[v.dict]=!0,i?i.parse(e):this.fallback},stop:function(e){e.stop()},stringify:rt,type:function(t){return e.type(t)}},f="__tpl_cs_cached_keys",l="__tpl_cs_stack",c="compiled debug dict fallback id".split(" "),h="<~>",p=/([-\*\+\?\.\|\^\$\/\\\(\)[\]\{\}])/g,d="\\$1",v={assert:"__ASSERT__",ctx:"__CONTEXT__",dict:"__dict__",filter:"__FILTER__",output:"__OUTPUT__",util:"__UTIL__"},m=I("return {0};\n ",v.output),g='\n"use strict";\n'+I('var $C = new ContextStack( {0}, this.fallback, this.dict ), $_ = $C.current(), iter = new Iter( null ), {1} = "", U;',v.ctx,v.output),y=999,b,w="console",E=/[\n\r]/gm,S=/(['"])/g,x=new RegExp(h,"gm"),T=/[\r\n]+/g,N=/\s+/g,C=/[\(\)\[\]\{\}\?\*\+\/<>%&=!-]/,k,L=/\.(\d+)(\.?)/g,A="['$1']$2",O=new RegExp("\\s*([^\\|]+(?:\\|[^\\|]+?)){0,}"+h,"g"),M="<__SPLIT__TEMPLATE__HERE__>",_=["","$1","$2",""].join(M),D={},P="t8-anon-{0}",H='{0}["{1}"].call( this, {2}{3}, {4} )',B="{0}.{1}";X.prototype={current:function(){return(this.top||this[l][0]).dict},get:function(t){var n,i=this[l],s=i.length,o;while(s--){n=i[s];if(t in n.cache)return n.cache[t];if((o=n.dict[t])!==r||(o=Object.value(n.dict,t))!==r)return n.cache[t]=o}return this.hasFallback?this.fallback:r},pop:function(){var t=this[l].pop().dict;return this.top=this[l][this[l].length-1],t},push:function(n){return this[l].push(this.top={cache:e.obj(),dict:n}),this}},V.prototype={empty:!0,hasNext:function(){return this.stopped||this.empty?!1:(++this.index<this.lastIndex||(this.stop().isLast=!0),this.key=this.keys[this.index1++],this.current=this.val=this._[this.key],this)},stop:function(){return this.stopped=!0,this}},e.defs(V.prototype,{first:{get:function(){return this._[this.keys[this.firstKey]]}},last:{get:function(){return this._[this.keys[this.lastKey]]}},next:{get:function(){return this._[this.keys[this.nextKey]]}},prev:{get:function(){return this._[this.keys[this.prevKey]]}},nextIndex:{get:function(){var e=this.index+1;return e<=this.lastIndex?e:r}},prevIndex:{get:function(){var e=this.index-1;return e>=this.firstIndex?e:r}},firstKey:{get:function(){return this.keys[this.firstIndex]}},lastKey:{get:function(){return this.keys[this.lastIndex]}},nextKey:{get:function(){return this.keys[this.nextIndex]}},prevKey:{get:function(){return this.keys[this.prevIndex]}}},"r"),b={assembleparts:K,clean:Q,compiletpl:G,createtpl:Y,emittag:Z,fnvar:v,formatstatement:et,get:ot,util:a,wrap:ut},at.prototype={compiled:!1,debug:!1,dict:null,fallback:"",parse:ct},e.defs(at,{m8:{value:e},escapeRE:F,format:I,get:q,gsub:R,stringify:rt},"r"),at.Assert=new ht(o),at.Filter=new ht(u),at.Statement=new ht,at.Tag=new function(){function s(t){n.forEach(o,t),e.copy(this,t),i[this.start]=this}function o(e){if(!(e in this))throw new TypeError(I("A "+t+" Tag requires an {0}",r[e]))}var n="emit end start".split(" "),r={emit:"emit function",end:"end tag definition",start:"start tag definition"},i={};this.all=function(){return e.copy(i)},this.compileRegExp=function(){var e=[],t=[],n;for(n in i)e.push(F(i[n].end.substring(0,1))),t.push(F(i[n].start.substring(1)));return k=new RegExp("(\\{["+t.join("")+"])\\s*(.+?)\\s*(["+e.join("")+"]\\})","gm")},this.create=function(e,t){return new s(e),t===!0||this.compileRegExp(),this},this.get=function(e){return i[e]}};var pt=[{start:"{{",end:"}}",emit:function(e,n,r,i){var s,o,u,a;if(r=="")throw new SyntaxError(t+" missing key in value declaration.");!wt.test(r)||(s=j(r,"|")?(r.match(bt)||dt).filter(W):r.match(bt));if(!s||s.length<=2)return e.wrap(e.formatstatement(n,r));s.shift(),a=e.formatstatement(n,s.shift()),u=vt(s.shift().toLowerCase()),o=s.join(" ");if(!u||!o)throw new SyntaxError(t+" missing tag or statement in one liner value declaration.");return u(e,n,o,i)+e.wrap(a)+vt("endif")}},{start:"{%",end:"%}",emit:function(e,n,r,i){if(r=="")throw new SyntaxError(t+" missing key in statement declaration.");var s,o,u;if(!(u=vt(r.toLowerCase()))){s=r.split(" "),u=vt(s.shift().toLowerCase());if(s.length==0&&typeof u=="string")return u;o=s.join(" ");if(!u||!o)throw s=[],u||s.push("tag"),o||s.push("statement"),new SyntaxError(t+" missing "+s.join(" and ")+" in statement declaration.")}if(!u)throw new SyntaxError(I(t+" tag: {0} does not exist.",u));return typeof u=="function"?u(e,n,o,i):u}},{start:"{[",end:"]}",emit:function(e,t,n,r){n=n.replace(mt,"$1").split("for each");var i,s,o,u,a=e.clean(n.shift()),f=e.clean(n.pop()).match(gt);return n=[],f.shift(),u=f.shift(),o=f.shift(),f.length>=2&&(s=f.shift(),i=f.shift()),n.push(vt("for")(e,t,(W(u)?u.match(yt,"$1").join(",")+" in ":"")+o,r)),!i||n.push(vt(s||"if")(e,t,i,r)),n.push(e.wrap(a.split(" ").map(function(n){return e.formatstatement(t,n)}).join(" "))),!i||n.push(vt("endif")),n.push(vt("endfor")(e,t)),n.join("")}},{start:"{:",end:":}",emit:function(e,t,n){return e.formatstatement(t,n)+";"}},{start:"{#",end:"#}",emit:function(e,t,n){return["\n/*",n,"*/\n"].join(" ")}}],dt=[],vt=at.Statement.get,mt=/\s*(,)\s*/g,gt=/^\(\s*(.*?)(?:\bin\b){0,1}(.*?)\s*\)\s*(if|unless){0,1}\s*(.*)$/i,yt=/(\w+)/g,bt=/^(.*?)\s+(if|unless)\s+(.*)|$/i,wt=/\s+(if|unless)\s+/i;pt.forEach(function(e){at.Tag.create(e,!0)}),at.Tag.compileRegExp(),function(){function i(e,t,n){return n.split(" ").map(function(n){return t(e,n)}).join(" ")}var t={"for":function(e,t,i){var s="U",o=s,u,a,f=e.clean(i).match(n),l=s,c=[];return f===null?u=i:(f.shift(),o=f.pop()||s,l=f.pop()||s,u=f.pop()||f.pop(),a=(f.pop()||"").match(r)),u=e.formatstatement(t,u),c.push(I(["","iter = new Iter( {0}, iter, {1}, {2} );","while ( iter.hasNext() ) {","$_ = iter.current;"].join("\n\r"),u,l,o)),a&&a.length>0&&(t.currentIterKeys.unshift(a),a.length<2?c.push(I("var {0} = iter.current;\n\r",a[0])):a.length>=2&&c.push(I("var {0} = iter.key, {1} = iter.current;\n\r",a[0],a[1]))),c.join("")},forempty:"\n\r}\n\rif ( iter.empty ) {\n\r",endfor:function(e,t){return t.currentIterKeys.shift(),I(["\n\r}","iter = iter.parent || new Iter( null );","$_ = iter.current || $C.current(); \n\r"].join("\n\r"),e.fnvar.util)},"if":function(e,t,n){return I("if ( {0} ) { ",i(t,e.formatstatement,n))},elseif:function(e,t,n){return I(" } else if ( {0} ) { ",i(t,e.formatstatement,n))},"else":" } else { ",endif:" }",sub:function(t,n,r,i){var s="endsub",o,u=r.trim(),a,f;return o=i.indexOf([s,u].join(" ")),o>-1||(o=i.indexOf(s)),a=i.splice(0,o+1),a.splice(a.length-2,a.length),u=I("{0}.{1}",n.id,u),f=new at("",e.copy({debug:n.debug,fallback:n.fallback,id:u},n.filters)),f.currentIterKeys=[],f.__tpl__=a.join(""),f._parse=t.compiletpl(f,t.assembleparts(f,a)),delete f.currentIterKeys,f.compiled=!0,""},unless:function(e,t,n){return I("if ( !( {0} ) ) { ",i(t,e.formatstatement,n))}},n=/^(\[[^,]+,\s*[^\]]+\]|[^\s]+)(?:\s+in\s+([^\s\[]+)){0,1}\s*(?:\[?(\d+)\.+(\d*)]*\]?){0,1}/i,r=/(\w+)/g;at.Statement.add(t),at.Statement.add("elsif",t.elseif)}(),at.Filter.add({capitalize:function(e){return e=at.stringify(e),e.charAt(0).toUpperCase()+e.substring(1).toLowerCase()},count:function(t){return e.len(t)||0},crop:function(e,t){return e=at.stringify(e),t=parseInt(t,10)||50,e.length>t?e.substring(0,t/2)+"..."+e.substring(e.length-t/2):e},def:function(e,t){return o.blank(e)?t:e},first:function(t){switch(e.nativeType(t)){case"array":return t[0];case"string":return t.charAt(0)}},join:function(t,n){return e.got(t,"join")&&typeof t.join=="function"?t.join(n):t},last:function(t){switch(e.nativeType(t)){case"array":return t[t.length-1];case"string":return t.charAt(t.length-1)}},lowercase:function(e){return at.stringify(e).toLowerCase()},prefix:function(e,t){return t+e},suffix:function(e,t){return e+t},truncate:function(e,t){return e=at.stringify(e),t=parseInt(t,10)||50,e.length>t?e.substring(0,t)+"...":e},uppercase:function(e){return at.stringify(e).toUpperCase()},wrap:function(e,t,n){return t+e+(n||t)}}),e.iter(n)||(n=e.ENV=="commonjs"?module:e.global),at=e.expose(at,t,n),e.expose(e,at)}(typeof m8!="undefined"?m8:typeof require!="undefined"?require("m8"):null,"Templ8")
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