Skip to content
Browse files

Added JSLint testing.

  • Loading branch information...
1 parent 317c5cc commit 835cfea202f8e2e9b988a5d046daa21e7fce7045 Pierre Matri committed Jul 21, 2012
Showing with 784 additions and 699 deletions.
  1. +29 −0 .jshintrc
  2. +7 −3 Makefile
  3. +370 −340 kiwi.js
  4. +1 −1 kiwi.min.js
  5. +12 −3 lib/cache.js
  6. +38 −35 lib/compiler.js
  7. +6 −5 lib/filter.js
  8. +24 −24 lib/filters/base.js
  9. +4 −4 lib/filters/datetime.js
  10. +1 −1 lib/kiwi.js
  11. +11 −11 lib/tags/as.js
  12. +42 −42 lib/tags/block.js
  13. +2 −2 lib/tags/comment.js
  14. +45 −43 lib/tags/each.js
  15. +14 −14 lib/tags/extend.js
  16. +23 −24 lib/tags/if.js
  17. +9 −9 lib/tags/ifblock.js
  18. +9 −9 lib/tags/include.js
  19. +26 −26 lib/tags/print.js
  20. +10 −9 lib/tags/raw.js
  21. +8 −8 lib/tags/tmpl.js
  22. +16 −16 lib/template.js
  23. +40 −41 lib/token.js
  24. +19 −12 lib/tools.js
  25. +15 −15 lib/utils.js
  26. +3 −2 package.json
View
29 .jshintrc
@@ -0,0 +1,29 @@
+{
+ "node" : true,
+ "es5" : true,
+ "browser" : true,
+ "boss" : false,
+ "curly": false,
+ "debug": false,
+ "devel": false,
+ "eqeqeq": true,
+ "evil": true,
+ "forin": false,
+ "immed": true,
+ "laxbreak": false,
+ "newcap": true,
+ "noarg": true,
+ "noempty": false,
+ "nonew": false,
+ "nomen": false,
+ "onevar": false,
+ "plusplus": false,
+ "regexp": false,
+ "undef": true,
+ "sub": true,
+ "strict": false,
+ "white": false,
+ "laxcomma": true,
+ "indent": 2,
+ "loopfunc": true
+}
View
10 Makefile
@@ -1,11 +1,12 @@
-SRC = $(shell find lib -name "*.js" -type f)
+SRC = $(shell find ./lib -name "*.js" -type f)
UGLIFY = $(shell find node_modules -name "uglifyjs" -type f)
+JSHINT = $(shell find ./node_modules -type l -name "jshint")
all: kiwi.min.js
test:
@./node_modules/.bin/mocha
-
+
kiwi.js: $(SRC)
@node support/compile.js $^
@@ -19,4 +20,7 @@ kiwi.min.js: kiwi.js
&& du kiwi.min.js \
&& du kiwi.js
-.PHONY: test
+lint:
+ @$(JSHINT) $(SRC)
+
+.PHONY: test lint
View
710 kiwi.js
@@ -56,6 +56,12 @@ require.register("cache.js", function(module, exports, require){
/**
+ * Module dependencies.
+ */
+
+
+
+/**
* Basic cache for client mode.
*
* Constructor.
@@ -79,7 +85,7 @@ function Cache() {
Cache.prototype.cache = function(key, value) {
if(_.isUndefined(value)) return;
this._cache[key] = value;
-}
+};
/**
@@ -92,14 +98,14 @@ Cache.prototype.cache = function(key, value) {
Cache.prototype.get = function(key) {
return this._cache[key];
-}
+};
/**
* Module exports.
*/
-module.exports = exports = Cache;
+module.exports = Cache;
}); // module: cache.js
require.register("compiler.js", function(module, exports, require){
@@ -142,7 +148,7 @@ var Compiler = module.exports = function(template) {
this.options = template.options;
this.helpers = {};
this.__compilationEnd = [];
-}
+};
/**
@@ -188,7 +194,7 @@ Compiler.prototype.compile = function(callback) {
// Apply tag before processors
utils.applyAll(this.source, token.tagBeforeProcessors, [this], onProcessed);
-}
+};
/**
@@ -212,7 +218,7 @@ Compiler.prototype._tokenize = function(source, callback) {
TAG_OPENING_DELIMITER
);
- if(nextInflexion == -1) {
+ if(nextInflexion === -1) {
this._pushLiteralToken(rootToken, currentToken, workingSource);
break;
} else {
@@ -238,15 +244,15 @@ Compiler.prototype._tokenize = function(source, callback) {
// Ensure we are at root level
if(rootToken !== currentToken) {
- return callback(new Error( 'Tokenization error: unexpected end of file, '
- + 'expected `'
- + currentToken.tag.tagName
- + '`.')
- );
+ return callback(new Error('Tokenization error: unexpected end of file, ' +
+ 'expected `' +
+ currentToken.tag.tagName +
+ '`.'
+ ));
}
callback(null, rootToken);
-}
+};
/**
@@ -260,7 +266,7 @@ Compiler.prototype._tokenize = function(source, callback) {
Compiler.prototype._pushLiteralToken = function(root, parent, literal) {
if(!literal.length) return;
parent.children.push(new token.LiteralToken(literal, root));
-}
+};
/**
@@ -278,6 +284,7 @@ Compiler.prototype._pushToken = function(root, current, tag) {
var tagName = match[2];
var openingTag = match[1] !== '/';
var tagType = current.lookupTag(tagName);
+ var newToken;
// Check whether we know this tag
if(!tagType) {
@@ -291,7 +298,7 @@ Compiler.prototype._pushToken = function(root, current, tag) {
if(current.tagType.isIntermediate) current = current.parent;
// Push the tag to the stack
- var newToken = new token.IntermediateToken(tag,
+ newToken = new token.IntermediateToken(tag,
tagType,
root,
current,
@@ -307,22 +314,22 @@ Compiler.prototype._pushToken = function(root, current, tag) {
// Handle opening tags
if(openingTag) {
- var newToken = new token.BlockToken(tag,
- tagType,
- root,
- current,
- [],
- this.options);
+ newToken = new token.BlockToken(tag,
+ tagType,
+ root,
+ current,
+ [],
+ this.options);
current.children.push(newToken);
return newToken;
// Handle closing tags
} else {
if(!current.parent) {
- throw new Error( 'Tokenization error: unexpected `'
- + tagName
- + '` tag at root level.'
+ throw new Error('Tokenization error: unexpected `' +
+ tagName +
+ '` tag at root level.'
);
}
@@ -331,11 +338,11 @@ Compiler.prototype._pushToken = function(root, current, tag) {
}
if(current.tagType.tagName !== tagName) {
- throw new Error( 'Tokenization error: unexpected `'
- + tagName
- + '` tag, expected `'
- + current.tag.tagName
- + '`.'
+ throw new Error('Tokenization error: unexpected `' +
+ tagName +
+ '` tag, expected `' +
+ current.tag.tagName +
+ '`.'
);
}
return current.parent;
@@ -347,25 +354,27 @@ Compiler.prototype._pushToken = function(root, current, tag) {
// Ensure we don't have a closing tag
if(!openingTag) {
- throw new Error( 'Tokenization error: `'
- + tagName
- + '` is not a block tag.'
+ throw new Error('Tokenization error: `' +
+ tagName +
+ '` is not a block tag.'
);
}
- var newToken = new token.LeafToken(tag,
- tagType,
- root,
- current,
- this.options);
+
+ newToken = new token.LeafToken(tag,
+ tagType,
+ root,
+ current,
+ this.options);
+
current.children.push(newToken);
return current;
}
-}
+};
Compiler.prototype.registerTemplateHelper = function(name, helper) {
this.helpers[name] = helper;
-}
+};
}); // module: compiler.js
require.register("filter.js", function(module, exports, require){
@@ -407,9 +416,10 @@ function filter(input, filters) {
input = filterFunction.apply(this, [input].concat(filterArgs));
});
if(unknownFilter) {
- throw new Error( 'Rendering error: Unknown filter `'
- + unknownFilter
- + '`.');
+ throw new Error('Rendering error: Unknown filter `' +
+ unknownFilter +
+ '`.'
+ );
}
return input;
}
@@ -429,9 +439,9 @@ var filters = module.exports.filters = {};
function loadFilters(loadedFiles) {
loadedFiles = loadedFiles || frame.files.requireDir(__dirname + '/filters/');
- for(file in loadedFiles) {
+ for(var file in loadedFiles) {
var fileFilters = loadedFiles[file];
- for(filter in fileFilters) {
+ for(var filter in fileFilters) {
filters[filter] = fileFilters[filter];
}
}
@@ -482,7 +492,7 @@ exports.escape = function(input) {
return acc;
}
return tools.escape(input);
-}
+};
/**
@@ -503,7 +513,7 @@ exports.escapeIfUnsafe = function(input) {
return acc;
}
return tools.escapeIfUnsafe(input);
-}
+};
/**
@@ -524,7 +534,7 @@ exports.capitalize = function(input) {
}
input = input.toString();
return input.charAt(0).toUpperCase() + input.slice(1);
-}
+};
/**
@@ -544,7 +554,7 @@ exports.upper = function(input) {
return acc;
}
return input.toString().toUpperCase();
-}
+};
/**
@@ -564,7 +574,7 @@ exports.lower = function(input) {
return acc;
}
return input.toString().toLowerCase();
-}
+};
/**
@@ -577,7 +587,7 @@ exports.lower = function(input) {
exports.json = function(input) {
return JSON.stringify(input);
-}
+};
/**
@@ -598,7 +608,7 @@ exports.add = function(input, operand) {
return acc;
}
return parseFloat(input) + parseFloat(operand);
-}
+};
/**
@@ -611,8 +621,8 @@ exports.add = function(input, operand) {
*/
exports.subtract = function(input, operand) {
- return exports.add(input, -parseInt(operand));
-}
+ return exports.add(input, -parseInt(operand, 10));
+};
/**
@@ -633,7 +643,7 @@ exports.mul = function(input, operand) {
return acc;
}
return parseFloat(input) * parseFloat(operand);
-}
+};
/**
@@ -654,7 +664,7 @@ exports.div = function(input, operand) {
return acc;
}
return parseFloat(input) / parseFloat(operand);
-}
+};
/**
@@ -667,7 +677,7 @@ exports.div = function(input, operand) {
exports.incr = function(input, operand) {
return exports.add(input, 1);
-}
+};
/**
@@ -680,7 +690,7 @@ exports.incr = function(input, operand) {
exports.decr = function(input, operand) {
return exports.add(input, -1);
-}
+};
/**
@@ -695,12 +705,12 @@ exports.round = function(input) {
if(typeof input === 'object') {
var acc = {};
_.each(input, function (value, key) {
- acc[key] = exports.round(value, operand);
+ acc[key] = exports.round(value);
});
return acc;
}
return Math.round(input);
-}
+};
/**
@@ -715,12 +725,12 @@ exports.floor = function(input) {
if(typeof input === 'object') {
var acc = {};
_.each(input, function (value, key) {
- acc[key] = exports.floor(value, operand);
+ acc[key] = exports.floor(value);
});
return acc;
}
return Math.floor(input);
-}
+};
/**
@@ -735,12 +745,12 @@ exports.ceil = function(input) {
if(typeof input === 'object') {
var acc = {};
_.each(input, function (value, key) {
- acc[key] = exports.ceil(value, operand);
+ acc[key] = exports.ceil(value);
});
return acc;
}
return Math.ceil(input);
-}
+};
/**
@@ -760,8 +770,8 @@ exports.cut = function(input, needle) {
});
return acc;
}
- return input.toString().replace(needle, '')
-}
+ return input.toString().replace(needle, '');
+};
/**
@@ -785,7 +795,7 @@ exports.addslashes = function(input) {
.replace(/\'/g, "\\'")
.replace(/\"/g, '\\"')
.replace(/\0/g,'\\0');
-}
+};
/**
@@ -809,7 +819,7 @@ exports.stripslashes = function(input) {
.replace(/\\"/g,'"')
.replace(/\\0/g,'\0')
.replace(/\\\\/g,'\\');
-}
+};
/**
@@ -937,7 +947,7 @@ exports.replace = function(input, search, replacement, flags) {
/**
* Module exports
*/
-
+
module.exports = exports;
}); // module: filters/base.js
@@ -966,7 +976,7 @@ require.register("filters/datetime.js", function(module, exports, require){
exports.timeago = function(input) {
return moment(input).fromNow();
-}
+};
/**
@@ -979,7 +989,7 @@ exports.timeago = function(input) {
exports.relativedate = function(input) {
return moment(input).calendar();
-}
+};
/**
@@ -993,13 +1003,13 @@ exports.relativedate = function(input) {
exports.date = function(input, pattern) {
return moment(input).format(pattern);
-}
+};
/**
* Module exports
*/
-
+
module.exports = exports;
}); // module: filters/datetime.js
@@ -1088,23 +1098,23 @@ asTag.compile = function(token, compiledContents,
var parsed = token.tag.match(AS_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
var name = parsed[1];
- var compiled = '(function(parentAcc) {'
- + 'var __acc = [];'
- + compiledContents
- + 'var __joined = __acc.join("");'
- + '__data["' + name + '"] = __tools.tools.safe(__joined);'
- + '})(__acc);'
+ var compiled = '(function(parentAcc) {' +
+ 'var __acc = [];' +
+ compiledContents +
+ 'var __joined = __acc.join("");' +
+ '__data["' + name + '"] = __tools.tools.safe(__joined);' +
+ '})(__acc);';
callback(null, compiled);
-}
+};
}); // module: tags/as.js
@@ -1159,56 +1169,59 @@ blockTag.compile = function(token, compiledContents,
var parsed = token.tag.match(BLOCK_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
var name = parsed[1];
var mode = parsed[2];
-
+
//console.log(compiledContents);
- var compiled = '(function(parentAcc) {'
- + 'var __acc = [];'
- + compiledContents
- + 'var __currentBlock = __acc.join("");'
- + 'if(!_.isUndefined(__blocks["' + name + '"])) {'
- + '__tmp = new String(__blocks["' + name + '"].replace('
- + '/\\{\\{parent\\}\\}/g, __currentBlock'
- + '));'
- + 'if(__blocks["' + name + '"].mode) {'
- + '__tmp.mode = __blocks["' + name + '"].mode;'
- + '}'
- + '__blocks["' + name + '"] = __tmp;'
- + '}'
- + 'var __acc = [];'
- + 'if(_.isUndefined(__blocks["' + name + '"]) || __blocks["' + name + '"].mode) {'
- + 'if(__blocks["' + name + '"] && __blocks["' + name + '"].mode == "append") {'
- + '__acc.push(__blocks["' + name + '"]);'
- + '}'
- + '__acc.push(__currentBlock);'
- + 'if(__blocks["' + name + '"] && __blocks["' + name + '"].mode == "prepend") {'
- + '__acc.push(__blocks["' + name + '"]);'
- + '}'
- + '} else {'
- + '__acc.push(__blocks["' + name + '"]);'
- + '}'
- + 'var __joined = new String(__acc.join(""));'
- + (mode ? ('__joined.mode = "' + mode + '";') : '')
- + 'parentAcc.push(__joined);'
- + '__blocks["' + name + '"] = __joined;'
- + '})(__acc);'
+ var compiled = '(function(parentAcc) {' +
+ 'var __acc = [];' +
+ compiledContents +
+ 'var __currentBlock = __acc.join("");' +
+ 'if(!_.isUndefined(__blocks["' + name + '"])) {' +
+ '__tmp = new String(__blocks["' + name + '"].replace(' +
+ '/\\{\\{parent\\}\\}/g, __currentBlock' +
+ '));' +
+ 'if(__blocks["' + name + '"].mode) {' +
+ '__tmp.mode = __blocks["' + name + '"].mode;' +
+ '}' +
+ '__blocks["' + name + '"] = __tmp;' +
+ '}' +
+ 'var __acc = [];' +
+ 'if(_.isUndefined(__blocks["' + name + '"]) ||' +
+ '__blocks["' + name + '"].mode) {' +
+ 'if(__blocks["' + name + '"] &&' +
+ '__blocks["' + name + '"].mode == "append") {' +
+ '__acc.push(__blocks["' + name + '"]);' +
+ '}' +
+ '__acc.push(__currentBlock);' +
+ 'if(__blocks["' + name + '"] &&' +
+ '__blocks["' + name + '"].mode == "prepend") {' +
+ '__acc.push(__blocks["' + name + '"]);' +
+ '}' +
+ '} else {' +
+ '__acc.push(__blocks["' + name + '"]);' +
+ '}' +
+ 'var __joined = new String(__acc.join(""));' +
+ (mode ? ('__joined.mode = "' + mode + '";') : '') +
+ 'parentAcc.push(__joined);' +
+ '__blocks["' + name + '"] = __joined;' +
+ '})(__acc);';
callback(null, compiled);
-}
+};
/**
* Parent tag
*/
-
+
/**
* Compile `token` with `compiledContents` to JavaScript, and invoke
* `callback(err, compiled)`.
@@ -1221,13 +1234,15 @@ blockTag.compile = function(token, compiledContents,
parentTag.compile = function(token, compiledContents, compiler, callback) {
if(!token.parent.tagType || token.parent.tagType.tagName !== 'block') {
- return callback(new Error('Compilation error: `parent` tag must be immediate child of a `block` tag.'));
+ return callback(new Error(
+ 'Compilation error: `parent` must be immediate child of a `block` tag.'
+ ));
}
-
+
token.parent.hasParentTag = true;
callback(null, '__acc.push("{{parent}}");');
-}
+};
}); // module: tags/block.js
@@ -1273,7 +1288,7 @@ commentTag.isBlock = false;
commentTag.compile = function(token, compiledContents, compiler, callback) {
callback(null, '');
-}
+};
/**
@@ -1289,7 +1304,7 @@ commentTag.compile = function(token, compiledContents, compiler, callback) {
commentTag.beforeProcessor = function(source, compiler, callback) {
source = source.replace(COMMENT_RE, '');
callback(null, source);
-}
+};
}); // module: tags/comment.js
require.register("tags/each.js", function(module, exports, require){
@@ -1322,7 +1337,7 @@ var emptyTag = intermediateTags.empty = {};
*/
eachTag.isBlock = true;
-eachTag.headDeclarations = 'var _eachLoop;'
+eachTag.headDeclarations = 'var _eachLoop;';
/**
@@ -1340,10 +1355,10 @@ eachTag.compile = function(token, compiledContents,
var parsed = token.tag.match(EACH_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
var elementVariable = parsed[1] || '$value';
@@ -1356,15 +1371,17 @@ eachTag.compile = function(token, compiledContents,
// Ensure there is only one tag
if(compiledIntermediate.length > 1) {
- return callback(new Error( 'Compilation Error: Too many intermediate '
- + 'tags for `each`.'));
+ return callback(new Error('Compilation Error: Too many intermediate ' +
+ 'tags for `each`.'
+ ));
}
// Check tag
if(token.intermediate[0].tag !== 'empty') {
- return callback(new Error( 'Compilation Error: Unexpected tag `'
- + token.intermediate[0].tag
- + '`.'));
+ return callback(new Error('Compilation Error: Unexpected tag `' +
+ token.intermediate[0].tag +
+ '`.'
+ ));
}
ifEmpty = compiledIntermediate[0];
@@ -1375,15 +1392,15 @@ eachTag.compile = function(token, compiledContents,
// Add loop collection part
if(!token.options.strict) {
- compiled += 'try {'
- + '__tmp = ' + collection
- + '} catch(__err) {'
- + 'if(__err instanceof ReferenceError) {'
- + '__tmp = [];'
- + '} else {'
- + 'throw __err;'
- + '}'
- + '}';
+ compiled += 'try {' +
+ '__tmp = ' + collection +
+ '} catch(__err) {' +
+ 'if(__err instanceof ReferenceError) {' +
+ '__tmp = [];' +
+ '} else {' +
+ 'throw __err;' +
+ '}' +
+ '}';
}
else {
compiled += '__tmp = ' + collection + ';';
@@ -1397,41 +1414,41 @@ eachTag.compile = function(token, compiledContents,
// Call each
if(token.options.eachCounters) {
- compiled += 'var __eachLoopCounter = 0;'
- + '_.each(__tmp, '
- + 'function(' + elementVariable + ',' + indexVariable + '){'
- + '_eachLoop = {'
- + 'size: __eachLoopLength,'
- + 'counter0: __eachLoopCounter,'
- + 'counter: __eachLoopCounter + 1,'
- + 'revcounter0: __eachLoopLength - __eachLoopCounter - 1,'
- + 'revcounter: __eachLoopLength - __eachLoopCounter,'
- + 'first: __eachLoopCounter === 0,'
- + 'last: __eachLoopCounter + 1 === __eachLoopLength,'
- + 'parentLoop: __parentEachLoop'
- + '};'
- + compiledContents
- + '__eachLoopCounter++;'
- + '});';
+ compiled += 'var __eachLoopCounter = 0;' +
+ '_.each(__tmp, ' +
+ 'function(' + elementVariable + ',' + indexVariable + '){' +
+ '_eachLoop = {' +
+ 'size: __eachLoopLength,' +
+ 'counter0: __eachLoopCounter,' +
+ 'counter: __eachLoopCounter + 1,' +
+ 'revcounter0: __eachLoopLength - __eachLoopCounter - 1,' +
+ 'revcounter: __eachLoopLength - __eachLoopCounter,' +
+ 'first: __eachLoopCounter === 0,' +
+ 'last: __eachLoopCounter + 1 === __eachLoopLength,' +
+ 'parentLoop: __parentEachLoop' +
+ '};' +
+ compiledContents +
+ '__eachLoopCounter++;' +
+ '});';
}
else {
- compiled += '_.each(__tmp, '
- + 'function(' + elementVariable + ',' + indexVariable + '){'
- + compiledContents
- + '});';
+ compiled += '_.each(__tmp, ' +
+ 'function(' + elementVariable + ',' + indexVariable + ') {' +
+ compiledContents +
+ '});';
}
// Add the empty remaining part, if requested
if(ifEmpty) {
- compiled += '} else {'
- + ifEmpty
- + '}';
+ compiled += '} else {' +
+ ifEmpty +
+ '}';
}
compiled += '})(_eachLoop);';
callback(null, compiled);
-}
+};
}); // module: tags/each.js
@@ -1485,30 +1502,30 @@ extendTag.isBlock = false;
extendTag.compile = function(token, compiledContents, compiler, callback) {
if(token.root.children[0] !== token) {
- return callback(new Error( 'Compilation error: Extend tag must be defined '
- + 'at the very beginning of the template.')
- );
+ return callback(new Error('Compilation error: Extend tag must be defined ' +
+ 'at the very beginning of the template.'
+ ));
}
var parsed = token.tag.match(EXTEND_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
var name = parsed[1];
- var compiled = 'var __originalCallback = __callback;'
- + '__callback = function(err, compiled) {'
- + '__helpers.extend(' + name + ', __compiled, __template,'
- + '__data, __originalCallback);'
- + '};';
+ var compiled = 'var __originalCallback = __callback;' +
+ '__callback = function(err, compiled) {' +
+ '__helpers.extend(' + name + ', __compiled, __template,' +
+ '__data, __originalCallback);' +
+ '};';
callback(null, compiled);
-}
+};
/**
@@ -1532,7 +1549,7 @@ helpers.extend = function(name, compiled, template, data, callback) {
}
template._renderRelative(name, data, compiled, onRendered);
-}
+};
}); // module: tags/extend.js
@@ -1587,18 +1604,18 @@ var elseTag = intermediateTags['else'] = {};
function createIfCondition(condition, strict) {
var compiled;
if(strict) {
- compiled = 'if(' + condition + ')'
+ compiled = 'if(' + condition + ')';
} else {
- compiled = 'try {'
- + '__tmp = ' + condition
- + '} catch(__err) {'
- + 'if(__err instanceof ReferenceError) {'
- + '__tmp = false;'
- + '} else {'
- + 'throw __err;'
- + '}'
- + '}'
- + 'if(__tmp)';
+ compiled = 'try {' +
+ '__tmp = ' + condition +
+ '} catch(__err) {' +
+ 'if(__err instanceof ReferenceError) {' +
+ '__tmp = false;' +
+ '} else {' +
+ 'throw __err;' +
+ '}' +
+ '}' +
+ 'if(__tmp)';
}
return compiled;
}
@@ -1626,19 +1643,18 @@ ifTag.compile = function(token, compiledContents,
var parsed = token.tag.match(IF_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
var condition = parsed[1];
var appendEnd = ['}'];
// Handle basic if
var compiled = createIfCondition(condition, token.options.strict);
- compiled += '{'
- + compiledContents;
+ compiled += '{' + compiledContents;
// Handle else
var err;
@@ -1648,9 +1664,9 @@ ifTag.compile = function(token, compiledContents,
var parsed = intermediateTag.match(ELSE_PARSE_RE);
if(!parsed) {
- err = new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.'
+ err = new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
);
return;
}
@@ -1660,9 +1676,9 @@ ifTag.compile = function(token, compiledContents,
compiled += '} else {';
} else {
appendEnd.push('}');
- compiled += '} else {'
- + createIfCondition(condition, token.options.strict)
- + '{'
+ compiled += '} else {' +
+ createIfCondition(condition, token.options.strict) +
+ '{';
}
compiled += compiledIntermediate[index];
@@ -1674,14 +1690,14 @@ ifTag.compile = function(token, compiledContents,
// Return
compiled += appendEnd.join('');
callback(null, compiled);
-}
+};
}); // module: tags/if.js
require.register("tags/ifblock.js", function(module, exports, require){
/*!
* Coolony's Kiwi
- * Copyright 2012 Pierre Matri <pierre.matri@coolony.com>
+ * Copyright ©2012 Pierre Matri <pierre.matri@coolony.com>
* MIT Licensed
*/
@@ -1724,20 +1740,20 @@ ifBlockTag.compile = function(token, compiledContents,
var parsed = token.tag.match(IFBLOCK_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
var name = parsed[1];
- var compiled = 'if(!_.isUndefined(__blocks["' + name + '"])) {'
- + compiledContents
- + '}'
+ var compiled = 'if(!_.isUndefined(__blocks["' + name + '"])) {' +
+ compiledContents +
+ '}';
callback(null, compiled);
-}
+};
}); // module: tags/ifblock.js
@@ -1793,21 +1809,21 @@ includeTag.compile = function(token, compiledContents, compiler, callback) {
var parsed = token.tag.match(INCLUDE_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
var name = parsed[1];
compiler.__compilationEnd.unshift('});');
- var compiled = '__helpers.include(' + name + ', __template,'
- + '__data, function(err, rendered) {'
- + '__acc.push(rendered);';
+ var compiled = '__helpers.include(' + name + ', __template,' +
+ '__data, function(err, rendered) {' +
+ '__acc.push(rendered);';
callback(null, compiled);
-}
+};
/**
@@ -1831,7 +1847,7 @@ helpers.include = function(name, template, data, callback) {
}
template._renderRelative(name, data, null, onRendered);
-}
+};
}); // module: tags/include.js
@@ -1898,7 +1914,7 @@ variableTag.beforeProcessor = function(source, compiler, callback) {
return '{{= :' + compiler.__print.length + ' ' + contents + '}}';
});
callback(null, source);
-}
+};
/**
@@ -1923,51 +1939,51 @@ function createPrintTagCompiler(defaultFilters) {
var parsed = token.tag.match(TAG_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
// Handle decompiler
if(parsed[1]) {
- var key = parseInt(parsed[1]) - 1
+ var key = parseInt(parsed[1], 10) - 1;
token.__originalTag = compiler.__print[key];
}
var contents = parsed[2];
var filters = parsed[3] ? parseFilters(parsed[3], defaultFilters) :
defaultFilters;
- var contents = '__tools.filter('
- + contents
- + ', '
- + '[' + filters.join(',') + ']'
- + ')';
+ contents = '__tools.filter(' +
+ contents +
+ ', ' +
+ '[' + filters.join(',') + ']' +
+ ')';
var ret;
if(!token.options.strict) {
- ret = 'try {'
- + 'var __tmp = ' + contents + ';'
- + '} catch(__err) {'
- + 'if(__err instanceof ReferenceError) {'
- + '__tmp = "";'
- + '} else {'
- + 'throw __err;'
- + '}'
- + '}'
- + '__acc.push(__tmp);';
+ ret = 'try {' +
+ 'var __tmp = ' + contents + ';' +
+ '} catch(__err) {' +
+ 'if(__err instanceof ReferenceError) {' +
+ '__tmp = "";' +
+ '} else {' +
+ 'throw __err;' +
+ '}' +
+ '}' +
+ '__acc.push(__tmp);';
} else {
ret = '__acc.push(' + contents + ');';
}
callback(null, ret);
- }
+ };
compiler.untokenize = function(token, compiler) {
return token.__originalTag ?
token.__originalTag :
('{{' + token.tag + '}}');
- }
+ };
return compiler;
}
@@ -1987,7 +2003,7 @@ function parseFilters(filters, defaults) {
var raw = false;
filters = filters.split(FILTER_SPLIT_RE)
.filter(function filterOne(filter) {
- if(filter == 'raw') {
+ if(filter === 'raw') {
raw = true;
return false;
}
@@ -2000,7 +2016,8 @@ function parseFilters(filters, defaults) {
return '"' + filter[1] + '"';
}
var splittedArgs = filter[2].split(FILTER_SPLIT_ARGS_RE);
- return '["' + filter[1] + '", ' + splittedArgs.join(',') + ']';
+ return '["' + filter[1] + '", ' +
+ splittedArgs.join(',') + ']';
});
if(!raw) filters = filters.concat(defaults);
@@ -2029,7 +2046,11 @@ var utils = require('../utils');
* @see https://github.com/kof/node-jqtpl
*/
-var VERBATIM_RE = /\{\{\s*verbatim\s*\}\}((?:.|\n)*?)\{\{\s*\/\s*verbatim\s*\}\}|{\{\s*raw\s*\}\}((?:.|\n)*?)\{\{\s*\/\s*raw\s*\}\}/g;
+var VERBATIM_RE = new RegExp(
+ '\\{\\{\\s*verbatim\\s*\\}\\}((?:.|\\n)*?)' +
+ '\\{\\{\\s*\\/\\s*verbatim\\s*\\}\\}|' +
+ '{\\{\\s*raw\\s*\\}\\}((?:.|\\n)*?)\\{\\{\\s*\\/\\s*raw\\s*\\}\\}'
+, 'g');
/**
@@ -2058,11 +2079,12 @@ verbatimTag.isBlock = false;
*/
verbatimTag.compile = function(token, compiledContents, compiler, callback) {
- var key = parseInt(token.tag.split(' ')[1]) - 1;
- callback(null, '__acc.push("'
- + utils.escapeCompiledString(compiler.__verbatim[key])
- + '");');
-}
+ var key = parseInt(token.tag.split(' ')[1], 10) - 1;
+ callback(null, '__acc.push("' +
+ utils.escapeCompiledString(compiler.__verbatim[key]) +
+ '");'
+ );
+};
/**
@@ -2083,7 +2105,7 @@ verbatimTag.beforeProcessor = function(source, compiler, callback) {
return '{{verbatim ' + compiler.__verbatim.length + '}}';
});
callback(null, source);
-}
+};
}); // module: tags/raw.js
@@ -2138,20 +2160,20 @@ tmplTag.compile = function(token, compiledContents, compiler, callback) {
var parsed = token.tag.match(TAG_PARSE_RE);
if(!parsed) {
- return callback(new Error( 'Compilation error: Unable to parse tag `'
- + token.tag
- + '`.')
- );
+ return callback(new Error('Compilation error: Unable to parse tag `' +
+ token.tag +
+ '`.'
+ ));
}
var nested = parsed[1];
compiler.__compilationEnd.unshift('});');
- callback(null, '__template._nest(' + nested + ', __data, '
- + 'function(err, rendered){'
- + '__acc.push(rendered);'
+ callback(null, '__template._nest(' + nested + ', __data, ' +
+ 'function(err, rendered){' +
+ '__acc.push(rendered);'
);
-}
+};
}); // module: tags/tmpl.js
@@ -2198,7 +2220,7 @@ var DEFAULTS = {
_parent: null,
_cacheAttachment: '_cache',
_cacheTmplAttachment: '_nestCache'
-}
+};
var TEMPLATE_EXPORTS = {filter: filter, utils: utils, tools: tools};
@@ -2253,7 +2275,7 @@ function Template(str, options) {
Template.prototype._getCache = function() {
return this.options.cacheContext[this.options._cacheProp];
-}
+};
/**
@@ -2266,7 +2288,7 @@ Template.prototype._getCache = function() {
Template.prototype.loadFile = function(filePath, callback) {
callback(new Error('Client mode does not support reading from file.'));
-}
+};
/**
@@ -2284,7 +2306,7 @@ Template.prototype.render = function(data, callback) {
callback = data;
data = {};
}
-
+
// Data defaults
if(!data) data = {};
@@ -2302,8 +2324,8 @@ Template.prototype.render = function(data, callback) {
this._compile(function(err){
if(err) return callback(err);
_this._renderCompiled(data, callback);
- })
-}
+ });
+};
/**
@@ -2315,10 +2337,10 @@ Template.prototype.render = function(data, callback) {
* @param {Function} callback
* @api public
*/
-
+
Template.prototype.loadAndRender = function(filePath, data, callback) {
callback(new Error('Client mode does not support reading from file.'));
-}
+};
/**
@@ -2338,7 +2360,7 @@ Template.prototype._renderCompiled = function onRendered(data, callback) {
} catch(err) {
callback(err);
}
-}
+};
/**
@@ -2370,7 +2392,7 @@ Template.prototype._compile = function(callback) {
// Invoke the callback
callback(null, compiled);
});
-}
+};
/**
@@ -2393,7 +2415,7 @@ Template.prototype._nest = function(nested, data, callback) {
if(err) return callback(err);
callback(null, rendered);
});
-}
+};
/**
@@ -2440,7 +2462,7 @@ Template.prototype._renderRelative = function(name, data, rendered, callback) {
} else {
this.options.lookup(name, this, onTemplateLocated);
}
-}
+};
/**
@@ -2452,14 +2474,14 @@ Template.prototype._renderRelative = function(name, data, rendered, callback) {
Template.prototype._cacheKey = function() {
return this.options.path || this.template || null;
-}
+};
/**
* Module exports
*/
-exports = module.exports = Template;
+module.exports = Template;
}); // module: template.js
@@ -2524,7 +2546,7 @@ function BaseToken(root, parent, options) {
BaseToken.prototype.compile = function(compiler, callback) {
callback(new Error('Stub method BaseToken#compile must be overloaded'));
-}
+};
/*
@@ -2538,13 +2560,13 @@ BaseToken.prototype.compile = function(compiler, callback) {
BaseToken.prototype.lookupTag = function(tag) {
if(tags[tag]) return tags[tag];
- if( this.tagType
- && this.tagType.intermediateTags
- && this.tagType.intermediateTags[tag]) {
+ if(this.tagType && this.tagType.intermediateTags &&
+ this.tagType.intermediateTags[tag]) {
+
this.tagType.intermediateTags[tag].isIntermediate = true;
return this.tagType.intermediateTags[tag];
}
-}
+};
/*
@@ -2577,12 +2599,12 @@ inherits(LiteralToken, BaseToken);
*/
LiteralToken.prototype.compile = function(compiler, callback) {
- this._compiled = '__acc.push("'
- + utils.escapeCompiledString(this.literal)
- + '");';
+ this._compiled = '__acc.push("' +
+ utils.escapeCompiledString(this.literal) +
+ '");';
callback(null, this._compiled);
-}
+};
/*
@@ -2620,30 +2642,30 @@ RootToken.prototype.compile = function(compiler, callback) {
function onCompiled(err, compiled) {
if(err) return callback(err);
- var compiled = 'var __this = this;'
- + 'var __acc = [];'
- + 'var __blocks = {};'
- + 'if(__template.options && __template.options._parent) {'
- + '__blocks = __template.options._parent.blocks;'
- + '}'
- + 'var __tmp;'
- + 'var __err;'
- + '__data = __data || {};'
- + headDeclarations.join('')
- + 'with(__data) {'
- + compiled
- + footDeclarations.join('')
- + 'var __compiled = new String(__acc.join(""));'
- + '__compiled.blocks = __blocks;'
- + '__callback(null, __compiled);'
- + compiler.__compilationEnd.join('')
- + '}';
+ compiled = 'var __this = this;' +
+ 'var __acc = [];' +
+ 'var __blocks = {};' +
+ 'if(__template.options && __template.options._parent) {' +
+ '__blocks = __template.options._parent.blocks;' +
+ '}' +
+ 'var __tmp;' +
+ 'var __err;' +
+ '__data = __data || {};' +
+ headDeclarations.join('') +
+ 'with(__data) {' +
+ compiled +
+ footDeclarations.join('') +
+ 'var __compiled = new String(__acc.join(""));' +
+ '__compiled.blocks = __blocks;' +
+ '__callback(null, __compiled);' +
+ compiler.__compilationEnd.join('') +
+ '}';
_this._compiled = compiled;
callback(null, compiled);
- };
+ }
utils.compileTokens(this.children, compiler, onCompiled);
-}
+};
/*
@@ -2710,7 +2732,7 @@ BlockToken.prototype.compile = function(compiler, callback) {
}
utils[compilationFunction](this.children, compiler, onContentsCompiled);
-}
+};
/*
@@ -2755,7 +2777,7 @@ LeafToken.prototype.compile = function(compiler, callback) {
}
var compiled = this.tagType.compile(this, null, compiler, onCompiled);
-}
+};
/*
@@ -2770,7 +2792,7 @@ LeafToken.prototype.untokenize = function(compiler) {
return this.tagType.compile.untokenize ?
this.tagType.compile.untokenize(this, compiler) :
('{{' + this.tag + '}}');
-}
+};
/*
@@ -2809,7 +2831,7 @@ IntermediateToken.prototype.compile = function(compiler, callback) {
}
utils.compileTokens(this.children, compiler, onContentsCompiled);
-}
+};
/*
@@ -2823,7 +2845,7 @@ IntermediateToken.prototype.compile = function(compiler, callback) {
IntermediateToken.prototype.lookupTag = function(tag) {
return this.parent.lookupTag(tag);
-}
+};
/**
@@ -2849,7 +2871,7 @@ function registerTag(name, tag) {
footDeclarations.push(tag.footDeclarations);
}
if(tag.helpers) {
- for(helperName in tag.helpers) {
+ for(var helperName in tag.helpers) {
registerHelper(helperName, tag.helpers[helperName]);
}
}
@@ -2875,8 +2897,7 @@ function registerHelper(name, helper) {
* Module exports
*/
-exports = module.exports = {
- headDeclarations: [],
+module.exports = {
BaseToken: BaseToken,
RootToken: RootToken,
BlockToken: BlockToken,
@@ -2890,7 +2911,7 @@ exports = module.exports = {
helpers: helpers,
registerTag: registerTag,
registerHelper: registerHelper
-}
+};
/*
@@ -2899,25 +2920,27 @@ exports = module.exports = {
function loadTags(loadedFiles) {
loadedFiles = loadedFiles || frame.files.requireDir(__dirname + '/tags/');
- for(file in loadedFiles) {
+ for(var file in loadedFiles) {
var fileTags = loadedFiles[file].tags;
var fileHelpers = loadedFiles[file].helpers;
// Process tags
- for(tag in fileTags) {
+ for(var tag in fileTags) {
registerTag(tag, fileTags[tag]);
}
// Process tags
if(fileHelpers) {
- for(helperName in fileHelpers) {
+ for(var helperName in fileHelpers) {
registerHelper(helperName, fileHelpers[helperName]);
}
}
}
}
- var files = ['block', 'comment', 'each', 'if', 'print', 'raw', 'tmpl', 'ifblock', 'as'];
+ var files = [
+ 'block', 'comment', 'each', 'if', 'print', 'raw', 'tmpl', 'ifblock', 'as'
+ ];
var acc = {};
_.each(files, function(file) {
acc[file] = require('./tags/' + file);
@@ -2971,14 +2994,14 @@ exports.createSimpleTag = function createSimpleTag(name, fn) {
splitted[0] = '__data';
var args = splitted.join(',');
- var compiled = '__acc.push(__tools.tools.escapeIfUnsafe('
- + '__helpers["' + name + '"](' + args + ')'
- + '));';
+ var compiled = '__acc.push(__tools.tools.escapeIfUnsafe(' +
+ '__helpers["' + name + '"](' + args + ')' +
+ '));';
callback(null, compiled);
}
- }
-}
+ };
+};
/**
@@ -2991,7 +3014,7 @@ exports.createSimpleTag = function createSimpleTag(name, fn) {
exports.createFilter = function createFilter(name, fn) {
filter.filters[name] = fn;
-}
+};
/**
@@ -3009,7 +3032,14 @@ var escape = exports.escape = function(str) {
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/'/g, "&#146;");
-}
+};
+
+
+/**
+ * Export SafeString.
+ */
+
+var SafeString = exports.SafeString = String;
/**
@@ -3021,10 +3051,9 @@ var escape = exports.escape = function(str) {
*/
exports.safe = function(str) {
- if(!(str instanceof String)) str = new String(str);
- str.safe = true;
+ if(!(str instanceof SafeString)) str = new SafeString(str);
return str;
-}
+};
/**
@@ -3036,8 +3065,8 @@ exports.safe = function(str) {
*/
exports.escapeIfUnsafe = function(str) {
- return str.safe ? str : escape(str);
-}
+ return str instanceof SafeString ? str : escape(str);
+};
/**
@@ -3049,6 +3078,7 @@ exports.registerTag = token.registerTag;
exports.registerHelper = token.registerHelpers;
exports.escapeCompiledString = utils.escapeCompiledString;
exports.applyAll = utils.applyAll;
+exports.safeString = String;
/**
@@ -3123,7 +3153,7 @@ function tmpAsyncForEach(array, fn, args, callback) {
} else {
callback();
}
-};
+}
var asyncForEach = frame ? frame.asyncForEach : tmpAsyncForEach;
@@ -3150,7 +3180,7 @@ var apply = exports.apply = function(input, processor, args, callback) {
}
processor.apply(this, [input].concat(args || []).concat([done]));
-}
+};
/**
@@ -3184,7 +3214,7 @@ exports.applyAll = function(input, processors, args, callback) {
args = null;
}
asyncForEach(processors, applyOne, done);
-}
+};
/**
* Asynchronously compiles `tokens`, and invoke
@@ -3232,8 +3262,8 @@ exports.compileTokens = function(tokens, compiler, callback) {
compileTokenArray(tokens, compiler, function(err, compiled) {
if(err) return callback(err);
callback(null, compiled.join(''));
- })
-}
+ });
+};
/**
@@ -3249,7 +3279,7 @@ exports.escapeCompiledString = function(str) {
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/\t/g, '\\t');
-}
+};
/**
@@ -3261,8 +3291,8 @@ exports.escapeCompiledString = function(str) {
*/
exports.isIterable = function(input) {
- return typeof input === 'object' && !(input instanceof String)
-}
+ return typeof input === 'object' && !(input instanceof String);
+};
/**
@@ -3282,7 +3312,7 @@ exports.inherits = function(subclass, superclass) {
subclass.prototype.constructor = subclass;
subclass._superclass = superclass;
subclass._superproto = superclass.prototype;
-}
+};
/**
View
2 kiwi.min.js
@@ -1,2 +1,2 @@
/*! Coolony's Kiwi | Copyright ©2012 Pierre Matri <pierre.matri@coolony.com> | MIT Licensed */
-(function(){function a(b){var c=a.resolve(b),d=a.modules[c];if(!d)throw new Error('failed to require "'+b+'"');return d.exports||(d.exports={},d.call(d.exports,d,d.exports,a.relative(c))),d.exports}a.modules={},a.resolve=function(b){var c=b,d=b+".js",e=b+"/index.js";return a.modules[d]&&d||a.modules[e]&&e||c},a.register=function(b,c){a.modules[b]=c},a.relative=function(b){return function(c){if("."!=c.charAt(0))return a(c);var d=b.split("/"),e=c.split("/");d.pop();for(var f=0;f<e.length;f++){var g=e[f];".."==g?d.pop():"."!=g&&d.push(g)}return a(d.join("/"))}},a.register("cache.js",function(a,b,c){function d(){this._cache={}}d.prototype.cache=function(a,b){if(_.isUndefined(b))return;this._cache[a]=b},d.prototype.get=function(a){return this._cache[a]},a.exports=b=d}),a.register("compiler.js",function(a,b,c){var d=c("./token"),e=c("./utils"),f="{{",g="}}",h=f.length,i=/^(\/)?\s*([^\s\}\(]*)/,j=a.exports=function(a){this.template=a,this.source=a.template,this.options=a.options,this.helpers={},this.__compilationEnd=[]};j.prototype.compile=function(a){function c(c,d){if(c)return a(c);b._tokenize(d,f)}function f(c,d){if(c)return a(c);d.compile(b,g)}function g(c,d){if(c)return a(c);var e=new Function("__template","__tools","_","__data","__helpers","__callback",d);e.__helpers=b.helpers,a(null,e)}var b=this;e.applyAll(this.source,d.tagBeforeProcessors,[this],c)},j.prototype._tokenize=function(a,b){var c=a,e=new d.RootToken,i=e,j=!1,k;for(;;){var l=c.search(j?g:f);if(l==-1){this._pushLiteralToken(i,e,c);break}j&&(l+=h),k=c.slice(0,l),c=c.slice(l);if(!j)this._pushLiteralToken(i,e,k);else{k=k.slice(2,-2);try{e=this._pushToken(i,e,k)}catch(m){return b(m)}}j=!j}if(i!==e)return b(new Error("Tokenization error: unexpected end of file, expected `"+e.tag.tagName+"`."));b(null,i)},j.prototype._pushLiteralToken=function(a,b,c){if(!c.length)return;b.children.push(new d.LiteralToken(c,a))},j.prototype._pushToken=function(a,b,c){var e=c.match(i),f=e[2],g=e[1]!=="/",h=b.lookupTag(f);if(!h)throw new Error("Tokenization error: Unknown tag `"+f+"`.");if(h.isIntermediate){b.tagType.isIntermediate&&(b=b.parent);var j=new d.IntermediateToken(c,h,a,b,[],this.options);return b.intermediate.push(j),j}if(h.isBlock){if(g){var j=new d.BlockToken(c,h,a,b,[],this.options);return b.children.push(j),j}if(!b.parent)throw new Error("Tokenization error: unexpected `"+f+"` tag at root level.");b.tagType.isIntermediate&&(b=b.parent);if(b.tagType.tagName!==f)throw new Error("Tokenization error: unexpected `"+f+"` tag, expected `"+b.tag.tagName+"`.");return b.parent}if(!g)throw new Error("Tokenization error: `"+f+"` is not a block tag.");var j=new d.LeafToken(c,h,a,b,this.options);return b.children.push(j),b},j.prototype.registerTemplateHelper=function(a,b){this.helpers[a]=b}}),a.register("filter.js",function(a,b,c){function d(b,c){var d;c.forEach(function(c){var e=[];_.isArray(c)&&(e=c.slice(1),c=c[0]);var f=a.exports.filters[c];if(!f)return d=c,!1;b=f.apply(this,[b].concat(e))});if(d)throw new Error("Rendering error: Unknown filter `"+d+"`.");return b}function f(a){a=a||frame.files.requireDir(__dirname+"/filters/");for(file in a){var b=a[file];for(d in b)e[d]=b[d]}}a.exports=d;var e=a.exports.filters={},g=["base","datetime"],h={};_.each(g,function(a){h[a]=c("./filters/"+a)}),f(h)}),a.register("filters/base.js",function(a,b,c){var d=c("../tools"),e=c("../utils");b.escape=function(a){if(a===null||a===undefined)return"";if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.escape(a)}),c}return d.escape(a)},b.escapeIfUnsafe=function(a){if(a===null||a===undefined)return"";if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.escapeIfUnsafe(a)}),c}return d.escapeIfUnsafe(a)},b.capitalize=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.capitalize(a)}),c}return a=a.toString(),a.charAt(0).toUpperCase()+a.slice(1)},b.upper=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.upper(a)}),c}return a.toString().toUpperCase()},b.lower=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.lower(a)}),c}return a.toString().toLowerCase()},b.json=function(a){return JSON.stringify(a)},b.add=function(a,c){if(typeof a=="object"){var d={};return _.each(a,function(a,e){d[e]=b.add(a,c)}),d}return parseFloat(a)+parseFloat(c)},b.subtract=function(a,c){return b.add(a,-parseInt(c))},b.mul=function(a,c){if(typeof a=="object"){var d={};return _.each(a,function(a,e){d[e]=b.mul(a,c)}),d}return parseFloat(a)*parseFloat(c)},b.div=function(a,c){if(typeof a=="object"){var d={};return _.each(a,function(a,e){d[e]=b.div(a,c)}),d}return parseFloat(a)/parseFloat(c)},b.incr=function(a,c){return b.add(a,1)},b.decr=function(a,c){return b.add(a,-1)},b.round=function(a){if(typeof a=="object"){var c={};return _.each(a,function(a,d){c[d]=b.round(a,operand)}),c}return Math.round(a)},b.floor=function(a){if(typeof a=="object"){var c={};return _.each(a,function(a,d){c[d]=b.floor(a,operand)}),c}return Math.floor(a)},b.ceil=function(a){if(typeof a=="object"){var c={};return _.each(a,function(a,d){c[d]=b.ceil(a,operand)}),c}return Math.ceil(a)},b.cut=function(a,c){if(typeof a=="object"){var d={};return _.each(a,function(a,e){d[e]=b.cut(a,c)}),d}return a.toString().replace(c,"")},b.addslashes=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.capitalize(a)}),c}return a.toString().replace(/\\/g,"\\\\").replace(/\'/g,"\\'").replace(/\"/g,'\\"').replace(/\0/g,"\\0")},b.stripslashes=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.capitalize(a)}),c}return a.toString().replace(/\\'/g,"'").replace(/\\"/g,'"').replace(/\\0/g,"\0").replace(/\\\\/g,"\\")},b.first=function(a){return typeof a=="object"&&!_.isArray(a)?"":_.isString(a)?a.substr(0,1):_.first(a)},b.last=function(a){return typeof a=="object"&&!_.isArray(a)?"":_.isString(a)?a.slice(-1):_.last(a)},b.length=function(a){return typeof a=="object"?_.keys(a).length:a.length},b.reverse=function(a){return _.isArray(a)?a.reverse():a},b.join=function(a,b){if(_.isArray(a))return a.join(b);if(typeof a=="object"){var c=[];return _.each(a,function(a,b){c.push(a)}),c.join(b)}return a},b.urlencode=function(a){return encodeURIComponent(a)},b.urldecode=function(a){return decodeURIComponent(a)},b.replace=function(a,b,c,d){return a.replace(new RegExp(b,d),c)},a.exports=b}),a.register("filters/datetime.js",function(a,b,c){b.timeago=function(a){return moment(a).fromNow()},b.relativedate=function(a){return moment(a).calendar()},b.date=function(a,b){return moment(a).format(b)},a.exports=b}),a.register("kiwi.js",function(a,b,c){var d=b.Template=c("./template");b.tools=c("./tools"),b.version="0.1.3",a.exports=b}),a.register("tags/as.js",function(a,b,c){var d=/^as\s+([^\s]+)$/;a.exports.tags={};var e=a.exports.tags.as={};e.isBlock=!0,e.compile=function(a,b,c,e,f){var g=a.tag.match(d);if(!g)return f(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var h=g[1],i="(function(parentAcc) {var __acc = [];"+b+'var __joined = __acc.join("");'+'__data["'+h+'"] = __tools.tools.safe(__joined);'+"})(__acc);";f(null,i)}}),a.register("tags/block.js",function(a,b,c){var d=/^block\s+([^\s]+)(?:\s+(append|prepend))?$/;a.exports.tags={};var e=a.exports.tags.block={},f=a.exports.tags.parent={};e.isBlock=!0,e.compile=function(a,b,c,e,f){var g=a.tag.match(d);if(!g)return f(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var h=g[1],i=g[2],j="(function(parentAcc) {var __acc = [];"+b+'var __currentBlock = __acc.join("");'+'if(!_.isUndefined(__blocks["'+h+'"])) {'+'__tmp = new String(__blocks["'+h+'"].replace('+"/\\{\\{parent\\}\\}/g, __currentBlock"+"));"+'if(__blocks["'+h+'"].mode) {'+'__tmp.mode = __blocks["'+h+'"].mode;'+"}"+'__blocks["'+h+'"] = __tmp;'+"}"+"var __acc = [];"+'if(_.isUndefined(__blocks["'+h+'"]) || __blocks["'+h+'"].mode) {'+'if(__blocks["'+h+'"] && __blocks["'+h+'"].mode == "append") {'+'__acc.push(__blocks["'+h+'"]);'+"}"+"__acc.push(__currentBlock);"+'if(__blocks["'+h+'"] && __blocks["'+h+'"].mode == "prepend") {'+'__acc.push(__blocks["'+h+'"]);'+"}"+"} else {"+'__acc.push(__blocks["'+h+'"]);'+"}"+'var __joined = new String(__acc.join(""));'+(i?'__joined.mode = "'+i+'";':"")+"parentAcc.push(__joined);"+'__blocks["'+h+'"] = __joined;'+"})(__acc);";f(null,j)},f.compile=function(a,b,c,d){if(!a.parent.tagType||a.parent.tagType.tagName!=="block")return d(new Error("Compilation error: `parent` tag must be immediate child of a `block` tag."));a.parent.hasParentTag=!0,d(null,'__acc.push("{{parent}}");')}}),a.register("tags/comment.js",function(a,b,c){var d=/\{\{\s*comment\s*\}\}((.|\n)*?)\{\{\s*\/\s*comment\s*\}\}/g;a.exports.tags={};var e=a.exports.tags["#"]={};e.isBlock=!1,e.compile=function(a,b,c,d){d(null,"")},e.beforeProcessor=function(a,b,c){a=a.replace(d,""),c(null,a)}}),a.register("tags/each.js",function(a,b,c){var d=/^each(?:\(([^\)\s]+)\s*\,\s*([^\)\s]+)\s*\))?\s+(.*)$/;a.exports.tags={};var e=a.exports.tags.each={},f=e.intermediateTags={},g=f.empty={};e.isBlock=!0,e.headDeclarations="var _eachLoop;",e.compile=function(a,b,c,e,f){var g=a.tag.match(d);if(!g)return f(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var h=g[1]||"$value",i=g[2]||"$index",j=g[3],k;if(c.length){if(c.length>1)return f(new Error("Compilation Error: Too many intermediate tags for `each`."));if(a.intermediate[0].tag!=="empty")return f(new Error("Compilation Error: Unexpected tag `"+a.intermediate[0].tag+"`."));k=c[0]}var l="(function(__parentEachLoop) {";a.options.strict?l+="__tmp = "+j+";":l+="try {__tmp = "+j+"} catch(__err) {"+"if(__err instanceof ReferenceError) {"+"__tmp = [];"+"} else {"+"throw __err;"+"}"+"}",l+="var __eachLoopLength = _.size(__tmp);",k&&(l+="if(__eachLoopLength) {"),a.options.eachCounters?l+="var __eachLoopCounter = 0;_.each(__tmp, function("+h+","+i+"){"+"_eachLoop = {"+"size: __eachLoopLength,"+"counter0: __eachLoopCounter,"+"counter: __eachLoopCounter + 1,"+"revcounter0: __eachLoopLength - __eachLoopCounter - 1,"+"revcounter: __eachLoopLength - __eachLoopCounter,"+"first: __eachLoopCounter === 0,"+"last: __eachLoopCounter + 1 === __eachLoopLength,"+"parentLoop: __parentEachLoop"+"};"+b+"__eachLoopCounter++;"+"});":l+="_.each(__tmp, function("+h+","+i+"){"+b+"});",k&&(l+="} else {"+k+"}"),l+="})(_eachLoop);",f(null,l)}}),a.register("tags/extend.js",function(a,b,c){var d=c("../utils"),e=/^extend\s+(.+)$/;a.exports.tags={};var f=a.exports.tags.extend={},g=a.exports.helpers={};f.isBlock=!1,f.compile=function(a,b,c,d){if(a.root.children[0]!==a)return d(new Error("Compilation error: Extend tag must be defined at the very beginning of the template."));var f=a.tag.match(e);if(!f)return d(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var g=f[1],h="var __originalCallback = __callback;__callback = function(err, compiled) {__helpers.extend("+g+", __compiled, __template,"+"__data, __originalCallback);"+"};";d(null,h)},g.extend=function(a,b,c,d,e){function f(a,b){if(a)return e(a);e(null,b)}c._renderRelative(a,d,b,f)}}),a.register("tags/if.js",function(a,b,c){function i(a,b){var c;return b?c="if("+a+")":c="try {__tmp = "+a+"} catch(__err) {"+"if(__err instanceof ReferenceError) {"+"__tmp = false;"+"} else {"+"throw __err;"+"}"+"}"+"if(__tmp)",c}var d=/^if\s+(.*)$/,e=/^else(?:\s+(.*))?$/;a.exports.tags={};var f=a.exports.tags["if"]={},g=f.intermediateTags={},h=g["else"]={};f.isBlock=!0,f.compile=function(a,b,c,f,g){var h=a.tag.match(d);if(!h)return g(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var j=h[1],k=["}"],l=i(j,a.options.strict);l+="{"+b;var m;_.each(a.intermediate,function(b,d){var f=b.tag,g=c[d],h=f.match(e);if(!h){m=new Error("Compilation error: Unable to parse tag `"+a.tag+"`.");return}var j=h[1];j?(k.push("}"),l+="} else {"+i(j,a.options.strict)+"{"):l+="} else {",l+=c[d]});if(m)return g(m);l+=k.join(""),g(null,l)}}),a.register("tags/ifblock.js",function(a,b,c){var d=/^ifblock\s+([^\s]+)$/;a.exports.tags={};var e=a.exports.tags.ifblock={};e.isBlock=!0,e.compile=function(a,b,c,e,f){var g=a.tag.match(d);if(!g)return f(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var h=g[1],i='if(!_.isUndefined(__blocks["'+h+'"])) {'+b+"}";f(null,i)}}),a.register("tags/include.js",function(a,b,c){var d=c("../utils"),e=/^include\s+(.+)$/;a.exports.tags={};var f=a.exports.tags.include={},g=a.exports.helpers={};f.isBlock=!1,f.compile=function(a,b,c,d){var f=a.tag.match(e);if(!f)return d(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var g=f[1];c.__compilationEnd.unshift("});");var h="__helpers.include("+g+", __template,"+"__data, function(err, rendered) {"+"__acc.push(rendered);";d(null,h)},g.include=function(a,b,c,d){function e(a,b){if(a)return d(a);d(null,b)}b._renderRelative(a,c,null,e)}}),a.register("tags/print.js",function(a,b,c){function n(a){var b=function(b,c,d,e){var g=b.tag.match(f);if(!g)return e(new Error("Compilation error: Unable to parse tag `"+b.tag+"`."));if(g[1]){var h=parseInt(g[1])-1;b.__originalTag=d.__print[h]}var i=g[2],j=g[3]?o(g[3],a):a,i="__tools.filter("+i+", "+"["+j.join(",")+"]"+")",k;b.options.strict?k="__acc.push("+i+");":k="try {var __tmp = "+i+";"+"} catch(__err) {"+"if(__err instanceof ReferenceError) {"+'__tmp = "";'+"} else {"+"throw __err;"+"}"+"}"+"__acc.push(__tmp);",e(null,k)};return b.untokenize=function(a,b){return a.__originalTag?a.__originalTag:"{{"+a.tag+"}}"},b}function o(a,b){var c=!1;return a=a.split(g).filter(function(b){return b=="raw"?(c=!0,!1):!0}).map(function(b){b=b.match(i),b[1]=b[1].replace('"','"');if(!b[2])return'"'+b[1]+'"';var c=b[2].split(h);return'["'+b[1]+'", '+c.join(",")+"]"}),c||(a=a.concat(b)),_.uniq(a)}var d=c("../filter"),e=/\$\{([^\}]*)\}/g,f=/^(?:=|html)\s+(?:\:(\d+)\s+)?([^|]+)(?:\|(.*))?$/,g=/\|(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g,h=/\,(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g,i=/^([a-z]+)\s*(?:\((.*)\))?$/i,j=["escapeIfUnsafe"].map(JSON.stringify),k=[];a.exports.tags={};var l=a.exports.tags["="]={},m=a.exports.tags.html={};l.isBlock=!1,m.isBlock=!1,l.beforeProcessor=function(a,b,c){b.__print=[],a=a.replace(e,function(a,c){return b.__print.push(a),"{{= :"+b.__print.length+" "+c+"}}"}),c(null,a)},l.compile=n(j),m.compile=n(k)}),a.register("tags/raw.js",function(a,b,c){var d=c("../utils"),e=/\{\{\s*verbatim\s*\}\}((?:.|\n)*?)\{\{\s*\/\s*verbatim\s*\}\}|{\{\s*raw\s*\}\}((?:.|\n)*?)\{\{\s*\/\s*raw\s*\}\}/g;a.exports.tags={};var f=a.exports.tags.verbatim={};f.isBlock=!1,f.compile=function(a,b,c,e){var f=parseInt(a.tag.split(" ")[1])-1;e(null,'__acc.push("'+d.escapeCompiledString(c.__verbatim[f])+'");')},f.beforeProcessorPrepend=!0,f.beforeProcessor=function(a,b,c){b.__verbatim=[],a=a.replace(e,function(c,d,e){return b.__verbatim.push(d||e),"{{verbatim "+b.__verbatim.length+"}}"}),c(null,a)}}),a.register("tags/tmpl.js",function(a,b,c){var d=c("../utils"),e=/^tmpl\s+(.*)$/;a.exports.tags={};var f=a.exports.tags.tmpl={};f.isBlock=!1,f.compile=function(a,b,c,d){var f=a.tag.match(e);if(!f)return d(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var g=f[1];c.__compilationEnd.unshift("});"),d(null,"__template._nest("+g+", __data, "+"function(err, rendered){"+"__acc.push(rendered);")}}),a.register("template.js",function(a,b,c){function m(a,b){_.isObject(a)&&!b&&(b=a,a=null),b=b?_.clone(b):{},b=_.defaults(b,k),b.cacheContext=b.cacheContext||m,this.template=a,this.options=b,this._compiled=null;if(b.cache&&!(this._getCache()instanceof b.cacheHandler)){var c=[b.cacheHandler].concat(b.cacheOptions);b.cacheContext[b._cacheProp]=typeof window!="undefined"?new b.cacheHandler:construct.apply(this,c)}}var d=c("./cache"),e=d,f=c("./utils"),g=c("./token"),h=c("./tools"),i=c("./compiler"),j=c("./filter"),k={lookup:f.lookupTemplate,load:f.loadTemplate,path:null,cache:!0,cacheHandler:d,cacheOptions:[],lookupPaths:[],cacheTmplHandler:e,cacheTmplOptions:[1e3],useIsolatedTmplCache:!0,cacheContext:null,strict:!0,eachCounters:!0,_parent:null,_cacheAttachment:"_cache",_cacheTmplAttachment:"_nestCache"},l={filter:j,utils:f,tools:h};m.prototype._getCache=function(){return this.options.cacheContext[this.options._cacheProp]},m.prototype.loadFile=function(a,b){b(new Error("Client mode does not support reading from file."))},m.prototype.render=function(a,b){_.isFunction(a)&&!b&&(b=a,a={}),a||(a={});var c="template::"+this._cacheKey();!this.compiled&&this.options.cache&&(this._compiled=this._getCache().get(c));if(this._compiled)return this._renderCompiled(a,b);var d=this;this._compile(function(c){if(c)return b(c);d._renderCompiled(a,b)})},m.prototype.loadAndRender=function(a,b,c){c(new Error("Client mode does not support reading from file."))},m.prototype._renderCompiled=function(b,c){try{this._compiled.call(this._compiled,this,l,_,b,g.helpers,c)}catch(d){c(d)}},m.prototype._compile=function(a){var b=this;if(!_.isString(this.template))return a(new Error("Template contents not set"));(new i(this)).compile(function(c,d){if(c)return a(c);b._compiled=d;var e="template::"+b._cacheKey();b.options.cache&&b._getCache().cache(e,d),a(null,d)})},m.prototype._nest=function(a,b,c){var d=_.clone(this.options);d.useIsolatedTmplCache&&(d._cacheAttachment=d._cacheTmplAttachment,d.cacheHandler=d.cacheTmplHandler,d.cacheOptions=d.cacheTmplOptions),(new m(a,d)).render(b,function(b,d){if(b)return c(b);c(null,d)})},m.prototype._renderRelative=function(a,b,c,d){function j(a,b){if(a)return d(a);e.options.cache&&e._getCache().cache(h,b),g.loadFile(b,k)}function k(a,c){if(a)return d(a);g.render(b,l)}function l(a,b){if(a)return d(a);d(null,b)}var e=this,f=_.clone(this.options);f._parent=c;var g=new m(f),h="path::"+this._cacheKey()+"::"+a,i;this.options.cache&&(i=this._getCache().get(h)),i?g.loadFile(i,k):this.options.lookup(a,this,j)},m.prototype._cacheKey=function(){return this.options.path||this.template||null},b=a.exports=m}),a.register("token.js",function(a,b,c){function l(a,b,c){this.parent=b,this.children=[],this.tag=null,this.tagType=null,this.options=c,this.root=a}function m(a,b,c,d){m._superclass.call(this,b,c,d),this.literal=a}function n(a,b){n._superclass.call(this,this,null,b),a||(a=[]),this.head=[],this.children=a}function o(a,b,c,d,e,f){o._superclass.call(this,c,d,f),this.tag=a,this.tagType=b,e||(e=[]),this.children=e,this.intermediate=[]}function p(a,b,c,d,e){p._superclass.call(this,c,d,e),this.tag=a,this.tagType=b}function q(a,b,c,d,e,f){q._superclass.call(this,a,b,c,d,e,f)}function r(a,b){b.beforeProcessor&&(b.beforeProcessorPrepend?j.unshift(b.beforeProcessor):j.push(b.beforeProcessor)),b.headDeclarations&&g.push(b.headDeclarations),b.footDeclarations&&h.push(b.footDeclarations);if(b.helpers)for(helperName in b.helpers)s(helperName,b.helpers[helperName]);i[a]=b,b.tagName=a}function s(a,b){k[a]=b}function t(a){a=a||d.files.requireDir(__dirname+"/tags/");for(file in a){var b=a[file].tags,c=a[file].helpers;for(tag in b)r(tag,b[tag]);if(c)for(helperName in c)s(helperName,c[helperName])}}var d,e=c("./utils"),f=d?d.classes.extend:e.inherits,g=[],h=[],i={},j=[],k={};l.prototype.compile=function(a,b){b(new Error("Stub method BaseToken#compile must be overloaded"))},l.prototype.lookupTag=function(a){if(i[a])return i[a];if(this.tagType&&this.tagType.intermediateTags&&this.tagType.intermediateTags[a])return this.tagType.intermediateTags[a].isIntermediate=!0,this.tagType.intermediateTags[a]},f(m,l),m.prototype.compile=function(a,b){this._compiled='__acc.push("'+e.escapeCompiledString(this.literal)+'");',b(null,this._compiled)},f(n,l),n.prototype.compile=function(a,b){function d(d,e){if(d)return b(d);var e="var __this = this;var __acc = [];var __blocks = {};if(__template.options && __template.options._parent) {__blocks = __template.options._parent.blocks;}var __tmp;var __err;__data = __data || {};"+g.join("")+"with(__data) {"+e+h.join("")+'var __compiled = new String(__acc.join(""));'+"__compiled.blocks = __blocks;"+"__callback(null, __compiled);"+a.__compilationEnd.join("")+"}";c._compiled=e,b(null,e)}var c=this;e.compileTokens(this.children,a,d)},f(o,l),o.prototype.compile=function(a,b){function i(f,g){if(f)return b(f);d=g,e.compileTokenArray(c.intermediate,a,j)}function j(e,h){if(e)return b(e);f=h,g(c,d,f,a,k)}function k(a,d){if(a)return b(a);c._compiled=d,b(null,d)}var c=this,d,f,g=this.tagType.compile,h=g.joinCompilationResult!==!1?"compileTokens":"compileTokenArray";e[h](this.children,a,i)},f(p,l),p.prototype.compile=function(a,b){function d(a,d){if(a)return b(a);c._compiled=d,b(null,d)}var c=this,e=this.tagType.compile(this,null,a,d)},p.prototype.untokenize=function(a){return this.tagType.compile.untokenize?this.tagType.compile.untokenize(this,a):"{{"+this.tag+"}}"},f(q,o),q.prototype.compile=function(a,b){function d(a,c){if(a)return b(a);b(null,c)}var c=this;e.compileTokens(this.children,a,d)},q.prototype.lookupTag=function(a){return this.parent.lookupTag(a)},b=a.exports={headDeclarations:[],BaseToken:l,RootToken:n,BlockToken:o,IntermediateToken:q,LeafToken:p,LiteralToken:m,headDeclarations:g,footDeclarations:h,tags:i,tagBeforeProcessors:j,helpers:k,registerTag:r,registerHelper:s};var u=["block","comment","each","if","print","raw","tmpl","ifblock","as"],v={};_.each(u,function(a){v[a]=c("./tags/"+a)}),t(v)}),a.register("tools.js",function(a,b,c){var d=c("./token"),e=c("./filter"),f=c("./utils"),g=/\s+(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g;b.createSimpleTag=function(b,c){d.helpers[b]=c,d.tags[b]={compile:function(a,c,d,e){var f=a.tag.split(g);f[0]="__data";var h=f.join(","),i='__acc.push(__tools.tools.escapeIfUnsafe(__helpers["'+b+'"]('+h+")"+"));";e(null,i)}}},b.createFilter=function(b,c){e.filters[b]=c};var h=b.escape=function(a){return a.toString().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#146;")};b.safe=function(a){return a instanceof String||(a=new String(a)),a.safe=!0,a},b.escapeIfUnsafe=function(a){return a.safe?a:h(a)},b.registerTag=d.registerTag,b.registerHelper=d.registerHelpers,b.escapeCompiledString=f.escapeCompiledString,b.applyAll=f.applyAll,a.exports=b}),a.register("utils.js",function(a,b,c){function f(a,b,c,d){function e(b){if(b)return d(b);a.length>0?setTimeout(f,0):d()}function f(){var d=a.shift();b.apply(this,[d].concat(c).concat([e]))}typeof c=="function"&&!d&&(d=c,c=null),c||(c=[]),a=a.slice(0),a.length>0?setTimeout(f,0):d()}function i(a,b,c){function f(a,c){a.compile(b,function(b,e){if(b)return c(b);d.push(e),c(null,e)}),e++}function h(a){if(a)return c(a);c(null,d)}var d=[],e=0;g(a,f,h)}var d,e=".kiwi",g=d?d.asyncForEach:f,h=b.apply=function(a,b,c,d){function e(a,b){if(a)return d(a);d(null,b)}typeof c=="function"&&!d&&(d=c,c=null),b.apply(this,[a].concat(c||[]).concat([e]))};b.applyAll=function(a,b,c,d){function e(b,d){h(a,b,c||[],function(c,e){if(c)return d(c);a=e,d()})}function f(b){if(b)return d(b);d(null,a)}typeof c=="function"&&!d&&(d=c,c=null),g(b,e,f)},b.compileTokenArray=i,b.compileTokens=function(a,b,c){i(a,b,function(a,b){if(a)return c(a);c(null,b.join(""))})},b.escapeCompiledString=function(a){return a.replace(/([\\"])/g,"\\$1").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")},b.isIterable=function(a){return typeof a=="object"&&!(a instanceof String)},b.inherits=function(a,b){function c(){}c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a,a._superclass=b,a._superproto=b.prototype},a.exports=b}),window.kiwi=a("kiwi")})();
+(function(){function a(b){var c=a.resolve(b),d=a.modules[c];if(!d)throw new Error('failed to require "'+b+'"');return d.exports||(d.exports={},d.call(d.exports,d,d.exports,a.relative(c))),d.exports}a.modules={},a.resolve=function(b){var c=b,d=b+".js",e=b+"/index.js";return a.modules[d]&&d||a.modules[e]&&e||c},a.register=function(b,c){a.modules[b]=c},a.relative=function(b){return function(c){if("."!=c.charAt(0))return a(c);var d=b.split("/"),e=c.split("/");d.pop();for(var f=0;f<e.length;f++){var g=e[f];".."==g?d.pop():"."!=g&&d.push(g)}return a(d.join("/"))}},a.register("cache.js",function(a,b,c){function d(){this._cache={}}d.prototype.cache=function(a,b){if(_.isUndefined(b))return;this._cache[a]=b},d.prototype.get=function(a){return this._cache[a]},a.exports=d}),a.register("compiler.js",function(a,b,c){var d=c("./token"),e=c("./utils"),f="{{",g="}}",h=f.length,i=/^(\/)?\s*([^\s\}\(]*)/,j=a.exports=function(a){this.template=a,this.source=a.template,this.options=a.options,this.helpers={},this.__compilationEnd=[]};j.prototype.compile=function(a){function c(c,d){if(c)return a(c);b._tokenize(d,f)}function f(c,d){if(c)return a(c);d.compile(b,g)}function g(c,d){if(c)return a(c);var e=new Function("__template","__tools","_","__data","__helpers","__callback",d);e.__helpers=b.helpers,a(null,e)}var b=this;e.applyAll(this.source,d.tagBeforeProcessors,[this],c)},j.prototype._tokenize=function(a,b){var c=a,e=new d.RootToken,i=e,j=!1,k;for(;;){var l=c.search(j?g:f);if(l===-1){this._pushLiteralToken(i,e,c);break}j&&(l+=h),k=c.slice(0,l),c=c.slice(l);if(!j)this._pushLiteralToken(i,e,k);else{k=k.slice(2,-2);try{e=this._pushToken(i,e,k)}catch(m){return b(m)}}j=!j}if(i!==e)return b(new Error("Tokenization error: unexpected end of file, expected `"+e.tag.tagName+"`."));b(null,i)},j.prototype._pushLiteralToken=function(a,b,c){if(!c.length)return;b.children.push(new d.LiteralToken(c,a))},j.prototype._pushToken=function(a,b,c){var e=c.match(i),f=e[2],g=e[1]!=="/",h=b.lookupTag(f),j;if(!h)throw new Error("Tokenization error: Unknown tag `"+f+"`.");if(h.isIntermediate)return b.tagType.isIntermediate&&(b=b.parent),j=new d.IntermediateToken(c,h,a,b,[],this.options),b.intermediate.push(j),j;if(h.isBlock){if(g)return j=new d.BlockToken(c,h,a,b,[],this.options),b.children.push(j),j;if(!b.parent)throw new Error("Tokenization error: unexpected `"+f+"` tag at root level.");b.tagType.isIntermediate&&(b=b.parent);if(b.tagType.tagName!==f)throw new Error("Tokenization error: unexpected `"+f+"` tag, expected `"+b.tag.tagName+"`.");return b.parent}if(!g)throw new Error("Tokenization error: `"+f+"` is not a block tag.");return j=new d.LeafToken(c,h,a,b,this.options),b.children.push(j),b},j.prototype.registerTemplateHelper=function(a,b){this.helpers[a]=b}}),a.register("filter.js",function(a,b,c){function d(b,c){var d;c.forEach(function(c){var e=[];_.isArray(c)&&(e=c.slice(1),c=c[0]);var f=a.exports.filters[c];if(!f)return d=c,!1;b=f.apply(this,[b].concat(e))});if(d)throw new Error("Rendering error: Unknown filter `"+d+"`.");return b}function f(a){a=a||frame.files.requireDir(__dirname+"/filters/");for(var b in a){var c=a[b];for(var d in c)e[d]=c[d]}}a.exports=d;var e=a.exports.filters={},g=["base","datetime"],h={};_.each(g,function(a){h[a]=c("./filters/"+a)}),f(h)}),a.register("filters/base.js",function(a,b,c){var d=c("../tools"),e=c("../utils");b.escape=function(a){if(a===null||a===undefined)return"";if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.escape(a)}),c}return d.escape(a)},b.escapeIfUnsafe=function(a){if(a===null||a===undefined)return"";if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.escapeIfUnsafe(a)}),c}return d.escapeIfUnsafe(a)},b.capitalize=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.capitalize(a)}),c}return a=a.toString(),a.charAt(0).toUpperCase()+a.slice(1)},b.upper=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.upper(a)}),c}return a.toString().toUpperCase()},b.lower=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.lower(a)}),c}return a.toString().toLowerCase()},b.json=function(a){return JSON.stringify(a)},b.add=function(a,c){if(typeof a=="object"){var d={};return _.each(a,function(a,e){d[e]=b.add(a,c)}),d}return parseFloat(a)+parseFloat(c)},b.subtract=function(a,c){return b.add(a,-parseInt(c,10))},b.mul=function(a,c){if(typeof a=="object"){var d={};return _.each(a,function(a,e){d[e]=b.mul(a,c)}),d}return parseFloat(a)*parseFloat(c)},b.div=function(a,c){if(typeof a=="object"){var d={};return _.each(a,function(a,e){d[e]=b.div(a,c)}),d}return parseFloat(a)/parseFloat(c)},b.incr=function(a,c){return b.add(a,1)},b.decr=function(a,c){return b.add(a,-1)},b.round=function(a){if(typeof a=="object"){var c={};return _.each(a,function(a,d){c[d]=b.round(a)}),c}return Math.round(a)},b.floor=function(a){if(typeof a=="object"){var c={};return _.each(a,function(a,d){c[d]=b.floor(a)}),c}return Math.floor(a)},b.ceil=function(a){if(typeof a=="object"){var c={};return _.each(a,function(a,d){c[d]=b.ceil(a)}),c}return Math.ceil(a)},b.cut=function(a,c){if(typeof a=="object"){var d={};return _.each(a,function(a,e){d[e]=b.cut(a,c)}),d}return a.toString().replace(c,"")},b.addslashes=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.capitalize(a)}),c}return a.toString().replace(/\\/g,"\\\\").replace(/\'/g,"\\'").replace(/\"/g,'\\"').replace(/\0/g,"\\0")},b.stripslashes=function(a){if(e.isIterable(a)){var c={};return _.each(a,function(a,d){c[d]=b.capitalize(a)}),c}return a.toString().replace(/\\'/g,"'").replace(/\\"/g,'"').replace(/\\0/g,"\0").replace(/\\\\/g,"\\")},b.first=function(a){return typeof a=="object"&&!_.isArray(a)?"":_.isString(a)?a.substr(0,1):_.first(a)},b.last=function(a){return typeof a=="object"&&!_.isArray(a)?"":_.isString(a)?a.slice(-1):_.last(a)},b.length=function(a){return typeof a=="object"?_.keys(a).length:a.length},b.reverse=function(a){return _.isArray(a)?a.reverse():a},b.join=function(a,b){if(_.isArray(a))return a.join(b);if(typeof a=="object"){var c=[];return _.each(a,function(a,b){c.push(a)}),c.join(b)}return a},b.urlencode=function(a){return encodeURIComponent(a)},b.urldecode=function(a){return decodeURIComponent(a)},b.replace=function(a,b,c,d){return a.replace(new RegExp(b,d),c)},a.exports=b}),a.register("filters/datetime.js",function(a,b,c){b.timeago=function(a){return moment(a).fromNow()},b.relativedate=function(a){return moment(a).calendar()},b.date=function(a,b){return moment(a).format(b)},a.exports=b}),a.register("kiwi.js",function(a,b,c){var d=b.Template=c("./template");b.tools=c("./tools"),b.version="0.1.3",a.exports=b}),a.register("tags/as.js",function(a,b,c){var d=/^as\s+([^\s]+)$/;a.exports.tags={};var e=a.exports.tags.as={};e.isBlock=!0,e.compile=function(a,b,c,e,f){var g=a.tag.match(d);if(!g)return f(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var h=g[1],i="(function(parentAcc) {var __acc = [];"+b+'var __joined = __acc.join("");'+'__data["'+h+'"] = __tools.tools.safe(__joined);'+"})(__acc);";f(null,i)}}),a.register("tags/block.js",function(a,b,c){var d=/^block\s+([^\s]+)(?:\s+(append|prepend))?$/;a.exports.tags={};var e=a.exports.tags.block={},f=a.exports.tags.parent={};e.isBlock=!0,e.compile=function(a,b,c,e,f){var g=a.tag.match(d);if(!g)return f(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var h=g[1],i=g[2],j="(function(parentAcc) {var __acc = [];"+b+'var __currentBlock = __acc.join("");'+'if(!_.isUndefined(__blocks["'+h+'"])) {'+'__tmp = new String(__blocks["'+h+'"].replace('+"/\\{\\{parent\\}\\}/g, __currentBlock"+"));"+'if(__blocks["'+h+'"].mode) {'+'__tmp.mode = __blocks["'+h+'"].mode;'+"}"+'__blocks["'+h+'"] = __tmp;'+"}"+"var __acc = [];"+'if(_.isUndefined(__blocks["'+h+'"]) ||'+'__blocks["'+h+'"].mode) {'+'if(__blocks["'+h+'"] &&'+'__blocks["'+h+'"].mode == "append") {'+'__acc.push(__blocks["'+h+'"]);'+"}"+"__acc.push(__currentBlock);"+'if(__blocks["'+h+'"] &&'+'__blocks["'+h+'"].mode == "prepend") {'+'__acc.push(__blocks["'+h+'"]);'+"}"+"} else {"+'__acc.push(__blocks["'+h+'"]);'+"}"+'var __joined = new String(__acc.join(""));'+(i?'__joined.mode = "'+i+'";':"")+"parentAcc.push(__joined);"+'__blocks["'+h+'"] = __joined;'+"})(__acc);";f(null,j)},f.compile=function(a,b,c,d){if(!a.parent.tagType||a.parent.tagType.tagName!=="block")return d(new Error("Compilation error: `parent` must be immediate child of a `block` tag."));a.parent.hasParentTag=!0,d(null,'__acc.push("{{parent}}");')}}),a.register("tags/comment.js",function(a,b,c){var d=/\{\{\s*comment\s*\}\}((.|\n)*?)\{\{\s*\/\s*comment\s*\}\}/g;a.exports.tags={};var e=a.exports.tags["#"]={};e.isBlock=!1,e.compile=function(a,b,c,d){d(null,"")},e.beforeProcessor=function(a,b,c){a=a.replace(d,""),c(null,a)}}),a.register("tags/each.js",function(a,b,c){var d=/^each(?:\(([^\)\s]+)\s*\,\s*([^\)\s]+)\s*\))?\s+(.*)$/;a.exports.tags={};var e=a.exports.tags.each={},f=e.intermediateTags={},g=f.empty={};e.isBlock=!0,e.headDeclarations="var _eachLoop;",e.compile=function(a,b,c,e,f){var g=a.tag.match(d);if(!g)return f(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var h=g[1]||"$value",i=g[2]||"$index",j=g[3],k;if(c.length){if(c.length>1)return f(new Error("Compilation Error: Too many intermediate tags for `each`."));if(a.intermediate[0].tag!=="empty")return f(new Error("Compilation Error: Unexpected tag `"+a.intermediate[0].tag+"`."));k=c[0]}var l="(function(__parentEachLoop) {";a.options.strict?l+="__tmp = "+j+";":l+="try {__tmp = "+j+"} catch(__err) {"+"if(__err instanceof ReferenceError) {"+"__tmp = [];"+"} else {"+"throw __err;"+"}"+"}",l+="var __eachLoopLength = _.size(__tmp);",k&&(l+="if(__eachLoopLength) {"),a.options.eachCounters?l+="var __eachLoopCounter = 0;_.each(__tmp, function("+h+","+i+"){"+"_eachLoop = {"+"size: __eachLoopLength,"+"counter0: __eachLoopCounter,"+"counter: __eachLoopCounter + 1,"+"revcounter0: __eachLoopLength - __eachLoopCounter - 1,"+"revcounter: __eachLoopLength - __eachLoopCounter,"+"first: __eachLoopCounter === 0,"+"last: __eachLoopCounter + 1 === __eachLoopLength,"+"parentLoop: __parentEachLoop"+"};"+b+"__eachLoopCounter++;"+"});":l+="_.each(__tmp, function("+h+","+i+") {"+b+"});",k&&(l+="} else {"+k+"}"),l+="})(_eachLoop);",f(null,l)}}),a.register("tags/extend.js",function(a,b,c){var d=c("../utils"),e=/^extend\s+(.+)$/;a.exports.tags={};var f=a.exports.tags.extend={},g=a.exports.helpers={};f.isBlock=!1,f.compile=function(a,b,c,d){if(a.root.children[0]!==a)return d(new Error("Compilation error: Extend tag must be defined at the very beginning of the template."));var f=a.tag.match(e);if(!f)return d(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var g=f[1],h="var __originalCallback = __callback;__callback = function(err, compiled) {__helpers.extend("+g+", __compiled, __template,"+"__data, __originalCallback);"+"};";d(null,h)},g.extend=function(a,b,c,d,e){function f(a,b){if(a)return e(a);e(null,b)}c._renderRelative(a,d,b,f)}}),a.register("tags/if.js",function(a,b,c){function i(a,b){var c;return b?c="if("+a+")":c="try {__tmp = "+a+"} catch(__err) {"+"if(__err instanceof ReferenceError) {"+"__tmp = false;"+"} else {"+"throw __err;"+"}"+"}"+"if(__tmp)",c}var d=/^if\s+(.*)$/,e=/^else(?:\s+(.*))?$/;a.exports.tags={};var f=a.exports.tags["if"]={},g=f.intermediateTags={},h=g["else"]={};f.isBlock=!0,f.compile=function(a,b,c,f,g){var h=a.tag.match(d);if(!h)return g(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var j=h[1],k=["}"],l=i(j,a.options.strict);l+="{"+b;var m;_.each(a.intermediate,function(b,d){var f=b.tag,g=c[d],h=f.match(e);if(!h){m=new Error("Compilation error: Unable to parse tag `"+a.tag+"`.");return}var j=h[1];j?(k.push("}"),l+="} else {"+i(j,a.options.strict)+"{"):l+="} else {",l+=c[d]});if(m)return g(m);l+=k.join(""),g(null,l)}}),a.register("tags/ifblock.js",function(a,b,c){var d=/^ifblock\s+([^\s]+)$/;a.exports.tags={};var e=a.exports.tags.ifblock={};e.isBlock=!0,e.compile=function(a,b,c,e,f){var g=a.tag.match(d);if(!g)return f(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var h=g[1],i='if(!_.isUndefined(__blocks["'+h+'"])) {'+b+"}";f(null,i)}}),a.register("tags/include.js",function(a,b,c){var d=c("../utils"),e=/^include\s+(.+)$/;a.exports.tags={};var f=a.exports.tags.include={},g=a.exports.helpers={};f.isBlock=!1,f.compile=function(a,b,c,d){var f=a.tag.match(e);if(!f)return d(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var g=f[1];c.__compilationEnd.unshift("});");var h="__helpers.include("+g+", __template,"+"__data, function(err, rendered) {"+"__acc.push(rendered);";d(null,h)},g.include=function(a,b,c,d){function e(a,b){if(a)return d(a);d(null,b)}b._renderRelative(a,c,null,e)}}),a.register("tags/print.js",function(a,b,c){function n(a){var b=function(b,c,d,e){var g=b.tag.match(f);if(!g)return e(new Error("Compilation error: Unable to parse tag `"+b.tag+"`."));if(g[1]){var h=parseInt(g[1],10)-1;b.__originalTag=d.__print[h]}var i=g[2],j=g[3]?o(g[3],a):a;i="__tools.filter("+i+", "+"["+j.join(",")+"]"+")";var k;b.options.strict?k="__acc.push("+i+");":k="try {var __tmp = "+i+";"+"} catch(__err) {"+"if(__err instanceof ReferenceError) {"+'__tmp = "";'+"} else {"+"throw __err;"+"}"+"}"+"__acc.push(__tmp);",e(null,k)};return b.untokenize=function(a,b){return a.__originalTag?a.__originalTag:"{{"+a.tag+"}}"},b}function o(a,b){var c=!1;return a=a.split(g).filter(function(b){return b==="raw"?(c=!0,!1):!0}).map(function(b){b=b.match(i),b[1]=b[1].replace('"','"');if(!b[2])return'"'+b[1]+'"';var c=b[2].split(h);return'["'+b[1]+'", '+c.join(",")+"]"}),c||(a=a.concat(b)),_.uniq(a)}var d=c("../filter"),e=/\$\{([^\}]*)\}/g,f=/^(?:=|html)\s+(?:\:(\d+)\s+)?([^|]+)(?:\|(.*))?$/,g=/\|(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g,h=/\,(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g,i=/^([a-z]+)\s*(?:\((.*)\))?$/i,j=["escapeIfUnsafe"].map(JSON.stringify),k=[];a.exports.tags={};var l=a.exports.tags["="]={},m=a.exports.tags.html={};l.isBlock=!1,m.isBlock=!1,l.beforeProcessor=function(a,b,c){b.__print=[],a=a.replace(e,function(a,c){return b.__print.push(a),"{{= :"+b.__print.length+" "+c+"}}"}),c(null,a)},l.compile=n(j),m.compile=n(k)}),a.register("tags/raw.js",function(a,b,c){var d=c("../utils"),e=new RegExp("\\{\\{\\s*verbatim\\s*\\}\\}((?:.|\\n)*?)\\{\\{\\s*\\/\\s*verbatim\\s*\\}\\}|{\\{\\s*raw\\s*\\}\\}((?:.|\\n)*?)\\{\\{\\s*\\/\\s*raw\\s*\\}\\}","g");a.exports.tags={};var f=a.exports.tags.verbatim={};f.isBlock=!1,f.compile=function(a,b,c,e){var f=parseInt(a.tag.split(" ")[1],10)-1;e(null,'__acc.push("'+d.escapeCompiledString(c.__verbatim[f])+'");')},f.beforeProcessorPrepend=!0,f.beforeProcessor=function(a,b,c){b.__verbatim=[],a=a.replace(e,function(c,d,e){return b.__verbatim.push(d||e),"{{verbatim "+b.__verbatim.length+"}}"}),c(null,a)}}),a.register("tags/tmpl.js",function(a,b,c){var d=c("../utils"),e=/^tmpl\s+(.*)$/;a.exports.tags={};var f=a.exports.tags.tmpl={};f.isBlock=!1,f.compile=function(a,b,c,d){var f=a.tag.match(e);if(!f)return d(new Error("Compilation error: Unable to parse tag `"+a.tag+"`."));var g=f[1];c.__compilationEnd.unshift("});"),d(null,"__template._nest("+g+", __data, "+"function(err, rendered){"+"__acc.push(rendered);")}}),a.register("template.js",function(a,b,c){function m(a,b){_.isObject(a)&&!b&&(b=a,a=null),b=b?_.clone(b):{},b=_.defaults(b,k),b.cacheContext=b.cacheContext||m,this.template=a,this.options=b,this._compiled=null;if(b.cache&&!(this._getCache()instanceof b.cacheHandler)){var c=[b.cacheHandler].concat(b.cacheOptions);b.cacheContext[b._cacheProp]=typeof window!="undefined"?new b.cacheHandler:construct.apply(this,c)}}var d=c("./cache"),e=d,f=c("./utils"),g=c("./token"),h=c("./tools"),i=c("./compiler"),j=c("./filter"),k={lookup:f.lookupTemplate,load:f.loadTemplate,path:null,cache:!0,cacheHandler:d,cacheOptions:[],lookupPaths:[],cacheTmplHandler:e,cacheTmplOptions:[1e3],useIsolatedTmplCache:!0,cacheContext:null,strict:!0,eachCounters:!0,_parent:null,_cacheAttachment:"_cache",_cacheTmplAttachment:"_nestCache"},l={filter:j,utils:f,tools:h};m.prototype._getCache=function(){return this.options.cacheContext[this.options._cacheProp]},m.prototype.loadFile=function(a,b){b(new Error("Client mode does not support reading from file."))},m.prototype.render=function(a,b){_.isFunction(a)&&!b&&(b=a,a={}),a||(a={});var c="template::"+this._cacheKey();!this.compiled&&this.options.cache&&(this._compiled=this._getCache().get(c));if(this._compiled)return this._renderCompiled(a,b);var d=this;this._compile(function(c){if(c)return b(c);d._renderCompiled(a,b)})},m.prototype.loadAndRender=function(a,b,c){c(new Error("Client mode does not support reading from file."))},m.prototype._renderCompiled=function(b,c){try{this._compiled.call(this._compiled,this,l,_,b,g.helpers,c)}catch(d){c(d)}},m.prototype._compile=function(a){var b=this;if(!_.isString(this.template))return a(new Error("Template contents not set"));(new i(this)).compile(function(c,d){if(c)return a(c);b._compiled=d;var e="template::"+b._cacheKey();b.options.cache&&b._getCache().cache(e,d),a(null,d)})},m.prototype._nest=function(a,b,c){var d=_.clone(this.options);d.useIsolatedTmplCache&&(d._cacheAttachment=d._cacheTmplAttachment,d.cacheHandler=d.cacheTmplHandler,d.cacheOptions=d.cacheTmplOptions),(new m(a,d)).render(b,function(b,d){if(b)return c(b);c(null,d)})},m.prototype._renderRelative=function(a,b,c,d){function j(a,b){if(a)return d(a);e.options.cache&&e._getCache().cache(h,b),g.loadFile(b,k)}function k(a,c){if(a)return d(a);g.render(b,l)}function l(a,b){if(a)return d(a);d(null,b)}var e=this,f=_.clone(this.options);f._parent=c;var g=new m(f),h="path::"+this._cacheKey()+"::"+a,i;this.options.cache&&(i=this._getCache().get(h)),i?g.loadFile(i,k):this.options.lookup(a,this,j)},m.prototype._cacheKey=function(){return this.options.path||this.template||null},a.exports=m}),a.register("token.js",function(a,b,c){function l(a,b,c){this.parent=b,this.children=[],this.tag=null,this.tagType=null,this.options=c,this.root=a}function m(a,b,c,d){m._superclass.call(this,b,c,d),this.literal=a}function n(a,b){n._superclass.call(this,this,null,b),a||(a=[]),this.head=[],this.children=a}function o(a,b,c,d,e,f){o._superclass.call(this,c,d,f),this.tag=a,this.tagType=b,e||(e=[]),this.children=e,this.intermediate=[]}function p(a,b,c,d,e){p._superclass.call(this,c,d,e),this.tag=a,this.tagType=b}function q(a,b,c,d,e,f){q._superclass.call(this,a,b,c,d,e,f)}function r(a,b){b.beforeProcessor&&(b.beforeProcessorPrepend?j.unshift(b.beforeProcessor):j.push(b.beforeProcessor)),b.headDeclarations&&g.push(b.headDeclarations),b.footDeclarations&&h.push(b.footDeclarations);if(b.helpers)for(var c in b.helpers)s(c,b.helpers[c]);i[a]=b,b.tagName=a}function s(a,b){k[a]=b}function t(a){a=a||d.files.requireDir(__dirname+"/tags/");for(var b in a){var c=a[b].tags,e=a[b].helpers;for(var f in c)r(f,c[f]);if(e)for(var g in e)s(g,e[g])}}var d,e=c("./utils"),f=d?d.classes.extend:e.inherits,g=[],h=[],i={},j=[],k={};l.prototype.compile=function(a,b){b(new Error("Stub method BaseToken#compile must be overloaded"))},l.prototype.lookupTag=function(a){if(i[a])return i[a];if(this.tagType&&this.tagType.intermediateTags&&this.tagType.intermediateTags[a])return this.tagType.intermediateTags[a].isIntermediate=!0,this.tagType.intermediateTags[a]},f(m,l),m.prototype.compile=function(a,b){this._compiled='__acc.push("'+e.escapeCompiledString(this.literal)+'");',b(null,this._compiled)},f(n,l),n.prototype.compile=function(a,b){function d(d,e){if(d)return b(d);e="var __this = this;var __acc = [];var __blocks = {};if(__template.options && __template.options._parent) {__blocks = __template.options._parent.blocks;}var __tmp;var __err;__data = __data || {};"+g.join("")+"with(__data) {"+e+h.join("")+'var __compiled = new String(__acc.join(""));'+"__compiled.blocks = __blocks;"+"__callback(null, __compiled);"+a.__compilationEnd.join("")+"}",c._compiled=e,b(null,e)}var c=this;e.compileTokens(this.children,a,d)},f(o,l),o.prototype.compile=function(a,b){function i(f,g){if(f)return b(f);d=g,e.compileTokenArray(c.intermediate,a,j)}function j(e,h){if(e)return b(e);f=h,g(c,d,f,a,k)}function k(a,d){if(a)return b(a);c._compiled=d,b(null,d)}var c=this,d,f,g=this.tagType.compile,h=g.joinCompilationResult!==!1?"compileTokens":"compileTokenArray";e[h](this.children,a,i)},f(p,l),p.prototype.compile=function(a,b){function d(a,d){if(a)return b(a);c._compiled=d,b(null,d)}var c=this,e=this.tagType.compile(this,null,a,d)},p.prototype.untokenize=function(a){return this.tagType.compile.untokenize?this.tagType.compile.untokenize(this,a):"{{"+this.tag+"}}"},f(q,o),q.prototype.compile=function(a,b){function d(a,c){if(a)return b(a);b(null,c)}var c=this;e.compileTokens(this.children,a,d)},q.prototype.lookupTag=function(a){return this.parent.lookupTag(a)},a.exports={BaseToken:l,RootToken:n,BlockToken:o,IntermediateToken:q,LeafToken:p,LiteralToken:m,headDeclarations:g,footDeclarations:h,tags:i,tagBeforeProcessors:j,helpers:k,registerTag:r,registerHelper:s};var u=["block","comment","each","if","print","raw","tmpl","ifblock","as"],v={};_.each(u,function(a){v[a]=c("./tags/"+a)}),t(v)}),a.register("tools.js",function(a,b,c){var d=c("./token"),e=c("./filter"),f=c("./utils"),g=/\s+(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/g;b.createSimpleTag=function(b,c){d.helpers[b]=c,d.tags[b]={compile:function(a,c,d,e){var f=a.tag.split(g);f[0]="__data";var h=f.join(","),i='__acc.push(__tools.tools.escapeIfUnsafe(__helpers["'+b+'"]('+h+")"+"));";e(null,i)}}},b.createFilter=function(b,c){e.filters[b]=c};var h=b.escape=function(a){return a.toString().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#146;")},i=b.SafeString=String;b.safe=function(a){return a instanceof i||(a=new i(a)),a},b.escapeIfUnsafe=function(a){return a instanceof i?a:h(a)},b.registerTag=d.registerTag,b.registerHelper=d.registerHelpers,b.escapeCompiledString=f.escapeCompiledString,b.applyAll=f.applyAll,b.safeString=String,a.exports=b}),a.register("utils.js",function(a,b,c){function f(a,b,c,d){function e(b){if(b)return d(b);a.length>0?setTimeout(f,0):d()}function f(){var d=a.shift();b.apply(this,[d].concat(c).concat([e]))}typeof c=="function"&&!d&&(d=c,c=null),c||(c=[]),a=a.slice(0),a.length>0?setTimeout(f,0):d()}function i(a,b,c){function f(a,c){a.compile(b,function(b,e){if(b)return c(b);d.push(e),c(null,e)}),e++}function h(a){if(a)return c(a);c(null,d)}var d=[],e=0;g(a,f,h)}var d,e=".kiwi",g=d?d.asyncForEach:f,h=b.apply=function(a,b,c,d){function e(a,b){if(a)return d(a);d(null,b)}typeof c=="function"&&!d&&(d=c,c=null),b.apply(this,[a].concat(c||[]).concat([e]))};b.applyAll=function(a,b,c,d){function e(b,d){h(a,b,c||[],function(c,e){if(c)return d(c);a=e,d()})}function f(b){if(b)return d(b);d(null,a)}typeof c=="function"&&!d&&(d=c,c=null),g(b,e,f)},b.compileTokenArray=i,b.compileTokens=function(a,b,c){i(a,b,function(a,b){if(a)return c(a);c(null,b.join(""))})},b.escapeCompiledString=function(a){return a.replace(/([\\"])/g,"\\$1").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")},b.isIterable=function(a){return typeof a=="object"&&!(a instanceof String)},b.inherits=function(a,b){function c(){}c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a,a._superclass=b,a._superproto=b.prototype},a.exports=b}),window.kiwi=a("kiwi")})();
View
15 lib/cache.js
@@ -6,6 +6,15 @@
/**
+ * Module dependencies.
+ */
+
+// if node
+var _ = require('underscore');
+// end
+
+
+/**
* Basic cache for client mode.
*
* Constructor.
@@ -29,7 +38,7 @@ function Cache() {
Cache.prototype.cache = function(key, value) {
if(_.isUndefined(value)) return;
this._cache[key] = value;
-}
+};
/**
@@ -42,11 +51,11 @@ Cache.prototype.cache = function(key, value) {
Cache.prototype.get = function(key) {
return this._cache[key];
-}
+};
/**
* Module exports.
*/
-module.exports = exports = Cache;
+module.exports = Cache;
View
73 lib/compiler.js
@@ -37,7 +37,7 @@ var Compiler = module.exports = function(template) {
this.options = template.options;
this.helpers = {};
this.__compilationEnd = [];
-}
+};
/**
@@ -83,7 +83,7 @@ Compiler.prototype.compile = function(callback) {
// Apply tag before processors
utils.applyAll(this.source, token.tagBeforeProcessors, [this], onProcessed);
-}
+};
/**
@@ -107,7 +107,7 @@ Compiler.prototype._tokenize = function(source, callback) {
TAG_OPENING_DELIMITER
);
- if(nextInflexion == -1) {
+ if(nextInflexion === -1) {
this._pushLiteralToken(rootToken, currentToken, workingSource);
break;
} else {
@@ -133,15 +133,15 @@ Compiler.prototype._tokenize = function(source, callback) {
// Ensure we are at root level
if(rootToken !== currentToken) {
- return callback(new Error( 'Tokenization error: unexpected end of file, '
- + 'expected `'
- + currentToken.tag.tagName
- + '`.')
- );
+ return callback(new Error('Tokenization error: unexpected end of file, ' +
+ 'expected `' +
+ currentToken.tag.tagName +
+ '`.'
+ ));
}
callback(null, rootToken);
-}
+};
/**
@@ -155,7 +155,7 @@ Compiler.prototype._tokenize = function(source, callback) {
Compiler.prototype._pushLiteralToken = function(root, parent, literal) {
if(!literal.length) return;
parent.children.push(new token.LiteralToken(literal, root));
-}
+};
/**
@@ -173,6 +173,7 @@ Compiler.prototype._pushToken = function(root, current, tag) {
var tagName = match[2];
var openingTag = match[1] !== '/';
var tagType = current.lookupTag(tagName);
+ var newToken;
// Check whether we know this tag
if(!tagType) {
@@ -186,7 +187,7 @@ Compiler.prototype._pushToken = function(root, current, tag) {
if(current.tagType.isIntermediate) current = current.parent;
// Push the tag to the stack
- var newToken = new token.IntermediateToken(tag,
+ newToken = new token.IntermediateToken(tag,
tagType,
root,
current,
@@ -202,22 +203,22 @@ Compiler.prototype._pushToken = function(root, current, tag) {
// Handle opening tags
if(openingTag) {
- var newToken = new token.BlockToken(tag,
- tagType,
- root,
- current,
- [],
- this.options);
+ newToken = new token.BlockToken(tag,
+ tagType,
+ root,
+ current,
+ [],
+ this.options);