Comparing version 1.0.5-dev to 2.0.0
@@ -236,7 +236,4 @@ /* | ||
function writeCode(tree) { | ||
return 'i = i || "";var b = i + "";var _ = this;' + walk(tree) + 'return b;'; | ||
} | ||
Hogan.generate = function (code, text, options) { | ||
Hogan.generate = function (tree, text, options) { | ||
var code = 'var _=this;_.b(i=i||"");' + walk(tree) + 'return _.fl();'; | ||
if (options.asString) { | ||
@@ -246,3 +243,3 @@ return 'function(c,p,i){' + code + ';}'; | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan); | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan, options); | ||
} | ||
@@ -288,12 +285,11 @@ | ||
return 'if(_.s(_.' + method + '("' + esc(id) + '",c,p,1),' + | ||
'c,p,0,' + start + ',' + end + ', "' + tags + '")){' + | ||
'b += _.rs(c,p,' + | ||
'function(c,p){ var b = "";' + | ||
'c,p,0,' + start + ',' + end + ',"' + tags + '")){' + | ||
'_.rs(c,p,' + | ||
'function(c,p,_){' + | ||
walk(nodes) + | ||
'return b;});c.pop();}' + | ||
'else{b += _.b; _.b = ""};'; | ||
'});c.pop();}'; | ||
} | ||
function invertedSection(nodes, id, method) { | ||
return 'if (!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
return 'if(!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
walk(nodes) + | ||
@@ -304,18 +300,18 @@ '};'; | ||
function partial(tok) { | ||
return 'b += _.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '");'; | ||
return '_.b(_.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '"));'; | ||
} | ||
function tripleStache(id, method) { | ||
return 'b += (_.' + method + '("' + esc(id) + '",c,p,0));'; | ||
return '_.b(_.t(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function variable(id, method) { | ||
return 'b += (_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
return '_.b(_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function text(id) { | ||
return 'b += ' + id + ';'; | ||
return '_.b(' + id + ');'; | ||
} | ||
Hogan.parse = function(tokens, options) { | ||
Hogan.parse = function(tokens, text, options) { | ||
options = options || {}; | ||
@@ -349,5 +345,5 @@ return buildTree(tokens, '', [], options.sectionTags || []); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), options)), text, options); | ||
t = this.generate(this.parse(this.scan(text, options.delimiters), text, options), text, options); | ||
return this.cache[key] = t; | ||
}; | ||
})(typeof exports !== 'undefined' ? exports : Hogan); |
@@ -18,9 +18,9 @@ /* | ||
(function (Hogan) { | ||
Hogan.Template = function constructor(renderFunc, text, compiler) { | ||
if (renderFunc) { | ||
this.r = renderFunc; | ||
} | ||
(function (Hogan, useArrayBuffer) { | ||
Hogan.Template = function (renderFunc, text, compiler, options) { | ||
this.r = renderFunc || this.r; | ||
this.c = compiler; | ||
this.options = options; | ||
this.text = text || ''; | ||
this.buf = (useArrayBuffer) ? [] : ''; | ||
} | ||
@@ -35,2 +35,5 @@ | ||
// triple stache | ||
t: coerceToString, | ||
render: function render(context, partials, indent) { | ||
@@ -54,3 +57,3 @@ return this.ri([context], partials || {}, indent); | ||
if (this.c && typeof partial == 'string') { | ||
partial = this.c.compile(partial); | ||
partial = this.c.compile(partial, this.options); | ||
} | ||
@@ -63,7 +66,7 @@ | ||
rs: function(context, partials, section) { | ||
var buf = '', | ||
tail = context[context.length - 1]; | ||
var tail = context[context.length - 1]; | ||
if (!isArray(tail)) { | ||
return buf = section(context, partials); | ||
section(context, partials, this); | ||
return; | ||
} | ||
@@ -73,7 +76,5 @@ | ||
context.push(tail[i]); | ||
buf += section(context, partials); | ||
section(context, partials, this); | ||
context.pop(); | ||
} | ||
return buf; | ||
}, | ||
@@ -163,12 +164,15 @@ | ||
var compiler = this.c; | ||
var t = val.call(cx, text, function(t) { | ||
return compiler.compile(t, {delimiters: tags}).render(cx, partials); | ||
}); | ||
var s = compiler.compile(t.toString(), {delimiters: tags}).render(cx, partials); | ||
this.b = s; | ||
var options = this.options; | ||
options.delimiters = tags; | ||
var text = val.call(cx, text); | ||
text = (text == null) ? String(text) : text.toString(); | ||
this.b(compiler.compile(text, options).render(cx, partials)); | ||
return false; | ||
}, | ||
// higher order template result buffer | ||
b: '', | ||
// template result buffering | ||
b: (useArrayBuffer) ? function(s) { this.buf.push(s); } : | ||
function(s) { this.buf += s; }, | ||
fl: (useArrayBuffer) ? function() { var r = this.buf.join(''); this.buf = []; return r; } : | ||
function() { var r = this.buf; this.buf = ''; return r; }, | ||
@@ -201,12 +205,11 @@ // lambda replace section | ||
var result = val.call(cx); | ||
if (typeof result == 'function') { | ||
result = result.call(cx); | ||
result = coerceToString(result.call(cx)); | ||
if (this.c && ~result.indexOf("{\u007B")) { | ||
return this.c.compile(result, this.options).render(cx, partials); | ||
} | ||
} | ||
result = result.toString(); | ||
if (this.c && ~result.indexOf("{{")) { | ||
return this.c.compile(result).render(cx, partials); | ||
} | ||
return result; | ||
return coerceToString(result); | ||
} | ||
@@ -223,4 +226,9 @@ | ||
function coerceToString(val) { | ||
return String((val === null || val === undefined) ? '' : val); | ||
} | ||
function hoganEscape(str) { | ||
str = String((str === null || str === undefined) ? '' : str); | ||
str = coerceToString(str); | ||
return hChars.test(str) ? | ||
@@ -227,0 +235,0 @@ str |
{ | ||
"name": "hogan.js" | ||
, "description": "A mustache compiler." | ||
, "version": "1.0.5-dev" | ||
, "version": "2.0.0" | ||
, "keywords": ["mustache", "template"] | ||
@@ -18,4 +18,8 @@ , "main": "./lib/hogan.js" | ||
] | ||
, "devDependencies": { "uglify-js": "*" } | ||
, "devDependencies": { | ||
"uglify-js": "*" | ||
, "jsdom": "0.2.10" | ||
, "step": "0.0.5" | ||
} | ||
, "bin" : { "hulk" : "./bin/hulk" } | ||
} |
@@ -36,4 +36,4 @@ ## Hogan.js - A mustache compiler. | ||
```js | ||
var text = "{{^check}}{{i18n}}No{{/i18n}}{{/check}}"; | ||
text += "{{#check}}{{i18n}}Yes{{/i18n}}{{/check}}"; | ||
var text = "{{^check}}{{#i18n}}No{{/i18n}}{{/check}}"; | ||
text += "{{#check}}{{#i18n}}Yes{{/i18n}}{{/check}}"; | ||
var tree = Hogan.parse(Hogan.scan(text)); | ||
@@ -40,0 +40,0 @@ |
@@ -16,6 +16,5 @@ /* | ||
var Hogan = Hogan || require('../lib/hogan') | ||
, doc = this["document"] | ||
var is = strictEqual; | ||
function testScanTextNoTags() { | ||
test("Scan Text No Tags", function() { | ||
var text = "<h2>hi</h2>"; | ||
@@ -25,5 +24,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[0]+'', text, "text is equal to first token"); | ||
} | ||
}); | ||
function testScanOneTag() { | ||
test("Scan One Tag", function() { | ||
var text = "{{hmm}}"; | ||
@@ -33,5 +32,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[0].n, "hmm", "First token content is variable name."); | ||
} | ||
}); | ||
function testScanMultipleTags() { | ||
test("Scan Multiple Tags", function() { | ||
var text = "asdf{{hmm}}asdf2{{hmm2}}asdf3"; | ||
@@ -47,5 +46,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[4]+'', "asdf3", "Fifth token is text"); | ||
} | ||
}); | ||
function testScanSectionOpen() { | ||
test("Scan Section Open", function() { | ||
var text = "{{#hmm}}"; | ||
@@ -56,5 +55,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[0].tag, "#", "First token is a section."); | ||
} | ||
}); | ||
function testScanSectionClose() { | ||
test("Scan Section Close", function() { | ||
var text = "{{/hmm}}"; | ||
@@ -65,5 +64,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[0].tag, "/", "First token is a section."); | ||
} | ||
}); | ||
function testScanSection() { | ||
test("Scan Section", function() { | ||
var text = "{{#hmm}}{{/hmm}}"; | ||
@@ -76,5 +75,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[1].tag, "/", "Second token is a section."); | ||
} | ||
}); | ||
function testScanSectionInContent() { | ||
test("Scan Section In Content", function() { | ||
var text = "abc{{#hmm}}def{{/hmm}}ghi"; | ||
@@ -90,5 +89,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[4]+'', "ghi", "Fifth token is text"); | ||
} | ||
}); | ||
function testScanNegativeSection() { | ||
test("Scan Negative Section", function() { | ||
var text = "{{^hmm}}{{/hmm}}"; | ||
@@ -101,5 +100,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[1].tag, "/", "Second token is a section."); | ||
} | ||
}); | ||
function testScanPartial() { | ||
test("Scan Partial", function() { | ||
var text = "{{>hmm}}"; | ||
@@ -110,6 +109,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[0].tag, ">", "First token is a partial."); | ||
} | ||
}); | ||
function testScanBackwardPartial() { | ||
test("Scan Backward Partial", function() { | ||
var text = "{{<hmm}}"; | ||
@@ -120,5 +118,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[0].tag, "<", "First token is a backward partial."); | ||
} | ||
}); | ||
function testScanAmpersandNoEscapeTag() { | ||
test("Scan Ampersand No Escape Tag", function() { | ||
var text = "{{&hmm}}"; | ||
@@ -129,5 +127,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[0].tag, "&", "First token is an ampersand no-escape."); | ||
} | ||
}); | ||
function testScanTripleStache() { | ||
test("Scan Triple Stache", function() { | ||
var text = "{{{hmm}}}"; | ||
@@ -138,5 +136,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[0].tag, "{", "First token is a triple-stache."); | ||
} | ||
}); | ||
function testScanSectionWithTripleStacheInside() { | ||
test("Scan Section With Triple Stache Inside", function() { | ||
var text = "a{{#yo}}b{{{hmm}}}c{{/yo}}d"; | ||
@@ -155,5 +153,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[6]+'', "d", "Seventh token content is correct text."); | ||
} | ||
}); | ||
function testScanSetDelimiter() { | ||
test("Scan Set Delimiter", function() { | ||
var text = "a{{=<% %>=}}b"; | ||
@@ -164,5 +162,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[1]+'', "b", "text after change delimiter is processed."); | ||
} | ||
}); | ||
function testScanResetDelimiter() { | ||
test("Scan Reset Delimiter", function() { | ||
var text = "a{{=<% %>=}}b<%hmm%>c<%={{ }}=%>d{{hmm}}"; | ||
@@ -179,5 +177,5 @@ var tokens = Hogan.scan(text); | ||
is(tokens[5].n, "hmm", "eighth token is correct name."); | ||
} | ||
}); | ||
function testSingleCharDelimiter() { | ||
test("Single Char Delimiter", function() { | ||
var text = '({{foo}} {{=[ ]=}}[text])'; | ||
@@ -189,5 +187,5 @@ var tokens = Hogan.scan(text); | ||
is(s, '(bar It worked!)', "Hogan substitution worked after custom delimiters."); | ||
} | ||
}); | ||
function testSetDelimiterWithWhitespace() { | ||
test("Set Delimiter With Whitespace", function() { | ||
var text = "{{= | | =}}|foo|"; | ||
@@ -197,5 +195,5 @@ var t = Hogan.compile(text); | ||
is(s, 'bar', "custom delimiters with whitespace works.") | ||
} | ||
}); | ||
function testParseBasic() { | ||
test("Parse Basic", function() { | ||
var text = "test"; | ||
@@ -205,5 +203,5 @@ var tree = Hogan.parse(Hogan.scan(text)); | ||
is(tree[0]+'', "test", "text is correct"); | ||
} | ||
}); | ||
function testParseVariables() { | ||
test("Parse Variables", function() { | ||
var text = "test{{foo}}test!{{bar}}test!!{{baz}}test!!!"; | ||
@@ -219,5 +217,5 @@ var tree = Hogan.parse(Hogan.scan(text)); | ||
is(tree[5].n, "baz", "third var is correct"); | ||
} | ||
}); | ||
function testParseSection() { | ||
test("Parse Section", function() { | ||
var text = "a{{#foo}}b{{/foo}}c"; | ||
@@ -232,11 +230,11 @@ var tree = Hogan.parse(Hogan.scan(text)); | ||
is(tree[2]+'', "c", "correct text in last node"); | ||
} | ||
}); | ||
function testParseIndexes() { | ||
test("Parse Indexes", function() { | ||
var text = "abc{{#foo}}asdf{{bar}}asdf{{/foo}}def"; | ||
var tree = Hogan.parse(Hogan.scan(text)); | ||
is(text.substring(tree[1].i, tree[1].end), "asdf{{bar}}asdf", "section text indexes are correct"); | ||
} | ||
}); | ||
function testParseNegativeSection() { | ||
test("Parse Negative Section", function() { | ||
var text = "a{{^foo}}b{{/foo}}c"; | ||
@@ -252,5 +250,5 @@ var tree = Hogan.parse(Hogan.scan(text)); | ||
is(tree[2]+'', "c", "correct text in last node"); | ||
} | ||
}); | ||
function testParseNestedSections() { | ||
test("Parse Nested Sections", function() { | ||
var text = "{{#bar}}{{#foo}}c{{/foo}}{{/bar}}" | ||
@@ -265,39 +263,32 @@ var tree = Hogan.parse(Hogan.scan(text)); | ||
is(tree[0].nodes[0].nodes[0]+'', "c", "correct text in nested section"); | ||
} | ||
}); | ||
function testMissingClosingTag() { | ||
test("Missing Closing Tag", function() { | ||
var text = "a{{#foo}}bc"; | ||
var msg = ''; | ||
try { | ||
raises(function() { | ||
var tree = Hogan.parse(Hogan.scan(text)); | ||
} catch (e) { | ||
msg = e.message; | ||
} | ||
is(msg, "missing closing tag: foo", "Error is generated"); | ||
} | ||
}, "missing closing tag: foo", "Error is generated"); | ||
}); | ||
function testBadNesting() { | ||
test("Bad Nesting", function() { | ||
var text = "a{{#foo}}{{#bar}}b{{/foo}}{{/bar}}c"; | ||
var msg = ''; | ||
try { | ||
raises(function() { | ||
var tree = Hogan.parse(Hogan.scan(text)); | ||
} catch (e) { | ||
msg = e.message; | ||
} | ||
is(msg, "Nesting error: bar vs. foo", "Error is generated"); | ||
} | ||
}, "Nesting error: bar vs. foo", "Error is generated"); | ||
}); | ||
function testBasicOutput() { | ||
test("Basic Output", function() { | ||
var text = "test"; | ||
var t = Hogan.compile(text); | ||
is(t.render(), text, "template renders one text node"); | ||
} | ||
}); | ||
function testBasicOutputAsString() { | ||
test("Basic Output As String", function() { | ||
return; | ||
var text = "test"; | ||
var textFunc = Hogan.compile(text, true); | ||
is(textFunc, "function(context, partials){this.buffer.push('test');};", "template renders correct text function."); | ||
} | ||
}); | ||
function testOneVariable() { | ||
test("One Variable", function() { | ||
var text = "test {{foo}} test"; | ||
@@ -307,5 +298,6 @@ var t = Hogan.compile(text); | ||
is(s, "test bar test", "basic variable substitution works."); | ||
} | ||
}); | ||
function testOneVariableAsString() { | ||
test("One Variable As String", function() { | ||
return; | ||
var text = "test {{foo}} test"; | ||
@@ -315,23 +307,23 @@ var funcText = Hogan.compile(text, true); | ||
"Function text is correct with variable substitution."); | ||
} | ||
}); | ||
function testRenderWithWhitespace() { | ||
test("Render With Whitespace", function() { | ||
var text = "{{ string }}"; | ||
var t = Hogan.compile(text); | ||
is(t.render({string: "---" }), "---", "tags with whitespace render correctly."); | ||
} | ||
}); | ||
function testRenderWithWhitespaceAroundTripleStache() { | ||
test("Render With Whitespace Around Triple Stache", function() { | ||
var text = " {{{string}}}\n"; | ||
var t = Hogan.compile(text); | ||
is(t.render({string: "---" }), " ---\n", "triple stache surrounded by whitespace render correctly."); | ||
} | ||
}); | ||
function testRenderWithWhitespaceAroundAmpersand() { | ||
test("Render With Whitespace Around Ampersand", function() { | ||
var text = " {{& string }}\n"; | ||
var t = Hogan.compile(text); | ||
is(t.render({string: "---" }), " ---\n", "ampersand surrounded by whitespace render correctly."); | ||
} | ||
}); | ||
function testMultipleVariables() { | ||
test("Multiple Variables", function() { | ||
var text = "test {{foo}} test {{bar}} test {{baz}} test {{foo}} test"; | ||
@@ -341,5 +333,5 @@ var t = Hogan.compile(text); | ||
is(s, "test 42 test 43 test 44 test 42 test", "all variables render correctly."); | ||
} | ||
}); | ||
function testNumberValues() { | ||
test("Number Values", function() { | ||
var text = "integer: {{foo}} float: {{bar}} negative: {{baz}}"; | ||
@@ -349,5 +341,5 @@ var t = Hogan.compile(text); | ||
is(s, "integer: 42 float: 42.42 negative: -42", "numbers render correctly"); | ||
} | ||
}); | ||
function testObjectRender() { | ||
test("Object Render", function() { | ||
var text = "object: {{foo}}"; | ||
@@ -357,5 +349,5 @@ var t = Hogan.compile(text); | ||
is(s, "object: [object Object]", "objects render default toString."); | ||
} | ||
}); | ||
function testObjectToStringRender() { | ||
test("Object To String Render", function() { | ||
var text = "object: {{foo}}"; | ||
@@ -365,5 +357,5 @@ var t = Hogan.compile(text); | ||
is(s, "object: yo!", "objects render supplied toString."); | ||
} | ||
}); | ||
function testArrayRender() { | ||
test("Array Render", function() { | ||
var text = "array: {{foo}}"; | ||
@@ -373,5 +365,5 @@ var t = Hogan.compile(text); | ||
is(s, "array: a,b,c", "arrays render default toString."); | ||
} | ||
}); | ||
function testEscaping() { | ||
test("Escaping", function() { | ||
var text = "{{foo}}"; | ||
@@ -388,6 +380,5 @@ var t = Hogan.compile(text); | ||
} | ||
}); | ||
} | ||
function testMustacheInjection() { | ||
test("Mustache Injection", function() { | ||
var text = "{{foo}}"; | ||
@@ -397,5 +388,5 @@ var t = Hogan.compile(text); | ||
is(s, "{{{<42}}}", "Can't inject mustache"); | ||
} | ||
}); | ||
function testTripleStache() { | ||
test("Triple Stache", function() { | ||
var text = "{{{foo}}}"; | ||
@@ -405,5 +396,5 @@ var t = Hogan.compile(text); | ||
is(s, "< > <div> \' \" &", "input correctly not-escaped."); | ||
} | ||
}); | ||
function testAmpNoEscaping() { | ||
test("Amp No Escaping", function() { | ||
var text = "{{&foo}}"; | ||
@@ -413,5 +404,5 @@ var t = Hogan.compile(text); | ||
is(s, "< > <div> \' \" &", "input correctly not-escaped."); | ||
} | ||
}); | ||
function testPartial() { | ||
test("Partial", function() { | ||
var partialText = "this is text from the partial--the magic number {{foo}} is from a variable"; | ||
@@ -425,5 +416,5 @@ var p = Hogan.compile(partialText); | ||
is(s, "This template contains a partial (this is text from the partial--the magic number 42 is from a variable).", "partials work"); | ||
} | ||
}); | ||
function testNestedPartials() { | ||
test("Nested Partials", function() { | ||
var partialText = "this is text from the partial--the magic number {{foo}} is from a variable"; | ||
@@ -440,5 +431,5 @@ var p = Hogan.compile(partialText); | ||
is(s, "This template contains a partial that contains a partial [This template contains a partial (this is text from the partial--the magic number 42 is from a variable).].", "nested partials work"); | ||
} | ||
}); | ||
function testNegativeSection() { | ||
test("Negative Section", function() { | ||
var text = "This template {{^foo}}BOO {{/foo}}contains an inverted section." | ||
@@ -463,5 +454,5 @@ var t = Hogan.compile(text); | ||
is(s, "This template BOO contains an inverted section.", "inverted sections with false returning method in context work"); | ||
} | ||
}); | ||
function testSectionElision() { | ||
test("Section Elision", function() { | ||
var text = "This template {{#foo}}BOO {{/foo}}contains a section." | ||
@@ -477,5 +468,5 @@ var t = Hogan.compile(text); | ||
is(s, "This template contains a section.", "sections with false context work"); | ||
} | ||
}); | ||
function testSectionObjectContext() { | ||
test("Section Object Context", function() { | ||
var text = "This template {{#foo}}{{bar}} {{/foo}}contains a section." | ||
@@ -485,5 +476,5 @@ var t = Hogan.compile(text); | ||
is(s, "This template 42 contains a section.", "sections with object context work"); | ||
} | ||
}); | ||
function testSectionArrayContext() { | ||
test("Section Array Context", function() { | ||
var text = "This template {{#foo}}{{bar}} {{/foo}}contains a section." | ||
@@ -493,5 +484,5 @@ var t = Hogan.compile(text); | ||
is(s, "This template 42 43 44 contains a section.", "sections with object ctx and array values work"); | ||
} | ||
}); | ||
function testFalsyVariableNoRender() { | ||
test("Falsy Variable No Render", function() { | ||
var text = "I ({{cannot}}) be seen!"; | ||
@@ -501,8 +492,20 @@ var t = Hogan.compile(text); | ||
is(s, "I () be seen!", "missing value doesn't render."); | ||
} | ||
}); | ||
function testSectionExtensions() { | ||
test("Undefined Return Value From Lambda", function() { | ||
var text = "abc{{foo}}def"; | ||
var t = Hogan.compile(text); | ||
var context = { | ||
foo: function(s) { | ||
return undefined; | ||
} | ||
} | ||
var s = t.render(context); | ||
is(s, "abcdef", "deal with undefined return values from lambdas.") | ||
}); | ||
test("Section Extensions", function() { | ||
var text = "Test {{_//|__foo}}bar{{/foo}}"; | ||
var options = {sectionTags:[{o:'_//|__foo', c:'foo'}]}; | ||
var tree = Hogan.parse(Hogan.scan(text), options); | ||
var tree = Hogan.parse(Hogan.scan(text), text, options); | ||
is(tree[1].tag, "#", "_//|__foo node transformed to section"); | ||
@@ -514,17 +517,71 @@ is(tree[1].n, "_//|__foo", "_//|__foo node transformed to section"); | ||
is(s, "Test bar", "Custom sections work"); | ||
} | ||
}); | ||
function testMisnestedSectionExtensions() { | ||
test("Misnested Section Extensions", function() { | ||
var text = "Test {{__foo}}bar{{/bar}}"; | ||
var options = {sectionTags:[{o:'__foo', c:'foo'}, {o:'__bar', c:'bar'}]}; | ||
var msg = ''; | ||
try { | ||
var tree = Hogan.parse(Hogan.scan(text), options); | ||
} catch (e) { | ||
msg = e.message; | ||
raises(function() { | ||
var tree = Hogan.parse(Hogan.scan(text), text, options); | ||
}, "Nesting error: __foo vs. bar", "Error is generated"); | ||
}); | ||
test("Section Extensions In Higher Order Sections", function() { | ||
var text = "Test{{_foo}}bar{{/foo}}"; | ||
var options = {sectionTags:[{o:'_foo', c:'foo'}, {o:'_baz', c:'baz'}]}; | ||
var t = Hogan.compile(text, options); | ||
var context = { | ||
"_foo": function (s) { | ||
return "{{_baz}}" + s + "{{/baz}}"; | ||
} | ||
} | ||
is(msg, "Nesting error: __foo vs. bar", "Error is generated"); | ||
} | ||
var s = t.render(context); | ||
is(s, "Test", "unprocessed test"); | ||
}); | ||
function testNestedSection() { | ||
test("Section Extensions In Lambda Replace Variable", function() { | ||
var text = "Test{{foo}}"; | ||
var options = {sectionTags:[{o:'_baz', c:'baz'}]}; | ||
var t = Hogan.compile(text, options); | ||
var context = { | ||
"foo": function () { | ||
return function() { "{{_baz}}" + s + "{{/baz}}"; }; | ||
} | ||
} | ||
var s = t.render(context); | ||
is(s, "Test", "unprocessed test"); | ||
}); | ||
test("Mustache not reprocessed for method calls in interpolations", function() { | ||
var text = "text with {{foo}} inside"; | ||
var t = Hogan.compile(text); | ||
var context = { | ||
foo: function() { | ||
return "no processing of {{tags}}"; | ||
} | ||
} | ||
var s = t.render(context); | ||
is(s, "text with no processing of {{tags}} inside", "method calls should not be processed as mustache."); | ||
var text = "text with {{{foo}}} inside"; | ||
var t = Hogan.compile(text); | ||
var s = t.render(context); | ||
is(s, "text with no processing of {{tags}} inside", "method calls should not be processed as mustache in triple staches."); | ||
}); | ||
test("Mustache is reprocessed for lambdas in interpolations", function() { | ||
var text = "text with {{foo}} inside"; | ||
var t = Hogan.compile(text); | ||
var context = { | ||
bar: "42", | ||
foo: function() { | ||
return function() { | ||
return "processing of {{bar}}"; | ||
}; | ||
} | ||
}; | ||
var s = t.render(context); | ||
is(s, "text with processing of 42 inside", "the return value of lambdas should be processed mustache."); | ||
}); | ||
test("Nested Section", function() { | ||
var text = "{{#foo}}{{#bar}}{{baz}}{{/bar}}{{/foo}}"; | ||
@@ -534,5 +591,5 @@ var t = Hogan.compile(text); | ||
is(s, "42", "can reach up context stack"); | ||
} | ||
}); | ||
function testDottedNames() { | ||
test("Dotted Names", function() { | ||
var text = '"{{person.name}}" == "{{#person}}{{name}}{{/person}}"'; | ||
@@ -542,5 +599,5 @@ var t = Hogan.compile(text); | ||
is(s, '"Joe" == "Joe"', "dotted names work"); | ||
} | ||
}); | ||
function testImplicitIterator() { | ||
test("Implicit Iterator", function() { | ||
var text = '{{#stuff}} {{.}} {{/stuff}}'; | ||
@@ -550,5 +607,5 @@ var t = Hogan.compile(text); | ||
is(s, " 42 43 44 ", "implicit iterators work"); | ||
} | ||
}); | ||
function testPartialsAndDelimiters() { | ||
test("Partials And Delimiters", function() { | ||
var text = '{{>include}}*\n{{= | | =}}\n*|>include|'; | ||
@@ -560,5 +617,5 @@ var partialText = ' .{{value}}. '; | ||
is(s, " .yes. *\n* .yes. ", "partials work around delimiters"); | ||
} | ||
}); | ||
function testStringPartials() { | ||
test("String Partials", function() { | ||
var text = "foo{{>mypartial}}baz"; | ||
@@ -569,5 +626,5 @@ var partialText = " bar "; | ||
is(s, "foo bar baz", "string partial works."); | ||
} | ||
}); | ||
function testMissingPartials() { | ||
test("Missing Partials", function() { | ||
var text = "foo{{>mypartial}} bar"; | ||
@@ -577,5 +634,5 @@ var t = Hogan.compile(text); | ||
is(s, "foo bar", "missing partial works."); | ||
} | ||
}); | ||
function testIndentedStandaloneComment() { | ||
test("Indented Standalone Comment", function() { | ||
var text = 'Begin.\n {{! Indented Comment Block! }}\nEnd.'; | ||
@@ -585,5 +642,5 @@ var t = Hogan.compile(text); | ||
is(s, 'Begin.\nEnd.', "Standalone comment blocks are removed."); | ||
} | ||
}); | ||
function testNewLineBetweenDelimiterChanges() { | ||
test("New Line Between Delimiter Changes", function() { | ||
var data = { section: true, data: 'I got interpolated.' }; | ||
@@ -594,5 +651,5 @@ var text = '\n{{#section}}\n {{data}}\n |data|\n{{/section}}x\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|'; | ||
is(s, '\n I got interpolated.\n |data|\nx\n\n {{data}}\n I got interpolated.\n', 'render correct') | ||
} | ||
}); | ||
function testMustacheJSApostrophe() { | ||
test("Mustache JS Apostrophe", function() { | ||
var text = '{{apos}}{{control}}'; | ||
@@ -602,5 +659,5 @@ var t = Hogan.compile(text); | ||
is(s, ''X', 'Apostrophe is escaped.'); | ||
} | ||
}); | ||
function testMustacheJSArrayOfImplicitPartials() { | ||
test("Mustache JS Array Of Implicit Partials", function() { | ||
var text = 'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}\n'; | ||
@@ -611,5 +668,5 @@ var partialText = '{{.}}\n'; | ||
is(s, 'Here is some stuff!\n1\n2\n3\n4\n', 'Partials with implicit iterators work.'); | ||
} | ||
}); | ||
function testMustacheJSArrayOfPartials() { | ||
test("Mustache JS Array Of Partials", function() { | ||
var text = 'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}\n'; | ||
@@ -620,5 +677,5 @@ var partialText = '{{i}}\n'; | ||
is(s, 'Here is some stuff!\n1\n2\n3\n4\n', 'Partials with arrays work.'); | ||
} | ||
}); | ||
function testMustacheJSArrayOfStrings() { | ||
test("Mustache JS Array Of Strings", function() { | ||
var text = '{{#strings}}{{.}} {{/strings}}'; | ||
@@ -628,5 +685,5 @@ var t = Hogan.compile(text); | ||
is(s, 'foo bar baz ', 'array of strings works with implicit iterators.'); | ||
} | ||
}); | ||
function testMustacheJSUndefinedString() { | ||
test("Mustache JS Undefined String", function() { | ||
var text = 'foo{{bar}}baz'; | ||
@@ -636,5 +693,26 @@ var t = Hogan.compile(text); | ||
is(s, 'foobaz', 'undefined value does not render.'); | ||
} | ||
}); | ||
function testMustacheJSTripleStacheAltDelimiter() { | ||
test("Mustache JS Undefined Triple Stache", function() { | ||
var text = 'foo{{{bar}}}baz'; | ||
var t = Hogan.compile(text); | ||
var s = t.render({bar:undefined}); | ||
is(s, 'foobaz', 'undefined value does not render in triple stache.'); | ||
}); | ||
test("Mustache JS Null String", function() { | ||
var text = 'foo{{bar}}baz'; | ||
var t = Hogan.compile(text); | ||
var s = t.render({bar:null}); | ||
is(s, 'foobaz', 'undefined value does not render.'); | ||
}); | ||
test("Mustache JS Null Triple Stache", function() { | ||
var text = 'foo{{{bar}}}baz'; | ||
var t = Hogan.compile(text); | ||
var s = t.render({bar:null}); | ||
is(s, 'foobaz', 'undefined value does not render in triple stache.'); | ||
}); | ||
test("Mustache JS Triple Stache Alt Delimiter", function() { | ||
var text = '{{=<% %>=}}<% foo %> {{foo}} <%{bar}%> {{{bar}}}'; | ||
@@ -644,7 +722,16 @@ var t = Hogan.compile(text); | ||
is(s, 'yeah {{foo}} hmm {{{bar}}}', 'triple stache inside alternate delimiter works.'); | ||
} | ||
}); | ||
/* Safety tests */ | ||
test("Updates object state", function() { | ||
var text = '{{foo}} {{bar}} {{foo}}'; | ||
var t = Hogan.compile(text); | ||
var s = t.render({foo: 1, bar: function() { this.foo++; return 42; } }); | ||
is(s, '1 42 2'); | ||
}); | ||
/* shootout benchmark tests */ | ||
function testShootOutString() { | ||
test("Shoot Out String", function() { | ||
var text = "Hello World!"; | ||
@@ -655,5 +742,5 @@ var expected = "Hello World!" | ||
is(s, expected, "Shootout String compiled correctly"); | ||
} | ||
}); | ||
function testShootOutReplace() { | ||
test("Shoot Out Replace", function() { | ||
var text = "Hello {{name}}! You have {{count}} new messages."; | ||
@@ -664,5 +751,5 @@ var expected = "Hello Mick! You have 30 new messages."; | ||
is(s, expected, "Shootout Replace compiled correctly"); | ||
} | ||
}); | ||
function testShootOutArray() { | ||
test("Shoot Out Array", function() { | ||
var text = "{{#names}}{{name}}{{/names}}"; | ||
@@ -673,5 +760,5 @@ var expected = "MoeLarryCurlyShemp"; | ||
is(s, expected, "Shootout Array compiled correctly"); | ||
} | ||
}); | ||
function testShootOutObject() { | ||
test("Shoot Out Object", function() { | ||
var text = "{{#person}}{{name}}{{age}}{{/person}}"; | ||
@@ -682,5 +769,5 @@ var expected = "Larry45"; | ||
is(s, expected, "Shootout Object compiled correctly"); | ||
} | ||
}); | ||
function testShootOutPartial() { | ||
test("Shoot Out Partial", function() { | ||
var text = "{{#peeps}}{{>replace}}{{/peeps}}"; | ||
@@ -692,5 +779,5 @@ var t = Hogan.compile(text); | ||
is(s, expected, "Shootout Partial compiled correctly"); | ||
} | ||
}); | ||
function testShootOutRecurse() { | ||
test("Shoot Out Recurse", function() { | ||
var text = "{{name}}{{#kids}}{{>recursion}}{{/kids}}"; | ||
@@ -712,5 +799,5 @@ var t = Hogan.compile(text); | ||
is(s, expected, "Shootout Recurse compiled correctly"); | ||
} | ||
}); | ||
function testShootOutFilter() { | ||
test("Shoot Out Filter", function() { | ||
var text = "{{#filter}}foo {{bar}}{{/filter}}"; | ||
@@ -720,4 +807,4 @@ var t = Hogan.compile(text); | ||
filter: function() { | ||
return function(text, render) { | ||
return render(text).toUpperCase(); | ||
return function(text) { | ||
return text.toUpperCase() + "{{bar}}"; | ||
} | ||
@@ -727,7 +814,7 @@ }, | ||
}); | ||
var expected = "FOO BAR" | ||
var expected = "FOO bar" | ||
is(s, expected, "Shootout Filter compiled correctly"); | ||
} | ||
}); | ||
function testShootOutComplex() { | ||
test("Shoot Out Complex", function() { | ||
var text = | ||
@@ -771,143 +858,22 @@ "<h1>{{header}}</h1>" + | ||
is(s, expected, "Shootout Complex compiled correctly"); | ||
} | ||
}); | ||
function testRenderOutput() { | ||
if (doc) return | ||
var fs = require('fs'); | ||
var inPath = 'test/templates'; | ||
var outPath = 'test/html'; | ||
$.each(['list'], function(i, name) { | ||
return; | ||
asyncTest("Render Output: " + name, function() { | ||
$.when( | ||
$.get('./templates/' + name + '.mustache'), | ||
$.get('./html/' + name + '.html') | ||
).done(function(tmpl, html) { | ||
var r = Hogan.compile(tmpl[0]).render({}); | ||
is(r, html[0], name + ': should correctly render html'); | ||
}) | ||
.fail(function() { ok(false, 'file missing'); }) | ||
.always(function() { start(); }); | ||
}); | ||
}); | ||
fs.readdirSync(inPath).forEach(function (file) { | ||
var i = fs.readFileSync([inPath, file].join('/'), 'utf-8'); | ||
var t = Hogan.compile(i); | ||
var r = t.render({}); | ||
var o = fs.readFileSync([outPath, file].join('/').replace(/mustache$/, 'html')).toString(); | ||
is(r === o, true, file + ' should correctly render html') | ||
}) | ||
} | ||
function testDefaultRenderImpl() { | ||
test("Default Render Impl", function() { | ||
var ht = new Hogan.Template(); | ||
is(ht.render() === '', true, 'default renderImpl returns an array.'); | ||
} | ||
function appendText(el, text) { | ||
var textNode = document.createTextNode(text); | ||
el.appendChild(textNode); | ||
el.appendChild(document.createElement('br')); | ||
} | ||
if (!this["output"]) { | ||
var output = function (s) { | ||
return doc ? appendText(doc.getElementById('console'), s) : console.log(s); | ||
}; | ||
} | ||
var passed = 0; | ||
var failed = 0; | ||
function is(got, expected, msg) { | ||
if (got === expected) { | ||
output("OK: " + msg); | ||
++passed; | ||
} else { | ||
output("FAIL: " + msg); | ||
output("Expected |" + expected + "|"); | ||
output(" Got |" + got + "|"); | ||
++failed; | ||
} | ||
} | ||
function complete() { | ||
output("\nTests Complete"); | ||
output("--------------"); | ||
output("Passed: " + passed); | ||
output("Failed: " + failed); | ||
output("\n"); | ||
} | ||
function runTests() { | ||
output("Tests Starting"); | ||
output("--------------"); | ||
testScanTextNoTags(); | ||
testScanOneTag(); | ||
testScanMultipleTags(); | ||
testScanSectionOpen(); | ||
testScanSectionClose(); | ||
testScanSection(); | ||
testScanSectionInContent(); | ||
testScanNegativeSection(); | ||
testScanPartial(); | ||
testScanBackwardPartial(); | ||
testScanAmpersandNoEscapeTag(); | ||
testScanTripleStache(); | ||
testScanSectionWithTripleStacheInside(); | ||
testScanSetDelimiter(); | ||
testScanResetDelimiter(); | ||
testSetDelimiterWithWhitespace(); | ||
testSingleCharDelimiter(); | ||
testParseBasic(); | ||
testParseVariables(); | ||
testParseSection(); | ||
testParseIndexes(); | ||
testParseNegativeSection(); | ||
testParseNestedSections(); | ||
testMissingClosingTag(); | ||
testBadNesting(); | ||
testBasicOutput(); | ||
//testBasicOutputAsString(); | ||
testOneVariable(); | ||
//testOneVariableAsString(); | ||
testMultipleVariables(); | ||
testNumberValues(); | ||
testObjectRender(); | ||
testObjectToStringRender(); | ||
testArrayRender(); | ||
testEscaping(); | ||
testMustacheInjection(); | ||
testTripleStache(); | ||
testAmpNoEscaping(); | ||
testPartial(); | ||
testNestedPartials(); | ||
testNegativeSection(); | ||
testSectionElision(); | ||
testSectionObjectContext(); | ||
testSectionArrayContext(); | ||
testRenderWithWhitespace(); | ||
testRenderWithWhitespaceAroundTripleStache(); | ||
testRenderWithWhitespaceAroundAmpersand(); | ||
testFalsyVariableNoRender(); | ||
testRenderOutput(); | ||
testDefaultRenderImpl(); | ||
testSectionExtensions(); | ||
testMisnestedSectionExtensions(); | ||
testNestedSection(); | ||
testShootOutString(); | ||
testShootOutReplace(); | ||
testShootOutArray(); | ||
testShootOutObject(); | ||
testShootOutPartial(); | ||
testShootOutRecurse(); | ||
testShootOutFilter(); | ||
testShootOutComplex(); | ||
testDottedNames(); | ||
testImplicitIterator(); | ||
testPartialsAndDelimiters(); | ||
testStringPartials(); | ||
testMissingPartials(); | ||
testIndentedStandaloneComment(); | ||
testNewLineBetweenDelimiterChanges(); | ||
testMustacheJSApostrophe(); | ||
testMustacheJSArrayOfImplicitPartials(); | ||
testMustacheJSArrayOfPartials(); | ||
testMustacheJSArrayOfStrings(); | ||
testMustacheJSUndefinedString(); | ||
testMustacheJSTripleStacheAltDelimiter(); | ||
complete(); | ||
} | ||
if (doc) { | ||
window.onload = runTests; | ||
} else { | ||
runTests(); | ||
} | ||
}); |
@@ -41,3 +41,3 @@ /* | ||
var packageJSON = JSON.parse(read('package.json')); | ||
var version = packageJSON.version.substring(0, packageJSON.version.indexOf('-')); | ||
var version = packageJSON.version; | ||
@@ -71,6 +71,1 @@ function removeFirstComment(text) { | ||
uglify(templateTarget, distPath + 'template-' + version + '.min.js'); | ||
// Add packageJSON to node distribution | ||
packageJSON.version = version; | ||
fs.writeFileSync(__dirname + '/../dist/nodejs/package.json', | ||
JSON.stringify(packageJSON, null, " ")); |
@@ -22,3 +22,3 @@ /* | ||
var homeTemplatePath = __dirname + '/../build/gh-pages/index.html.mustache'; | ||
var contextPath = __dirname + '/../dist/nodejs/package.json'; | ||
var contextPath = __dirname + '/../package.json'; | ||
@@ -25,0 +25,0 @@ var homepage = fs.readFileSync(homeTemplatePath).toString(); |
@@ -20,9 +20,9 @@ /* | ||
(function (Hogan) { | ||
Hogan.Template = function constructor(renderFunc, text, compiler) { | ||
if (renderFunc) { | ||
this.r = renderFunc; | ||
} | ||
(function (Hogan, useArrayBuffer) { | ||
Hogan.Template = function (renderFunc, text, compiler, options) { | ||
this.r = renderFunc || this.r; | ||
this.c = compiler; | ||
this.options = options; | ||
this.text = text || ''; | ||
this.buf = (useArrayBuffer) ? [] : ''; | ||
} | ||
@@ -37,2 +37,5 @@ | ||
// triple stache | ||
t: coerceToString, | ||
render: function render(context, partials, indent) { | ||
@@ -56,3 +59,3 @@ return this.ri([context], partials || {}, indent); | ||
if (this.c && typeof partial == 'string') { | ||
partial = this.c.compile(partial); | ||
partial = this.c.compile(partial, this.options); | ||
} | ||
@@ -65,7 +68,7 @@ | ||
rs: function(context, partials, section) { | ||
var buf = '', | ||
tail = context[context.length - 1]; | ||
var tail = context[context.length - 1]; | ||
if (!isArray(tail)) { | ||
return buf = section(context, partials); | ||
section(context, partials, this); | ||
return; | ||
} | ||
@@ -75,7 +78,5 @@ | ||
context.push(tail[i]); | ||
buf += section(context, partials); | ||
section(context, partials, this); | ||
context.pop(); | ||
} | ||
return buf; | ||
}, | ||
@@ -165,12 +166,16 @@ | ||
var compiler = this.c; | ||
var options = this.options; | ||
options.delimiters = tags; | ||
var t = val.call(cx, text, function(t) { | ||
return compiler.compile(t, {delimiters: tags}).render(cx, partials); | ||
return compiler.compile(t, options).render(cx, partials); | ||
}); | ||
var s = compiler.compile(t.toString(), {delimiters: tags}).render(cx, partials); | ||
this.b = s; | ||
this.b(compiler.compile(t.toString(), options).render(cx, partials)); | ||
return false; | ||
}, | ||
// higher order template result buffer | ||
b: '', | ||
// template result buffering | ||
b: (useArrayBuffer) ? function(s) { this.buf.push(s); } : | ||
function(s) { this.buf += s; }, | ||
fl: (useArrayBuffer) ? function() { var r = this.buf.join(''); this.buf = []; return r; } : | ||
function() { var r = this.buf; this.buf = ''; return r; }, | ||
@@ -206,6 +211,6 @@ // lambda replace section | ||
} | ||
result = result.toString(); | ||
result = coerceToString(result); | ||
if (this.c && ~result.indexOf("{{")) { | ||
return this.c.compile(result).render(cx, partials); | ||
if (this.c && ~result.indexOf("{\u007B")) { | ||
return this.c.compile(result, this.options).render(cx, partials); | ||
} | ||
@@ -225,4 +230,9 @@ | ||
function coerceToString(val) { | ||
return String((val === null || val === undefined) ? '' : val); | ||
} | ||
function hoganEscape(str) { | ||
str = String((str === null || str === undefined) ? '' : str); | ||
str = coerceToString(str); | ||
return hChars.test(str) ? | ||
@@ -468,3 +478,3 @@ str | ||
function writeCode(tree) { | ||
return 'i = i || "";var b = i + "";var _ = this;' + walk(tree) + 'return b;'; | ||
return 'var _=this;_.b(i=i||"");' + walk(tree) + 'return _.fl();'; | ||
} | ||
@@ -477,3 +487,3 @@ | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan); | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan, options); | ||
} | ||
@@ -519,12 +529,11 @@ | ||
return 'if(_.s(_.' + method + '("' + esc(id) + '",c,p,1),' + | ||
'c,p,0,' + start + ',' + end + ', "' + tags + '")){' + | ||
'b += _.rs(c,p,' + | ||
'function(c,p){ var b = "";' + | ||
'c,p,0,' + start + ',' + end + ',"' + tags + '")){' + | ||
'_.rs(c,p,' + | ||
'function(c,p,_){' + | ||
walk(nodes) + | ||
'return b;});c.pop();}' + | ||
'else{b += _.b; _.b = ""};'; | ||
'});c.pop();}'; | ||
} | ||
function invertedSection(nodes, id, method) { | ||
return 'if (!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
return 'if(!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
walk(nodes) + | ||
@@ -535,18 +544,18 @@ '};'; | ||
function partial(tok) { | ||
return 'b += _.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '");'; | ||
return '_.b(_.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '"));'; | ||
} | ||
function tripleStache(id, method) { | ||
return 'b += (_.' + method + '("' + esc(id) + '",c,p,0));'; | ||
return '_.b(_.t(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function variable(id, method) { | ||
return 'b += (_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
return '_.b(_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function text(id) { | ||
return 'b += ' + id + ';'; | ||
return '_.b(' + id + ');'; | ||
} | ||
Hogan.parse = function(tokens, options) { | ||
Hogan.parse = function(tokens, text, options) { | ||
options = options || {}; | ||
@@ -580,3 +589,3 @@ return buildTree(tokens, '', [], options.sectionTags || []); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), options)), text, options); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), text, options)), text, options); | ||
return this.cache[key] = t; | ||
@@ -583,0 +592,0 @@ }; |
@@ -20,9 +20,9 @@ /* | ||
(function (Hogan) { | ||
Hogan.Template = function constructor(renderFunc, text, compiler) { | ||
if (renderFunc) { | ||
this.r = renderFunc; | ||
} | ||
(function (Hogan, useArrayBuffer) { | ||
Hogan.Template = function (renderFunc, text, compiler, options) { | ||
this.r = renderFunc || this.r; | ||
this.c = compiler; | ||
this.options = options; | ||
this.text = text || ''; | ||
this.buf = (useArrayBuffer) ? [] : ''; | ||
} | ||
@@ -37,2 +37,5 @@ | ||
// triple stache | ||
t: coerceToString, | ||
render: function render(context, partials, indent) { | ||
@@ -56,3 +59,3 @@ return this.ri([context], partials || {}, indent); | ||
if (this.c && typeof partial == 'string') { | ||
partial = this.c.compile(partial); | ||
partial = this.c.compile(partial, this.options); | ||
} | ||
@@ -65,7 +68,7 @@ | ||
rs: function(context, partials, section) { | ||
var buf = '', | ||
tail = context[context.length - 1]; | ||
var tail = context[context.length - 1]; | ||
if (!isArray(tail)) { | ||
return buf = section(context, partials); | ||
section(context, partials, this); | ||
return; | ||
} | ||
@@ -75,7 +78,5 @@ | ||
context.push(tail[i]); | ||
buf += section(context, partials); | ||
section(context, partials, this); | ||
context.pop(); | ||
} | ||
return buf; | ||
}, | ||
@@ -165,12 +166,16 @@ | ||
var compiler = this.c; | ||
var options = this.options; | ||
options.delimiters = tags; | ||
var t = val.call(cx, text, function(t) { | ||
return compiler.compile(t, {delimiters: tags}).render(cx, partials); | ||
return compiler.compile(t, options).render(cx, partials); | ||
}); | ||
var s = compiler.compile(t.toString(), {delimiters: tags}).render(cx, partials); | ||
this.b = s; | ||
this.b(compiler.compile(t.toString(), options).render(cx, partials)); | ||
return false; | ||
}, | ||
// higher order template result buffer | ||
b: '', | ||
// template result buffering | ||
b: (useArrayBuffer) ? function(s) { this.buf.push(s); } : | ||
function(s) { this.buf += s; }, | ||
fl: (useArrayBuffer) ? function() { var r = this.buf.join(''); this.buf = []; return r; } : | ||
function() { var r = this.buf; this.buf = ''; return r; }, | ||
@@ -206,6 +211,6 @@ // lambda replace section | ||
} | ||
result = result.toString(); | ||
result = coerceToString(result); | ||
if (this.c && ~result.indexOf("{{")) { | ||
return this.c.compile(result).render(cx, partials); | ||
if (this.c && ~result.indexOf("{\u007B")) { | ||
return this.c.compile(result, this.options).render(cx, partials); | ||
} | ||
@@ -225,4 +230,9 @@ | ||
function coerceToString(val) { | ||
return String((val === null || val === undefined) ? '' : val); | ||
} | ||
function hoganEscape(str) { | ||
str = String((str === null || str === undefined) ? '' : str); | ||
str = coerceToString(str); | ||
return hChars.test(str) ? | ||
@@ -468,3 +478,3 @@ str | ||
function writeCode(tree) { | ||
return 'i = i || "";var b = i + "";var _ = this;' + walk(tree) + 'return b;'; | ||
return 'var _=this;_.b(i=i||"");' + walk(tree) + 'return _.fl();'; | ||
} | ||
@@ -477,3 +487,3 @@ | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan); | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan, options); | ||
} | ||
@@ -519,12 +529,11 @@ | ||
return 'if(_.s(_.' + method + '("' + esc(id) + '",c,p,1),' + | ||
'c,p,0,' + start + ',' + end + ', "' + tags + '")){' + | ||
'b += _.rs(c,p,' + | ||
'function(c,p){ var b = "";' + | ||
'c,p,0,' + start + ',' + end + ',"' + tags + '")){' + | ||
'_.rs(c,p,' + | ||
'function(c,p,_){' + | ||
walk(nodes) + | ||
'return b;});c.pop();}' + | ||
'else{b += _.b; _.b = ""};'; | ||
'});c.pop();}'; | ||
} | ||
function invertedSection(nodes, id, method) { | ||
return 'if (!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
return 'if(!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
walk(nodes) + | ||
@@ -535,18 +544,18 @@ '};'; | ||
function partial(tok) { | ||
return 'b += _.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '");'; | ||
return '_.b(_.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '"));'; | ||
} | ||
function tripleStache(id, method) { | ||
return 'b += (_.' + method + '("' + esc(id) + '",c,p,0));'; | ||
return '_.b(_.t(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function variable(id, method) { | ||
return 'b += (_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
return '_.b(_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function text(id) { | ||
return 'b += ' + id + ';'; | ||
return '_.b(' + id + ');'; | ||
} | ||
Hogan.parse = function(tokens, options) { | ||
Hogan.parse = function(tokens, text, options) { | ||
options = options || {}; | ||
@@ -580,3 +589,3 @@ return buildTree(tokens, '', [], options.sectionTags || []); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), options)), text, options); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), text, options)), text, options); | ||
return this.cache[key] = t; | ||
@@ -583,0 +592,0 @@ }; |
@@ -20,9 +20,9 @@ /* | ||
(function (Hogan) { | ||
Hogan.Template = function constructor(renderFunc, text, compiler) { | ||
if (renderFunc) { | ||
this.r = renderFunc; | ||
} | ||
(function (Hogan, useArrayBuffer) { | ||
Hogan.Template = function (renderFunc, text, compiler, options) { | ||
this.r = renderFunc || this.r; | ||
this.c = compiler; | ||
this.options = options; | ||
this.text = text || ''; | ||
this.buf = (useArrayBuffer) ? [] : ''; | ||
} | ||
@@ -37,2 +37,5 @@ | ||
// triple stache | ||
t: coerceToString, | ||
render: function render(context, partials, indent) { | ||
@@ -56,3 +59,3 @@ return this.ri([context], partials || {}, indent); | ||
if (this.c && typeof partial == 'string') { | ||
partial = this.c.compile(partial); | ||
partial = this.c.compile(partial, this.options); | ||
} | ||
@@ -65,7 +68,7 @@ | ||
rs: function(context, partials, section) { | ||
var buf = '', | ||
tail = context[context.length - 1]; | ||
var tail = context[context.length - 1]; | ||
if (!isArray(tail)) { | ||
return buf = section(context, partials); | ||
section(context, partials, this); | ||
return; | ||
} | ||
@@ -75,7 +78,5 @@ | ||
context.push(tail[i]); | ||
buf += section(context, partials); | ||
section(context, partials, this); | ||
context.pop(); | ||
} | ||
return buf; | ||
}, | ||
@@ -165,12 +166,16 @@ | ||
var compiler = this.c; | ||
var options = this.options; | ||
options.delimiters = tags; | ||
var t = val.call(cx, text, function(t) { | ||
return compiler.compile(t, {delimiters: tags}).render(cx, partials); | ||
return compiler.compile(t, options).render(cx, partials); | ||
}); | ||
var s = compiler.compile(t.toString(), {delimiters: tags}).render(cx, partials); | ||
this.b = s; | ||
this.b(compiler.compile(t.toString(), options).render(cx, partials)); | ||
return false; | ||
}, | ||
// higher order template result buffer | ||
b: '', | ||
// template result buffering | ||
b: (useArrayBuffer) ? function(s) { this.buf.push(s); } : | ||
function(s) { this.buf += s; }, | ||
fl: (useArrayBuffer) ? function() { var r = this.buf.join(''); this.buf = []; return r; } : | ||
function() { var r = this.buf; this.buf = ''; return r; }, | ||
@@ -206,6 +211,6 @@ // lambda replace section | ||
} | ||
result = result.toString(); | ||
result = coerceToString(result); | ||
if (this.c && ~result.indexOf("{{")) { | ||
return this.c.compile(result).render(cx, partials); | ||
if (this.c && ~result.indexOf("{\u007B")) { | ||
return this.c.compile(result, this.options).render(cx, partials); | ||
} | ||
@@ -225,4 +230,9 @@ | ||
function coerceToString(val) { | ||
return String((val === null || val === undefined) ? '' : val); | ||
} | ||
function hoganEscape(str) { | ||
str = String((str === null || str === undefined) ? '' : str); | ||
str = coerceToString(str); | ||
return hChars.test(str) ? | ||
@@ -468,3 +478,3 @@ str | ||
function writeCode(tree) { | ||
return 'i = i || "";var b = i + "";var _ = this;' + walk(tree) + 'return b;'; | ||
return 'var _=this;_.b(i=i||"");' + walk(tree) + 'return _.fl();'; | ||
} | ||
@@ -477,3 +487,3 @@ | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan); | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan, options); | ||
} | ||
@@ -519,12 +529,11 @@ | ||
return 'if(_.s(_.' + method + '("' + esc(id) + '",c,p,1),' + | ||
'c,p,0,' + start + ',' + end + ', "' + tags + '")){' + | ||
'b += _.rs(c,p,' + | ||
'function(c,p){ var b = "";' + | ||
'c,p,0,' + start + ',' + end + ',"' + tags + '")){' + | ||
'_.rs(c,p,' + | ||
'function(c,p,_){' + | ||
walk(nodes) + | ||
'return b;});c.pop();}' + | ||
'else{b += _.b; _.b = ""};'; | ||
'});c.pop();}'; | ||
} | ||
function invertedSection(nodes, id, method) { | ||
return 'if (!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
return 'if(!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
walk(nodes) + | ||
@@ -535,18 +544,18 @@ '};'; | ||
function partial(tok) { | ||
return 'b += _.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '");'; | ||
return '_.b(_.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '"));'; | ||
} | ||
function tripleStache(id, method) { | ||
return 'b += (_.' + method + '("' + esc(id) + '",c,p,0));'; | ||
return '_.b(_.t(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function variable(id, method) { | ||
return 'b += (_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
return '_.b(_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function text(id) { | ||
return 'b += ' + id + ';'; | ||
return '_.b(' + id + ');'; | ||
} | ||
Hogan.parse = function(tokens, options) { | ||
Hogan.parse = function(tokens, text, options) { | ||
options = options || {}; | ||
@@ -580,3 +589,3 @@ return buildTree(tokens, '', [], options.sectionTags || []); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), options)), text, options); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), text, options)), text, options); | ||
return this.cache[key] = t; | ||
@@ -583,0 +592,0 @@ }; |
@@ -5,2 +5,2 @@ /** | ||
*/ | ||
var Hogan={};(function(a){function h(a){return a=String(a===null||a===undefined?"":a),g.test(a)?a.replace(b,"&").replace(c,"<").replace(d,">").replace(e,"'").replace(f,"""):a}a.Template=function j(a,b,c){a&&(this.r=a),this.c=c,this.text=b||""},a.Template.prototype={r:function(a,b,c){return""},v:h,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e)),e.ri(b,c,d)):""},rs:function(a,b,c){var d="",e=a[a.length-1];if(!i(e))return d=c(a,b);for(var f=0;f<e.length;f++)a.push(e[f]),d+=c(a,b),a.pop();return d},s:function(a,b,c,d,e,f,g){var h;return i(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&i(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=a.call(b,d,function(a){return f.compile(a,{delimiters:e}).render(b,c)}),h=f.compile(g.toString(),{delimiters:e}).render(b,c);return this.b=h,!1},b:"",ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=e.toString(),this.c&&~e.indexOf("{{")?this.c.compile(e).render(d,c):e}};var b=/&/g,c=/</g,d=/>/g,e=/\'/g,f=/\"/g,g=/[&<>\"\']/,i=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),function(a){function h(a){a.n.substr(a.n.length-1)==="}"&&(a.n=a.n.substring(0,a.n.length-1))}function i(a){return a.trim?a.trim():a.replace(/^\s*|\s*$/g,"")}function j(a,b,c){if(b.charAt(c)!=a.charAt(0))return!1;for(var d=1,e=a.length;d<e;d++)if(b.charAt(c+d)!=a.charAt(d))return!1;return!0}function k(a,b,c,d){var e=[],f=null,g=null;while(a.length>0){g=a.shift();if(g.tag=="#"||g.tag=="^"||l(g,d))c.push(g),g.nodes=k(a,g.tag,c,d),e.push(g);else{if(g.tag=="/"){if(c.length===0)throw new Error("Closing tag without opener: /"+g.n);f=c.pop();if(g.n!=f.n&&!m(g.n,f.n,d))throw new Error("Nesting error: "+f.n+" vs. "+g.n);return f.end=g.i,e}e.push(g)}}if(c.length>0)throw new Error("missing closing tag: "+c.pop().n);return e}function l(a,b){for(var c=0,d=b.length;c<d;c++)if(b[c].o==a.n)return a.tag="#",!0}function m(a,b,c){for(var d=0,e=c.length;d<e;d++)if(c[d].c==a&&c[d].o==b)return!0}function n(a){return'i = i || "";var b = i + "";var _ = this;'+q(a)+"return b;"}function o(a){return a.replace(f,"\\\\").replace(c,'\\"').replace(d,"\\n").replace(e,"\\r")}function p(a){return~a.indexOf(".")?"d":"f"}function q(a){var b="";for(var c=0,d=a.length;c<d;c++){var e=a[c].tag;e=="#"?b+=r(a[c].nodes,a[c].n,p(a[c].n),a[c].i,a[c].end,a[c].otag+" "+a[c].ctag):e=="^"?b+=s(a[c].nodes,a[c].n,p(a[c].n)):e=="<"||e==">"?b+=t(a[c]):e=="{"||e=="&"?b+=u(a[c].n,p(a[c].n)):e=="\n"?b+=w('"\\n"'+(a.length-1==c?"":" + i")):e=="_v"?b+=v(a[c].n,p(a[c].n)):e===undefined&&(b+=w('"'+o(a[c])+'"'))}return b}function r(a,b,c,d,e,f){return"if(_.s(_."+c+'("'+o(b)+'",c,p,1),'+"c,p,0,"+d+","+e+', "'+f+'")){'+"b += _.rs(c,p,"+'function(c,p){ var b = "";'+q(a)+"return b;});c.pop();}"+'else{b += _.b; _.b = ""};'}function s(a,b,c){return"if (!_.s(_."+c+'("'+o(b)+'",c,p,1),c,p,1,0,0,"")){'+q(a)+"};"}function t(a){return'b += _.rp("'+o(a.n)+'",c,p,"'+(a.indent||"")+'");'}function u(a,b){return"b += (_."+b+'("'+o(a)+'",c,p,0));'}function v(a,b){return"b += (_.v(_."+b+'("'+o(a)+'",c,p,0)));'}function w(a){return"b += "+a+";"}var b=/\S/,c=/\"/g,d=/\n/g,e=/\r/g,f=/\\/g,g={"#":1,"^":2,"/":3,"!":4,">":5,"<":6,"=":7,_v:8,"{":9,"&":10};a.scan=function(c,d){function w(){p.length>0&&(q.push(new String(p)),p="")}function x(){var a=!0;for(var c=t;c<q.length;c++){a=q[c].tag&&g[q[c].tag]<g._v||!q[c].tag&&q[c].match(b)===null;if(!a)return!1}return a}function y(a,b){w();if(a&&x())for(var c=t,d;c<q.length;c++)q[c].tag||((d=q[c+1])&&d.tag==">"&&(d.indent=q[c].toString()),q.splice(c,1));else b||q.push({tag:"\n"});r=!1,t=q.length}function z(a,b){var c="="+v,d=a.indexOf(c,b),e=i(a.substring(a.indexOf("=",b)+1,d)).split(" ");return u=e[0],v=e[1],d+c.length-1}var e=c.length,f=0,k=1,l=2,m=f,n=null,o=null,p="",q=[],r=!1,s=0,t=0,u="{{",v="}}";d&&(d=d.split(" "),u=d[0],v=d[1]);for(s=0;s<e;s++)m==f?j(u,c,s)?(--s,w(),m=k):c.charAt(s)=="\n"?y(r):p+=c.charAt(s):m==k?(s+=u.length-1,o=g[c.charAt(s+1)],n=o?c.charAt(s+1):"_v",n=="="?(s=z(c,s),m=f):(o&&s++,m=l),r=s):j(v,c,s)?(q.push({tag:n,n:i(p),otag:u,ctag:v,i:n=="/"?r-v.length:s+u.length}),p="",s+=v.length-1,m=f,n=="{"&&(v=="}}"?s++:h(q[q.length-1]))):p+=c.charAt(s);return y(r,!0),q},a.generate=function(b,c,d){return d.asString?"function(c,p,i){"+b+";}":new a.Template(new Function("c","p","i",b),c,a)},a.parse=function(a,b){return b=b||{},k(a,"",[],b.sectionTags||[])},a.cache={},a.compile=function(a,b){b=b||{};var c=a+"||"+!!b.asString,d=this.cache[c];return d?d:(d=this.generate(n(this.parse(this.scan(a,b.delimiters),b)),a,b),this.cache[c]=d)}}(typeof exports!="undefined"?exports:Hogan),typeof define=="function"&&define.amd&&define(Hogan) | ||
var Hogan={};(function(a,b){function i(a){return String(a===null||a===undefined?"":a)}function j(a){return a=i(a),h.test(a)?a.replace(c,"&").replace(d,"<").replace(e,">").replace(f,"'").replace(g,"""):a}a.Template=function(a,c,d,e){this.r=a||this.r,this.c=d,this.options=e,this.text=c||"",this.buf=b?[]:""},a.Template.prototype={r:function(a,b,c){return""},v:j,t:i,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e,this.options)),e.ri(b,c,d)):""},rs:function(a,b,c){var d=a[a.length-1];if(!k(d)){c(a,b,this);return}for(var e=0;e<d.length;e++)a.push(d[e]),c(a,b,this),a.pop()},s:function(a,b,c,d,e,f,g){var h;return k(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&k(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=this.options;g.delimiters=e;var h=a.call(b,d,function(a){return f.compile(a,g).render(b,c)});return this.b(f.compile(h.toString(),g).render(b,c)),!1},b:b?function(a){this.buf.push(a)}:function(a){this.buf+=a},fl:b?function(){var a=this.buf.join("");return this.buf=[],a}:function(){var a=this.buf;return this.buf="",a},ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=i(e),this.c&&~e.indexOf("{{")?this.c.compile(e,this.options).render(d,c):e}};var c=/&/g,d=/</g,e=/>/g,f=/\'/g,g=/\"/g,h=/[&<>\"\']/,k=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),function(a){function h(a){a.n.substr(a.n.length-1)==="}"&&(a.n=a.n.substring(0,a.n.length-1))}function i(a){return a.trim?a.trim():a.replace(/^\s*|\s*$/g,"")}function j(a,b,c){if(b.charAt(c)!=a.charAt(0))return!1;for(var d=1,e=a.length;d<e;d++)if(b.charAt(c+d)!=a.charAt(d))return!1;return!0}function k(a,b,c,d){var e=[],f=null,g=null;while(a.length>0){g=a.shift();if(g.tag=="#"||g.tag=="^"||l(g,d))c.push(g),g.nodes=k(a,g.tag,c,d),e.push(g);else{if(g.tag=="/"){if(c.length===0)throw new Error("Closing tag without opener: /"+g.n);f=c.pop();if(g.n!=f.n&&!m(g.n,f.n,d))throw new Error("Nesting error: "+f.n+" vs. "+g.n);return f.end=g.i,e}e.push(g)}}if(c.length>0)throw new Error("missing closing tag: "+c.pop().n);return e}function l(a,b){for(var c=0,d=b.length;c<d;c++)if(b[c].o==a.n)return a.tag="#",!0}function m(a,b,c){for(var d=0,e=c.length;d<e;d++)if(c[d].c==a&&c[d].o==b)return!0}function n(a){return'var _=this;_.b(i=i||"");'+q(a)+"return _.fl();"}function o(a){return a.replace(f,"\\\\").replace(c,'\\"').replace(d,"\\n").replace(e,"\\r")}function p(a){return~a.indexOf(".")?"d":"f"}function q(a){var b="";for(var c=0,d=a.length;c<d;c++){var e=a[c].tag;e=="#"?b+=r(a[c].nodes,a[c].n,p(a[c].n),a[c].i,a[c].end,a[c].otag+" "+a[c].ctag):e=="^"?b+=s(a[c].nodes,a[c].n,p(a[c].n)):e=="<"||e==">"?b+=t(a[c]):e=="{"||e=="&"?b+=u(a[c].n,p(a[c].n)):e=="\n"?b+=w('"\\n"'+(a.length-1==c?"":" + i")):e=="_v"?b+=v(a[c].n,p(a[c].n)):e===undefined&&(b+=w('"'+o(a[c])+'"'))}return b}function r(a,b,c,d,e,f){return"if(_.s(_."+c+'("'+o(b)+'",c,p,1),'+"c,p,0,"+d+","+e+',"'+f+'")){'+"_.rs(c,p,"+"function(c,p,_){"+q(a)+"});c.pop();}"}function s(a,b,c){return"if(!_.s(_."+c+'("'+o(b)+'",c,p,1),c,p,1,0,0,"")){'+q(a)+"};"}function t(a){return'_.b(_.rp("'+o(a.n)+'",c,p,"'+(a.indent||"")+'"));'}function u(a,b){return"_.b(_.t(_."+b+'("'+o(a)+'",c,p,0)));'}function v(a,b){return"_.b(_.v(_."+b+'("'+o(a)+'",c,p,0)));'}function w(a){return"_.b("+a+");"}var b=/\S/,c=/\"/g,d=/\n/g,e=/\r/g,f=/\\/g,g={"#":1,"^":2,"/":3,"!":4,">":5,"<":6,"=":7,_v:8,"{":9,"&":10};a.scan=function(c,d){function w(){p.length>0&&(q.push(new String(p)),p="")}function x(){var a=!0;for(var c=t;c<q.length;c++){a=q[c].tag&&g[q[c].tag]<g._v||!q[c].tag&&q[c].match(b)===null;if(!a)return!1}return a}function y(a,b){w();if(a&&x())for(var c=t,d;c<q.length;c++)q[c].tag||((d=q[c+1])&&d.tag==">"&&(d.indent=q[c].toString()),q.splice(c,1));else b||q.push({tag:"\n"});r=!1,t=q.length}function z(a,b){var c="="+v,d=a.indexOf(c,b),e=i(a.substring(a.indexOf("=",b)+1,d)).split(" ");return u=e[0],v=e[1],d+c.length-1}var e=c.length,f=0,k=1,l=2,m=f,n=null,o=null,p="",q=[],r=!1,s=0,t=0,u="{{",v="}}";d&&(d=d.split(" "),u=d[0],v=d[1]);for(s=0;s<e;s++)m==f?j(u,c,s)?(--s,w(),m=k):c.charAt(s)=="\n"?y(r):p+=c.charAt(s):m==k?(s+=u.length-1,o=g[c.charAt(s+1)],n=o?c.charAt(s+1):"_v",n=="="?(s=z(c,s),m=f):(o&&s++,m=l),r=s):j(v,c,s)?(q.push({tag:n,n:i(p),otag:u,ctag:v,i:n=="/"?r-v.length:s+u.length}),p="",s+=v.length-1,m=f,n=="{"&&(v=="}}"?s++:h(q[q.length-1]))):p+=c.charAt(s);return y(r,!0),q},a.generate=function(b,c,d){return d.asString?"function(c,p,i){"+b+";}":new a.Template(new Function("c","p","i",b),c,a,d)},a.parse=function(a,b,c){return c=c||{},k(a,"",[],c.sectionTags||[])},a.cache={},a.compile=function(a,b){b=b||{};var c=a+"||"+!!b.asString,d=this.cache[c];return d?d:(d=this.generate(n(this.parse(this.scan(a,b.delimiters),a,b)),a,b),this.cache[c]=d)}}(typeof exports!="undefined"?exports:Hogan),typeof define=="function"&&define.amd&&define(Hogan) |
@@ -5,2 +5,2 @@ /** | ||
*/ | ||
var Hogan={};(function(a){function h(a){return a=String(a===null||a===undefined?"":a),g.test(a)?a.replace(b,"&").replace(c,"<").replace(d,">").replace(e,"'").replace(f,"""):a}a.Template=function j(a,b,c){a&&(this.r=a),this.c=c,this.text=b||""},a.Template.prototype={r:function(a,b,c){return""},v:h,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e)),e.ri(b,c,d)):""},rs:function(a,b,c){var d="",e=a[a.length-1];if(!i(e))return d=c(a,b);for(var f=0;f<e.length;f++)a.push(e[f]),d+=c(a,b),a.pop();return d},s:function(a,b,c,d,e,f,g){var h;return i(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&i(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=a.call(b,d,function(a){return f.compile(a,{delimiters:e}).render(b,c)}),h=f.compile(g.toString(),{delimiters:e}).render(b,c);return this.b=h,!1},b:"",ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=e.toString(),this.c&&~e.indexOf("{{")?this.c.compile(e).render(d,c):e}};var b=/&/g,c=/</g,d=/>/g,e=/\'/g,f=/\"/g,g=/[&<>\"\']/,i=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),function(a){function h(a){a.n.substr(a.n.length-1)==="}"&&(a.n=a.n.substring(0,a.n.length-1))}function i(a){return a.trim?a.trim():a.replace(/^\s*|\s*$/g,"")}function j(a,b,c){if(b.charAt(c)!=a.charAt(0))return!1;for(var d=1,e=a.length;d<e;d++)if(b.charAt(c+d)!=a.charAt(d))return!1;return!0}function k(a,b,c,d){var e=[],f=null,g=null;while(a.length>0){g=a.shift();if(g.tag=="#"||g.tag=="^"||l(g,d))c.push(g),g.nodes=k(a,g.tag,c,d),e.push(g);else{if(g.tag=="/"){if(c.length===0)throw new Error("Closing tag without opener: /"+g.n);f=c.pop();if(g.n!=f.n&&!m(g.n,f.n,d))throw new Error("Nesting error: "+f.n+" vs. "+g.n);return f.end=g.i,e}e.push(g)}}if(c.length>0)throw new Error("missing closing tag: "+c.pop().n);return e}function l(a,b){for(var c=0,d=b.length;c<d;c++)if(b[c].o==a.n)return a.tag="#",!0}function m(a,b,c){for(var d=0,e=c.length;d<e;d++)if(c[d].c==a&&c[d].o==b)return!0}function n(a){return'i = i || "";var b = i + "";var _ = this;'+q(a)+"return b;"}function o(a){return a.replace(f,"\\\\").replace(c,'\\"').replace(d,"\\n").replace(e,"\\r")}function p(a){return~a.indexOf(".")?"d":"f"}function q(a){var b="";for(var c=0,d=a.length;c<d;c++){var e=a[c].tag;e=="#"?b+=r(a[c].nodes,a[c].n,p(a[c].n),a[c].i,a[c].end,a[c].otag+" "+a[c].ctag):e=="^"?b+=s(a[c].nodes,a[c].n,p(a[c].n)):e=="<"||e==">"?b+=t(a[c]):e=="{"||e=="&"?b+=u(a[c].n,p(a[c].n)):e=="\n"?b+=w('"\\n"'+(a.length-1==c?"":" + i")):e=="_v"?b+=v(a[c].n,p(a[c].n)):e===undefined&&(b+=w('"'+o(a[c])+'"'))}return b}function r(a,b,c,d,e,f){return"if(_.s(_."+c+'("'+o(b)+'",c,p,1),'+"c,p,0,"+d+","+e+', "'+f+'")){'+"b += _.rs(c,p,"+'function(c,p){ var b = "";'+q(a)+"return b;});c.pop();}"+'else{b += _.b; _.b = ""};'}function s(a,b,c){return"if (!_.s(_."+c+'("'+o(b)+'",c,p,1),c,p,1,0,0,"")){'+q(a)+"};"}function t(a){return'b += _.rp("'+o(a.n)+'",c,p,"'+(a.indent||"")+'");'}function u(a,b){return"b += (_."+b+'("'+o(a)+'",c,p,0));'}function v(a,b){return"b += (_.v(_."+b+'("'+o(a)+'",c,p,0)));'}function w(a){return"b += "+a+";"}var b=/\S/,c=/\"/g,d=/\n/g,e=/\r/g,f=/\\/g,g={"#":1,"^":2,"/":3,"!":4,">":5,"<":6,"=":7,_v:8,"{":9,"&":10};a.scan=function(c,d){function w(){p.length>0&&(q.push(new String(p)),p="")}function x(){var a=!0;for(var c=t;c<q.length;c++){a=q[c].tag&&g[q[c].tag]<g._v||!q[c].tag&&q[c].match(b)===null;if(!a)return!1}return a}function y(a,b){w();if(a&&x())for(var c=t,d;c<q.length;c++)q[c].tag||((d=q[c+1])&&d.tag==">"&&(d.indent=q[c].toString()),q.splice(c,1));else b||q.push({tag:"\n"});r=!1,t=q.length}function z(a,b){var c="="+v,d=a.indexOf(c,b),e=i(a.substring(a.indexOf("=",b)+1,d)).split(" ");return u=e[0],v=e[1],d+c.length-1}var e=c.length,f=0,k=1,l=2,m=f,n=null,o=null,p="",q=[],r=!1,s=0,t=0,u="{{",v="}}";d&&(d=d.split(" "),u=d[0],v=d[1]);for(s=0;s<e;s++)m==f?j(u,c,s)?(--s,w(),m=k):c.charAt(s)=="\n"?y(r):p+=c.charAt(s):m==k?(s+=u.length-1,o=g[c.charAt(s+1)],n=o?c.charAt(s+1):"_v",n=="="?(s=z(c,s),m=f):(o&&s++,m=l),r=s):j(v,c,s)?(q.push({tag:n,n:i(p),otag:u,ctag:v,i:n=="/"?r-v.length:s+u.length}),p="",s+=v.length-1,m=f,n=="{"&&(v=="}}"?s++:h(q[q.length-1]))):p+=c.charAt(s);return y(r,!0),q},a.generate=function(b,c,d){return d.asString?"function(c,p,i){"+b+";}":new a.Template(new Function("c","p","i",b),c,a)},a.parse=function(a,b){return b=b||{},k(a,"",[],b.sectionTags||[])},a.cache={},a.compile=function(a,b){b=b||{};var c=a+"||"+!!b.asString,d=this.cache[c];return d?d:(d=this.generate(n(this.parse(this.scan(a,b.delimiters),b)),a,b),this.cache[c]=d)}}(typeof exports!="undefined"?exports:Hogan),typeof module!="undefined"&&module.exports&&(module.exports=Hogan) | ||
var Hogan={};(function(a,b){function i(a){return String(a===null||a===undefined?"":a)}function j(a){return a=i(a),h.test(a)?a.replace(c,"&").replace(d,"<").replace(e,">").replace(f,"'").replace(g,"""):a}a.Template=function(a,c,d,e){this.r=a||this.r,this.c=d,this.options=e,this.text=c||"",this.buf=b?[]:""},a.Template.prototype={r:function(a,b,c){return""},v:j,t:i,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e,this.options)),e.ri(b,c,d)):""},rs:function(a,b,c){var d=a[a.length-1];if(!k(d)){c(a,b,this);return}for(var e=0;e<d.length;e++)a.push(d[e]),c(a,b,this),a.pop()},s:function(a,b,c,d,e,f,g){var h;return k(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&k(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=this.options;g.delimiters=e;var h=a.call(b,d,function(a){return f.compile(a,g).render(b,c)});return this.b(f.compile(h.toString(),g).render(b,c)),!1},b:b?function(a){this.buf.push(a)}:function(a){this.buf+=a},fl:b?function(){var a=this.buf.join("");return this.buf=[],a}:function(){var a=this.buf;return this.buf="",a},ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=i(e),this.c&&~e.indexOf("{{")?this.c.compile(e,this.options).render(d,c):e}};var c=/&/g,d=/</g,e=/>/g,f=/\'/g,g=/\"/g,h=/[&<>\"\']/,k=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),function(a){function h(a){a.n.substr(a.n.length-1)==="}"&&(a.n=a.n.substring(0,a.n.length-1))}function i(a){return a.trim?a.trim():a.replace(/^\s*|\s*$/g,"")}function j(a,b,c){if(b.charAt(c)!=a.charAt(0))return!1;for(var d=1,e=a.length;d<e;d++)if(b.charAt(c+d)!=a.charAt(d))return!1;return!0}function k(a,b,c,d){var e=[],f=null,g=null;while(a.length>0){g=a.shift();if(g.tag=="#"||g.tag=="^"||l(g,d))c.push(g),g.nodes=k(a,g.tag,c,d),e.push(g);else{if(g.tag=="/"){if(c.length===0)throw new Error("Closing tag without opener: /"+g.n);f=c.pop();if(g.n!=f.n&&!m(g.n,f.n,d))throw new Error("Nesting error: "+f.n+" vs. "+g.n);return f.end=g.i,e}e.push(g)}}if(c.length>0)throw new Error("missing closing tag: "+c.pop().n);return e}function l(a,b){for(var c=0,d=b.length;c<d;c++)if(b[c].o==a.n)return a.tag="#",!0}function m(a,b,c){for(var d=0,e=c.length;d<e;d++)if(c[d].c==a&&c[d].o==b)return!0}function n(a){return'var _=this;_.b(i=i||"");'+q(a)+"return _.fl();"}function o(a){return a.replace(f,"\\\\").replace(c,'\\"').replace(d,"\\n").replace(e,"\\r")}function p(a){return~a.indexOf(".")?"d":"f"}function q(a){var b="";for(var c=0,d=a.length;c<d;c++){var e=a[c].tag;e=="#"?b+=r(a[c].nodes,a[c].n,p(a[c].n),a[c].i,a[c].end,a[c].otag+" "+a[c].ctag):e=="^"?b+=s(a[c].nodes,a[c].n,p(a[c].n)):e=="<"||e==">"?b+=t(a[c]):e=="{"||e=="&"?b+=u(a[c].n,p(a[c].n)):e=="\n"?b+=w('"\\n"'+(a.length-1==c?"":" + i")):e=="_v"?b+=v(a[c].n,p(a[c].n)):e===undefined&&(b+=w('"'+o(a[c])+'"'))}return b}function r(a,b,c,d,e,f){return"if(_.s(_."+c+'("'+o(b)+'",c,p,1),'+"c,p,0,"+d+","+e+',"'+f+'")){'+"_.rs(c,p,"+"function(c,p,_){"+q(a)+"});c.pop();}"}function s(a,b,c){return"if(!_.s(_."+c+'("'+o(b)+'",c,p,1),c,p,1,0,0,"")){'+q(a)+"};"}function t(a){return'_.b(_.rp("'+o(a.n)+'",c,p,"'+(a.indent||"")+'"));'}function u(a,b){return"_.b(_.t(_."+b+'("'+o(a)+'",c,p,0)));'}function v(a,b){return"_.b(_.v(_."+b+'("'+o(a)+'",c,p,0)));'}function w(a){return"_.b("+a+");"}var b=/\S/,c=/\"/g,d=/\n/g,e=/\r/g,f=/\\/g,g={"#":1,"^":2,"/":3,"!":4,">":5,"<":6,"=":7,_v:8,"{":9,"&":10};a.scan=function(c,d){function w(){p.length>0&&(q.push(new String(p)),p="")}function x(){var a=!0;for(var c=t;c<q.length;c++){a=q[c].tag&&g[q[c].tag]<g._v||!q[c].tag&&q[c].match(b)===null;if(!a)return!1}return a}function y(a,b){w();if(a&&x())for(var c=t,d;c<q.length;c++)q[c].tag||((d=q[c+1])&&d.tag==">"&&(d.indent=q[c].toString()),q.splice(c,1));else b||q.push({tag:"\n"});r=!1,t=q.length}function z(a,b){var c="="+v,d=a.indexOf(c,b),e=i(a.substring(a.indexOf("=",b)+1,d)).split(" ");return u=e[0],v=e[1],d+c.length-1}var e=c.length,f=0,k=1,l=2,m=f,n=null,o=null,p="",q=[],r=!1,s=0,t=0,u="{{",v="}}";d&&(d=d.split(" "),u=d[0],v=d[1]);for(s=0;s<e;s++)m==f?j(u,c,s)?(--s,w(),m=k):c.charAt(s)=="\n"?y(r):p+=c.charAt(s):m==k?(s+=u.length-1,o=g[c.charAt(s+1)],n=o?c.charAt(s+1):"_v",n=="="?(s=z(c,s),m=f):(o&&s++,m=l),r=s):j(v,c,s)?(q.push({tag:n,n:i(p),otag:u,ctag:v,i:n=="/"?r-v.length:s+u.length}),p="",s+=v.length-1,m=f,n=="{"&&(v=="}}"?s++:h(q[q.length-1]))):p+=c.charAt(s);return y(r,!0),q},a.generate=function(b,c,d){return d.asString?"function(c,p,i){"+b+";}":new a.Template(new Function("c","p","i",b),c,a,d)},a.parse=function(a,b,c){return c=c||{},k(a,"",[],c.sectionTags||[])},a.cache={},a.compile=function(a,b){b=b||{};var c=a+"||"+!!b.asString,d=this.cache[c];return d?d:(d=this.generate(n(this.parse(this.scan(a,b.delimiters),a,b)),a,b),this.cache[c]=d)}}(typeof exports!="undefined"?exports:Hogan),typeof module!="undefined"&&module.exports&&(module.exports=Hogan) |
@@ -5,2 +5,2 @@ /** | ||
*/ | ||
var Hogan={};(function(a){function h(a){return a=String(a===null||a===undefined?"":a),g.test(a)?a.replace(b,"&").replace(c,"<").replace(d,">").replace(e,"'").replace(f,"""):a}a.Template=function j(a,b,c){a&&(this.r=a),this.c=c,this.text=b||""},a.Template.prototype={r:function(a,b,c){return""},v:h,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e)),e.ri(b,c,d)):""},rs:function(a,b,c){var d="",e=a[a.length-1];if(!i(e))return d=c(a,b);for(var f=0;f<e.length;f++)a.push(e[f]),d+=c(a,b),a.pop();return d},s:function(a,b,c,d,e,f,g){var h;return i(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&i(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=a.call(b,d,function(a){return f.compile(a,{delimiters:e}).render(b,c)}),h=f.compile(g.toString(),{delimiters:e}).render(b,c);return this.b=h,!1},b:"",ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=e.toString(),this.c&&~e.indexOf("{{")?this.c.compile(e).render(d,c):e}};var b=/&/g,c=/</g,d=/>/g,e=/\'/g,f=/\"/g,g=/[&<>\"\']/,i=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),function(a){function h(a){a.n.substr(a.n.length-1)==="}"&&(a.n=a.n.substring(0,a.n.length-1))}function i(a){return a.trim?a.trim():a.replace(/^\s*|\s*$/g,"")}function j(a,b,c){if(b.charAt(c)!=a.charAt(0))return!1;for(var d=1,e=a.length;d<e;d++)if(b.charAt(c+d)!=a.charAt(d))return!1;return!0}function k(a,b,c,d){var e=[],f=null,g=null;while(a.length>0){g=a.shift();if(g.tag=="#"||g.tag=="^"||l(g,d))c.push(g),g.nodes=k(a,g.tag,c,d),e.push(g);else{if(g.tag=="/"){if(c.length===0)throw new Error("Closing tag without opener: /"+g.n);f=c.pop();if(g.n!=f.n&&!m(g.n,f.n,d))throw new Error("Nesting error: "+f.n+" vs. "+g.n);return f.end=g.i,e}e.push(g)}}if(c.length>0)throw new Error("missing closing tag: "+c.pop().n);return e}function l(a,b){for(var c=0,d=b.length;c<d;c++)if(b[c].o==a.n)return a.tag="#",!0}function m(a,b,c){for(var d=0,e=c.length;d<e;d++)if(c[d].c==a&&c[d].o==b)return!0}function n(a){return'i = i || "";var b = i + "";var _ = this;'+q(a)+"return b;"}function o(a){return a.replace(f,"\\\\").replace(c,'\\"').replace(d,"\\n").replace(e,"\\r")}function p(a){return~a.indexOf(".")?"d":"f"}function q(a){var b="";for(var c=0,d=a.length;c<d;c++){var e=a[c].tag;e=="#"?b+=r(a[c].nodes,a[c].n,p(a[c].n),a[c].i,a[c].end,a[c].otag+" "+a[c].ctag):e=="^"?b+=s(a[c].nodes,a[c].n,p(a[c].n)):e=="<"||e==">"?b+=t(a[c]):e=="{"||e=="&"?b+=u(a[c].n,p(a[c].n)):e=="\n"?b+=w('"\\n"'+(a.length-1==c?"":" + i")):e=="_v"?b+=v(a[c].n,p(a[c].n)):e===undefined&&(b+=w('"'+o(a[c])+'"'))}return b}function r(a,b,c,d,e,f){return"if(_.s(_."+c+'("'+o(b)+'",c,p,1),'+"c,p,0,"+d+","+e+', "'+f+'")){'+"b += _.rs(c,p,"+'function(c,p){ var b = "";'+q(a)+"return b;});c.pop();}"+'else{b += _.b; _.b = ""};'}function s(a,b,c){return"if (!_.s(_."+c+'("'+o(b)+'",c,p,1),c,p,1,0,0,"")){'+q(a)+"};"}function t(a){return'b += _.rp("'+o(a.n)+'",c,p,"'+(a.indent||"")+'");'}function u(a,b){return"b += (_."+b+'("'+o(a)+'",c,p,0));'}function v(a,b){return"b += (_.v(_."+b+'("'+o(a)+'",c,p,0)));'}function w(a){return"b += "+a+";"}var b=/\S/,c=/\"/g,d=/\n/g,e=/\r/g,f=/\\/g,g={"#":1,"^":2,"/":3,"!":4,">":5,"<":6,"=":7,_v:8,"{":9,"&":10};a.scan=function(c,d){function w(){p.length>0&&(q.push(new String(p)),p="")}function x(){var a=!0;for(var c=t;c<q.length;c++){a=q[c].tag&&g[q[c].tag]<g._v||!q[c].tag&&q[c].match(b)===null;if(!a)return!1}return a}function y(a,b){w();if(a&&x())for(var c=t,d;c<q.length;c++)q[c].tag||((d=q[c+1])&&d.tag==">"&&(d.indent=q[c].toString()),q.splice(c,1));else b||q.push({tag:"\n"});r=!1,t=q.length}function z(a,b){var c="="+v,d=a.indexOf(c,b),e=i(a.substring(a.indexOf("=",b)+1,d)).split(" ");return u=e[0],v=e[1],d+c.length-1}var e=c.length,f=0,k=1,l=2,m=f,n=null,o=null,p="",q=[],r=!1,s=0,t=0,u="{{",v="}}";d&&(d=d.split(" "),u=d[0],v=d[1]);for(s=0;s<e;s++)m==f?j(u,c,s)?(--s,w(),m=k):c.charAt(s)=="\n"?y(r):p+=c.charAt(s):m==k?(s+=u.length-1,o=g[c.charAt(s+1)],n=o?c.charAt(s+1):"_v",n=="="?(s=z(c,s),m=f):(o&&s++,m=l),r=s):j(v,c,s)?(q.push({tag:n,n:i(p),otag:u,ctag:v,i:n=="/"?r-v.length:s+u.length}),p="",s+=v.length-1,m=f,n=="{"&&(v=="}}"?s++:h(q[q.length-1]))):p+=c.charAt(s);return y(r,!0),q},a.generate=function(b,c,d){return d.asString?"function(c,p,i){"+b+";}":new a.Template(new Function("c","p","i",b),c,a)},a.parse=function(a,b){return b=b||{},k(a,"",[],b.sectionTags||[])},a.cache={},a.compile=function(a,b){b=b||{};var c=a+"||"+!!b.asString,d=this.cache[c];return d?d:(d=this.generate(n(this.parse(this.scan(a,b.delimiters),b)),a,b),this.cache[c]=d)}}(typeof exports!="undefined"?exports:Hogan) | ||
var Hogan={};(function(a,b){function i(a){return String(a===null||a===undefined?"":a)}function j(a){return a=i(a),h.test(a)?a.replace(c,"&").replace(d,"<").replace(e,">").replace(f,"'").replace(g,"""):a}a.Template=function(a,c,d,e){this.r=a||this.r,this.c=d,this.options=e,this.text=c||"",this.buf=b?[]:""},a.Template.prototype={r:function(a,b,c){return""},v:j,t:i,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e,this.options)),e.ri(b,c,d)):""},rs:function(a,b,c){var d=a[a.length-1];if(!k(d)){c(a,b,this);return}for(var e=0;e<d.length;e++)a.push(d[e]),c(a,b,this),a.pop()},s:function(a,b,c,d,e,f,g){var h;return k(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&k(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=this.options;g.delimiters=e;var h=a.call(b,d,function(a){return f.compile(a,g).render(b,c)});return this.b(f.compile(h.toString(),g).render(b,c)),!1},b:b?function(a){this.buf.push(a)}:function(a){this.buf+=a},fl:b?function(){var a=this.buf.join("");return this.buf=[],a}:function(){var a=this.buf;return this.buf="",a},ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=i(e),this.c&&~e.indexOf("{{")?this.c.compile(e,this.options).render(d,c):e}};var c=/&/g,d=/</g,e=/>/g,f=/\'/g,g=/\"/g,h=/[&<>\"\']/,k=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),function(a){function h(a){a.n.substr(a.n.length-1)==="}"&&(a.n=a.n.substring(0,a.n.length-1))}function i(a){return a.trim?a.trim():a.replace(/^\s*|\s*$/g,"")}function j(a,b,c){if(b.charAt(c)!=a.charAt(0))return!1;for(var d=1,e=a.length;d<e;d++)if(b.charAt(c+d)!=a.charAt(d))return!1;return!0}function k(a,b,c,d){var e=[],f=null,g=null;while(a.length>0){g=a.shift();if(g.tag=="#"||g.tag=="^"||l(g,d))c.push(g),g.nodes=k(a,g.tag,c,d),e.push(g);else{if(g.tag=="/"){if(c.length===0)throw new Error("Closing tag without opener: /"+g.n);f=c.pop();if(g.n!=f.n&&!m(g.n,f.n,d))throw new Error("Nesting error: "+f.n+" vs. "+g.n);return f.end=g.i,e}e.push(g)}}if(c.length>0)throw new Error("missing closing tag: "+c.pop().n);return e}function l(a,b){for(var c=0,d=b.length;c<d;c++)if(b[c].o==a.n)return a.tag="#",!0}function m(a,b,c){for(var d=0,e=c.length;d<e;d++)if(c[d].c==a&&c[d].o==b)return!0}function n(a){return'var _=this;_.b(i=i||"");'+q(a)+"return _.fl();"}function o(a){return a.replace(f,"\\\\").replace(c,'\\"').replace(d,"\\n").replace(e,"\\r")}function p(a){return~a.indexOf(".")?"d":"f"}function q(a){var b="";for(var c=0,d=a.length;c<d;c++){var e=a[c].tag;e=="#"?b+=r(a[c].nodes,a[c].n,p(a[c].n),a[c].i,a[c].end,a[c].otag+" "+a[c].ctag):e=="^"?b+=s(a[c].nodes,a[c].n,p(a[c].n)):e=="<"||e==">"?b+=t(a[c]):e=="{"||e=="&"?b+=u(a[c].n,p(a[c].n)):e=="\n"?b+=w('"\\n"'+(a.length-1==c?"":" + i")):e=="_v"?b+=v(a[c].n,p(a[c].n)):e===undefined&&(b+=w('"'+o(a[c])+'"'))}return b}function r(a,b,c,d,e,f){return"if(_.s(_."+c+'("'+o(b)+'",c,p,1),'+"c,p,0,"+d+","+e+',"'+f+'")){'+"_.rs(c,p,"+"function(c,p,_){"+q(a)+"});c.pop();}"}function s(a,b,c){return"if(!_.s(_."+c+'("'+o(b)+'",c,p,1),c,p,1,0,0,"")){'+q(a)+"};"}function t(a){return'_.b(_.rp("'+o(a.n)+'",c,p,"'+(a.indent||"")+'"));'}function u(a,b){return"_.b(_.t(_."+b+'("'+o(a)+'",c,p,0)));'}function v(a,b){return"_.b(_.v(_."+b+'("'+o(a)+'",c,p,0)));'}function w(a){return"_.b("+a+");"}var b=/\S/,c=/\"/g,d=/\n/g,e=/\r/g,f=/\\/g,g={"#":1,"^":2,"/":3,"!":4,">":5,"<":6,"=":7,_v:8,"{":9,"&":10};a.scan=function(c,d){function w(){p.length>0&&(q.push(new String(p)),p="")}function x(){var a=!0;for(var c=t;c<q.length;c++){a=q[c].tag&&g[q[c].tag]<g._v||!q[c].tag&&q[c].match(b)===null;if(!a)return!1}return a}function y(a,b){w();if(a&&x())for(var c=t,d;c<q.length;c++)q[c].tag||((d=q[c+1])&&d.tag==">"&&(d.indent=q[c].toString()),q.splice(c,1));else b||q.push({tag:"\n"});r=!1,t=q.length}function z(a,b){var c="="+v,d=a.indexOf(c,b),e=i(a.substring(a.indexOf("=",b)+1,d)).split(" ");return u=e[0],v=e[1],d+c.length-1}var e=c.length,f=0,k=1,l=2,m=f,n=null,o=null,p="",q=[],r=!1,s=0,t=0,u="{{",v="}}";d&&(d=d.split(" "),u=d[0],v=d[1]);for(s=0;s<e;s++)m==f?j(u,c,s)?(--s,w(),m=k):c.charAt(s)=="\n"?y(r):p+=c.charAt(s):m==k?(s+=u.length-1,o=g[c.charAt(s+1)],n=o?c.charAt(s+1):"_v",n=="="?(s=z(c,s),m=f):(o&&s++,m=l),r=s):j(v,c,s)?(q.push({tag:n,n:i(p),otag:u,ctag:v,i:n=="/"?r-v.length:s+u.length}),p="",s+=v.length-1,m=f,n=="{"&&(v=="}}"?s++:h(q[q.length-1]))):p+=c.charAt(s);return y(r,!0),q},a.generate=function(b,c,d){return d.asString?"function(c,p,i){"+b+";}":new a.Template(new Function("c","p","i",b),c,a,d)},a.parse=function(a,b,c){return c=c||{},k(a,"",[],c.sectionTags||[])},a.cache={},a.compile=function(a,b){b=b||{};var c=a+"||"+!!b.asString,d=this.cache[c];return d?d:(d=this.generate(n(this.parse(this.scan(a,b.delimiters),a,b)),a,b),this.cache[c]=d)}}(typeof exports!="undefined"?exports:Hogan) |
@@ -5,2 +5,2 @@ /** | ||
*/ | ||
var Hogan={};(function(a){function h(a){return a=String(a===null||a===undefined?"":a),g.test(a)?a.replace(b,"&").replace(c,"<").replace(d,">").replace(e,"'").replace(f,"""):a}a.Template=function j(a,b,c){a&&(this.r=a),this.c=c,this.text=b||""},a.Template.prototype={r:function(a,b,c){return""},v:h,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e)),e.ri(b,c,d)):""},rs:function(a,b,c){var d="",e=a[a.length-1];if(!i(e))return d=c(a,b);for(var f=0;f<e.length;f++)a.push(e[f]),d+=c(a,b),a.pop();return d},s:function(a,b,c,d,e,f,g){var h;return i(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&i(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=a.call(b,d,function(a){return f.compile(a,{delimiters:e}).render(b,c)}),h=f.compile(g.toString(),{delimiters:e}).render(b,c);return this.b=h,!1},b:"",ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=e.toString(),this.c&&~e.indexOf("{{")?this.c.compile(e).render(d,c):e}};var b=/&/g,c=/</g,d=/>/g,e=/\'/g,f=/\"/g,g=/[&<>\"\']/,i=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),function(a){function h(a){a.n.substr(a.n.length-1)==="}"&&(a.n=a.n.substring(0,a.n.length-1))}function i(a){return a.trim?a.trim():a.replace(/^\s*|\s*$/g,"")}function j(a,b,c){if(b.charAt(c)!=a.charAt(0))return!1;for(var d=1,e=a.length;d<e;d++)if(b.charAt(c+d)!=a.charAt(d))return!1;return!0}function k(a,b,c,d){var e=[],f=null,g=null;while(a.length>0){g=a.shift();if(g.tag=="#"||g.tag=="^"||l(g,d))c.push(g),g.nodes=k(a,g.tag,c,d),e.push(g);else{if(g.tag=="/"){if(c.length===0)throw new Error("Closing tag without opener: /"+g.n);f=c.pop();if(g.n!=f.n&&!m(g.n,f.n,d))throw new Error("Nesting error: "+f.n+" vs. "+g.n);return f.end=g.i,e}e.push(g)}}if(c.length>0)throw new Error("missing closing tag: "+c.pop().n);return e}function l(a,b){for(var c=0,d=b.length;c<d;c++)if(b[c].o==a.n)return a.tag="#",!0}function m(a,b,c){for(var d=0,e=c.length;d<e;d++)if(c[d].c==a&&c[d].o==b)return!0}function n(a){return'i = i || "";var b = i + "";var _ = this;'+q(a)+"return b;"}function o(a){return a.replace(f,"\\\\").replace(c,'\\"').replace(d,"\\n").replace(e,"\\r")}function p(a){return~a.indexOf(".")?"d":"f"}function q(a){var b="";for(var c=0,d=a.length;c<d;c++){var e=a[c].tag;e=="#"?b+=r(a[c].nodes,a[c].n,p(a[c].n),a[c].i,a[c].end,a[c].otag+" "+a[c].ctag):e=="^"?b+=s(a[c].nodes,a[c].n,p(a[c].n)):e=="<"||e==">"?b+=t(a[c]):e=="{"||e=="&"?b+=u(a[c].n,p(a[c].n)):e=="\n"?b+=w('"\\n"'+(a.length-1==c?"":" + i")):e=="_v"?b+=v(a[c].n,p(a[c].n)):e===undefined&&(b+=w('"'+o(a[c])+'"'))}return b}function r(a,b,c,d,e,f){return"if(_.s(_."+c+'("'+o(b)+'",c,p,1),'+"c,p,0,"+d+","+e+', "'+f+'")){'+"b += _.rs(c,p,"+'function(c,p){ var b = "";'+q(a)+"return b;});c.pop();}"+'else{b += _.b; _.b = ""};'}function s(a,b,c){return"if (!_.s(_."+c+'("'+o(b)+'",c,p,1),c,p,1,0,0,"")){'+q(a)+"};"}function t(a){return'b += _.rp("'+o(a.n)+'",c,p,"'+(a.indent||"")+'");'}function u(a,b){return"b += (_."+b+'("'+o(a)+'",c,p,0));'}function v(a,b){return"b += (_.v(_."+b+'("'+o(a)+'",c,p,0)));'}function w(a){return"b += "+a+";"}var b=/\S/,c=/\"/g,d=/\n/g,e=/\r/g,f=/\\/g,g={"#":1,"^":2,"/":3,"!":4,">":5,"<":6,"=":7,_v:8,"{":9,"&":10};a.scan=function(c,d){function w(){p.length>0&&(q.push(new String(p)),p="")}function x(){var a=!0;for(var c=t;c<q.length;c++){a=q[c].tag&&g[q[c].tag]<g._v||!q[c].tag&&q[c].match(b)===null;if(!a)return!1}return a}function y(a,b){w();if(a&&x())for(var c=t,d;c<q.length;c++)q[c].tag||((d=q[c+1])&&d.tag==">"&&(d.indent=q[c].toString()),q.splice(c,1));else b||q.push({tag:"\n"});r=!1,t=q.length}function z(a,b){var c="="+v,d=a.indexOf(c,b),e=i(a.substring(a.indexOf("=",b)+1,d)).split(" ");return u=e[0],v=e[1],d+c.length-1}var e=c.length,f=0,k=1,l=2,m=f,n=null,o=null,p="",q=[],r=!1,s=0,t=0,u="{{",v="}}";d&&(d=d.split(" "),u=d[0],v=d[1]);for(s=0;s<e;s++)m==f?j(u,c,s)?(--s,w(),m=k):c.charAt(s)=="\n"?y(r):p+=c.charAt(s):m==k?(s+=u.length-1,o=g[c.charAt(s+1)],n=o?c.charAt(s+1):"_v",n=="="?(s=z(c,s),m=f):(o&&s++,m=l),r=s):j(v,c,s)?(q.push({tag:n,n:i(p),otag:u,ctag:v,i:n=="/"?r-v.length:s+u.length}),p="",s+=v.length-1,m=f,n=="{"&&(v=="}}"?s++:h(q[q.length-1]))):p+=c.charAt(s);return y(r,!0),q},a.generate=function(b,c,d){return d.asString?"function(c,p,i){"+b+";}":new a.Template(new Function("c","p","i",b),c,a)},a.parse=function(a,b){return b=b||{},k(a,"",[],b.sectionTags||[])},a.cache={},a.compile=function(a,b){b=b||{};var c=a+"||"+!!b.asString,d=this.cache[c];return d?d:(d=this.generate(n(this.parse(this.scan(a,b.delimiters),b)),a,b),this.cache[c]=d)}}(typeof exports!="undefined"?exports:Hogan);var Mustache=function(a){function b(b,c,d,e){var f=this.f(b,c,d,0),g=c;return f&&(g=g.concat(f)),a.Template.prototype.rp.call(this,b,g,d,e)}var c=function(c,d,e){this.rp=b,a.Template.call(this,c,d,e)};c.prototype=a.Template.prototype;var d,e=function(){this.cache={},this.generate=function(a,b,e){return new c(new Function("c","p","i",a),b,d)}};return e.prototype=a,d=new e,{to_html:function(a,b,c,e){var f=d.compile(a),g=f.render(b,c);if(!e)return g;e(g)}}}(Hogan) | ||
var Hogan={};(function(a,b){function i(a){return String(a===null||a===undefined?"":a)}function j(a){return a=i(a),h.test(a)?a.replace(c,"&").replace(d,"<").replace(e,">").replace(f,"'").replace(g,"""):a}a.Template=function(a,c,d,e){this.r=a||this.r,this.c=d,this.options=e,this.text=c||"",this.buf=b?[]:""},a.Template.prototype={r:function(a,b,c){return""},v:j,t:i,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e,this.options)),e.ri(b,c,d)):""},rs:function(a,b,c){var d=a[a.length-1];if(!k(d)){c(a,b,this);return}for(var e=0;e<d.length;e++)a.push(d[e]),c(a,b,this),a.pop()},s:function(a,b,c,d,e,f,g){var h;return k(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&k(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=this.options;g.delimiters=e;var h=a.call(b,d,function(a){return f.compile(a,g).render(b,c)});return this.b(f.compile(h.toString(),g).render(b,c)),!1},b:b?function(a){this.buf.push(a)}:function(a){this.buf+=a},fl:b?function(){var a=this.buf.join("");return this.buf=[],a}:function(){var a=this.buf;return this.buf="",a},ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=i(e),this.c&&~e.indexOf("{{")?this.c.compile(e,this.options).render(d,c):e}};var c=/&/g,d=/</g,e=/>/g,f=/\'/g,g=/\"/g,h=/[&<>\"\']/,k=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan),function(a){function h(a){a.n.substr(a.n.length-1)==="}"&&(a.n=a.n.substring(0,a.n.length-1))}function i(a){return a.trim?a.trim():a.replace(/^\s*|\s*$/g,"")}function j(a,b,c){if(b.charAt(c)!=a.charAt(0))return!1;for(var d=1,e=a.length;d<e;d++)if(b.charAt(c+d)!=a.charAt(d))return!1;return!0}function k(a,b,c,d){var e=[],f=null,g=null;while(a.length>0){g=a.shift();if(g.tag=="#"||g.tag=="^"||l(g,d))c.push(g),g.nodes=k(a,g.tag,c,d),e.push(g);else{if(g.tag=="/"){if(c.length===0)throw new Error("Closing tag without opener: /"+g.n);f=c.pop();if(g.n!=f.n&&!m(g.n,f.n,d))throw new Error("Nesting error: "+f.n+" vs. "+g.n);return f.end=g.i,e}e.push(g)}}if(c.length>0)throw new Error("missing closing tag: "+c.pop().n);return e}function l(a,b){for(var c=0,d=b.length;c<d;c++)if(b[c].o==a.n)return a.tag="#",!0}function m(a,b,c){for(var d=0,e=c.length;d<e;d++)if(c[d].c==a&&c[d].o==b)return!0}function n(a){return'var _=this;_.b(i=i||"");'+q(a)+"return _.fl();"}function o(a){return a.replace(f,"\\\\").replace(c,'\\"').replace(d,"\\n").replace(e,"\\r")}function p(a){return~a.indexOf(".")?"d":"f"}function q(a){var b="";for(var c=0,d=a.length;c<d;c++){var e=a[c].tag;e=="#"?b+=r(a[c].nodes,a[c].n,p(a[c].n),a[c].i,a[c].end,a[c].otag+" "+a[c].ctag):e=="^"?b+=s(a[c].nodes,a[c].n,p(a[c].n)):e=="<"||e==">"?b+=t(a[c]):e=="{"||e=="&"?b+=u(a[c].n,p(a[c].n)):e=="\n"?b+=w('"\\n"'+(a.length-1==c?"":" + i")):e=="_v"?b+=v(a[c].n,p(a[c].n)):e===undefined&&(b+=w('"'+o(a[c])+'"'))}return b}function r(a,b,c,d,e,f){return"if(_.s(_."+c+'("'+o(b)+'",c,p,1),'+"c,p,0,"+d+","+e+',"'+f+'")){'+"_.rs(c,p,"+"function(c,p,_){"+q(a)+"});c.pop();}"}function s(a,b,c){return"if(!_.s(_."+c+'("'+o(b)+'",c,p,1),c,p,1,0,0,"")){'+q(a)+"};"}function t(a){return'_.b(_.rp("'+o(a.n)+'",c,p,"'+(a.indent||"")+'"));'}function u(a,b){return"_.b(_.t(_."+b+'("'+o(a)+'",c,p,0)));'}function v(a,b){return"_.b(_.v(_."+b+'("'+o(a)+'",c,p,0)));'}function w(a){return"_.b("+a+");"}var b=/\S/,c=/\"/g,d=/\n/g,e=/\r/g,f=/\\/g,g={"#":1,"^":2,"/":3,"!":4,">":5,"<":6,"=":7,_v:8,"{":9,"&":10};a.scan=function(c,d){function w(){p.length>0&&(q.push(new String(p)),p="")}function x(){var a=!0;for(var c=t;c<q.length;c++){a=q[c].tag&&g[q[c].tag]<g._v||!q[c].tag&&q[c].match(b)===null;if(!a)return!1}return a}function y(a,b){w();if(a&&x())for(var c=t,d;c<q.length;c++)q[c].tag||((d=q[c+1])&&d.tag==">"&&(d.indent=q[c].toString()),q.splice(c,1));else b||q.push({tag:"\n"});r=!1,t=q.length}function z(a,b){var c="="+v,d=a.indexOf(c,b),e=i(a.substring(a.indexOf("=",b)+1,d)).split(" ");return u=e[0],v=e[1],d+c.length-1}var e=c.length,f=0,k=1,l=2,m=f,n=null,o=null,p="",q=[],r=!1,s=0,t=0,u="{{",v="}}";d&&(d=d.split(" "),u=d[0],v=d[1]);for(s=0;s<e;s++)m==f?j(u,c,s)?(--s,w(),m=k):c.charAt(s)=="\n"?y(r):p+=c.charAt(s):m==k?(s+=u.length-1,o=g[c.charAt(s+1)],n=o?c.charAt(s+1):"_v",n=="="?(s=z(c,s),m=f):(o&&s++,m=l),r=s):j(v,c,s)?(q.push({tag:n,n:i(p),otag:u,ctag:v,i:n=="/"?r-v.length:s+u.length}),p="",s+=v.length-1,m=f,n=="{"&&(v=="}}"?s++:h(q[q.length-1]))):p+=c.charAt(s);return y(r,!0),q},a.generate=function(b,c,d){return d.asString?"function(c,p,i){"+b+";}":new a.Template(new Function("c","p","i",b),c,a,d)},a.parse=function(a,b,c){return c=c||{},k(a,"",[],c.sectionTags||[])},a.cache={},a.compile=function(a,b){b=b||{};var c=a+"||"+!!b.asString,d=this.cache[c];return d?d:(d=this.generate(n(this.parse(this.scan(a,b.delimiters),a,b)),a,b),this.cache[c]=d)}}(typeof exports!="undefined"?exports:Hogan);var Mustache=function(a){function b(b,c,d,e){var f=this.f(b,c,d,0),g=c;return f&&(g=g.concat(f)),a.Template.prototype.rp.call(this,b,g,d,e)}var c=function(c,d,e){this.rp=b,a.Template.call(this,c,d,e)};c.prototype=a.Template.prototype;var d,e=function(){this.cache={},this.generate=function(a,b,e){return new c(new Function("c","p","i",a),b,d)}};return e.prototype=a,d=new e,{to_html:function(a,b,c,e){var f=d.compile(a),g=f.render(b,c);if(!e)return g;e(g)}}}(Hogan) |
@@ -22,9 +22,9 @@ /* | ||
(function (Hogan) { | ||
Hogan.Template = function constructor(renderFunc, text, compiler) { | ||
if (renderFunc) { | ||
this.r = renderFunc; | ||
} | ||
(function (Hogan, useArrayBuffer) { | ||
Hogan.Template = function (renderFunc, text, compiler, options) { | ||
this.r = renderFunc || this.r; | ||
this.c = compiler; | ||
this.options = options; | ||
this.text = text || ''; | ||
this.buf = (useArrayBuffer) ? [] : ''; | ||
} | ||
@@ -39,2 +39,5 @@ | ||
// triple stache | ||
t: coerceToString, | ||
render: function render(context, partials, indent) { | ||
@@ -58,3 +61,3 @@ return this.ri([context], partials || {}, indent); | ||
if (this.c && typeof partial == 'string') { | ||
partial = this.c.compile(partial); | ||
partial = this.c.compile(partial, this.options); | ||
} | ||
@@ -67,7 +70,7 @@ | ||
rs: function(context, partials, section) { | ||
var buf = '', | ||
tail = context[context.length - 1]; | ||
var tail = context[context.length - 1]; | ||
if (!isArray(tail)) { | ||
return buf = section(context, partials); | ||
section(context, partials, this); | ||
return; | ||
} | ||
@@ -77,7 +80,5 @@ | ||
context.push(tail[i]); | ||
buf += section(context, partials); | ||
section(context, partials, this); | ||
context.pop(); | ||
} | ||
return buf; | ||
}, | ||
@@ -167,12 +168,16 @@ | ||
var compiler = this.c; | ||
var options = this.options; | ||
options.delimiters = tags; | ||
var t = val.call(cx, text, function(t) { | ||
return compiler.compile(t, {delimiters: tags}).render(cx, partials); | ||
return compiler.compile(t, options).render(cx, partials); | ||
}); | ||
var s = compiler.compile(t.toString(), {delimiters: tags}).render(cx, partials); | ||
this.b = s; | ||
this.b(compiler.compile(t.toString(), options).render(cx, partials)); | ||
return false; | ||
}, | ||
// higher order template result buffer | ||
b: '', | ||
// template result buffering | ||
b: (useArrayBuffer) ? function(s) { this.buf.push(s); } : | ||
function(s) { this.buf += s; }, | ||
fl: (useArrayBuffer) ? function() { var r = this.buf.join(''); this.buf = []; return r; } : | ||
function() { var r = this.buf; this.buf = ''; return r; }, | ||
@@ -208,6 +213,6 @@ // lambda replace section | ||
} | ||
result = result.toString(); | ||
result = coerceToString(result); | ||
if (this.c && ~result.indexOf("{{")) { | ||
return this.c.compile(result).render(cx, partials); | ||
if (this.c && ~result.indexOf("{\u007B")) { | ||
return this.c.compile(result, this.options).render(cx, partials); | ||
} | ||
@@ -227,4 +232,9 @@ | ||
function coerceToString(val) { | ||
return String((val === null || val === undefined) ? '' : val); | ||
} | ||
function hoganEscape(str) { | ||
str = String((str === null || str === undefined) ? '' : str); | ||
str = coerceToString(str); | ||
return hChars.test(str) ? | ||
@@ -470,3 +480,3 @@ str | ||
function writeCode(tree) { | ||
return 'i = i || "";var b = i + "";var _ = this;' + walk(tree) + 'return b;'; | ||
return 'var _=this;_.b(i=i||"");' + walk(tree) + 'return _.fl();'; | ||
} | ||
@@ -479,3 +489,3 @@ | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan); | ||
return new Hogan.Template(new Function('c', 'p', 'i', code), text, Hogan, options); | ||
} | ||
@@ -521,12 +531,11 @@ | ||
return 'if(_.s(_.' + method + '("' + esc(id) + '",c,p,1),' + | ||
'c,p,0,' + start + ',' + end + ', "' + tags + '")){' + | ||
'b += _.rs(c,p,' + | ||
'function(c,p){ var b = "";' + | ||
'c,p,0,' + start + ',' + end + ',"' + tags + '")){' + | ||
'_.rs(c,p,' + | ||
'function(c,p,_){' + | ||
walk(nodes) + | ||
'return b;});c.pop();}' + | ||
'else{b += _.b; _.b = ""};'; | ||
'});c.pop();}'; | ||
} | ||
function invertedSection(nodes, id, method) { | ||
return 'if (!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
return 'if(!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' + | ||
walk(nodes) + | ||
@@ -537,18 +546,18 @@ '};'; | ||
function partial(tok) { | ||
return 'b += _.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '");'; | ||
return '_.b(_.rp("' + esc(tok.n) + '",c,p,"' + (tok.indent || '') + '"));'; | ||
} | ||
function tripleStache(id, method) { | ||
return 'b += (_.' + method + '("' + esc(id) + '",c,p,0));'; | ||
return '_.b(_.t(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function variable(id, method) { | ||
return 'b += (_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
return '_.b(_.v(_.' + method + '("' + esc(id) + '",c,p,0)));'; | ||
} | ||
function text(id) { | ||
return 'b += ' + id + ';'; | ||
return '_.b(' + id + ');'; | ||
} | ||
Hogan.parse = function(tokens, options) { | ||
Hogan.parse = function(tokens, text, options) { | ||
options = options || {}; | ||
@@ -582,3 +591,3 @@ return buildTree(tokens, '', [], options.sectionTags || []); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), options)), text, options); | ||
t = this.generate(writeCode(this.parse(this.scan(text, options.delimiters), text, options)), text, options); | ||
return this.cache[key] = t; | ||
@@ -585,0 +594,0 @@ }; |
@@ -18,9 +18,9 @@ /* | ||
(function (Hogan) { | ||
Hogan.Template = function constructor(renderFunc, text, compiler) { | ||
if (renderFunc) { | ||
this.r = renderFunc; | ||
} | ||
(function (Hogan, useArrayBuffer) { | ||
Hogan.Template = function (renderFunc, text, compiler, options) { | ||
this.r = renderFunc || this.r; | ||
this.c = compiler; | ||
this.options = options; | ||
this.text = text || ''; | ||
this.buf = (useArrayBuffer) ? [] : ''; | ||
} | ||
@@ -35,2 +35,5 @@ | ||
// triple stache | ||
t: coerceToString, | ||
render: function render(context, partials, indent) { | ||
@@ -54,3 +57,3 @@ return this.ri([context], partials || {}, indent); | ||
if (this.c && typeof partial == 'string') { | ||
partial = this.c.compile(partial); | ||
partial = this.c.compile(partial, this.options); | ||
} | ||
@@ -63,7 +66,7 @@ | ||
rs: function(context, partials, section) { | ||
var buf = '', | ||
tail = context[context.length - 1]; | ||
var tail = context[context.length - 1]; | ||
if (!isArray(tail)) { | ||
return buf = section(context, partials); | ||
section(context, partials, this); | ||
return; | ||
} | ||
@@ -73,7 +76,5 @@ | ||
context.push(tail[i]); | ||
buf += section(context, partials); | ||
section(context, partials, this); | ||
context.pop(); | ||
} | ||
return buf; | ||
}, | ||
@@ -163,12 +164,16 @@ | ||
var compiler = this.c; | ||
var options = this.options; | ||
options.delimiters = tags; | ||
var t = val.call(cx, text, function(t) { | ||
return compiler.compile(t, {delimiters: tags}).render(cx, partials); | ||
return compiler.compile(t, options).render(cx, partials); | ||
}); | ||
var s = compiler.compile(t.toString(), {delimiters: tags}).render(cx, partials); | ||
this.b = s; | ||
this.b(compiler.compile(t.toString(), options).render(cx, partials)); | ||
return false; | ||
}, | ||
// higher order template result buffer | ||
b: '', | ||
// template result buffering | ||
b: (useArrayBuffer) ? function(s) { this.buf.push(s); } : | ||
function(s) { this.buf += s; }, | ||
fl: (useArrayBuffer) ? function() { var r = this.buf.join(''); this.buf = []; return r; } : | ||
function() { var r = this.buf; this.buf = ''; return r; }, | ||
@@ -204,6 +209,6 @@ // lambda replace section | ||
} | ||
result = result.toString(); | ||
result = coerceToString(result); | ||
if (this.c && ~result.indexOf("{{")) { | ||
return this.c.compile(result).render(cx, partials); | ||
if (this.c && ~result.indexOf("{\u007B")) { | ||
return this.c.compile(result, this.options).render(cx, partials); | ||
} | ||
@@ -223,4 +228,9 @@ | ||
function coerceToString(val) { | ||
return String((val === null || val === undefined) ? '' : val); | ||
} | ||
function hoganEscape(str) { | ||
str = String((str === null || str === undefined) ? '' : str); | ||
str = coerceToString(str); | ||
return hChars.test(str) ? | ||
@@ -227,0 +237,0 @@ str |
@@ -5,2 +5,2 @@ /** | ||
*/ | ||
var Hogan={};(function(a){function h(a){return a=String(a===null||a===undefined?"":a),g.test(a)?a.replace(b,"&").replace(c,"<").replace(d,">").replace(e,"'").replace(f,"""):a}a.Template=function j(a,b,c){a&&(this.r=a),this.c=c,this.text=b||""},a.Template.prototype={r:function(a,b,c){return""},v:h,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e)),e.ri(b,c,d)):""},rs:function(a,b,c){var d="",e=a[a.length-1];if(!i(e))return d=c(a,b);for(var f=0;f<e.length;f++)a.push(e[f]),d+=c(a,b),a.pop();return d},s:function(a,b,c,d,e,f,g){var h;return i(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&i(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=a.call(b,d,function(a){return f.compile(a,{delimiters:e}).render(b,c)}),h=f.compile(g.toString(),{delimiters:e}).render(b,c);return this.b=h,!1},b:"",ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=e.toString(),this.c&&~e.indexOf("{{")?this.c.compile(e).render(d,c):e}};var b=/&/g,c=/</g,d=/>/g,e=/\'/g,f=/\"/g,g=/[&<>\"\']/,i=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan) | ||
var Hogan={};(function(a,b){function i(a){return String(a===null||a===undefined?"":a)}function j(a){return a=i(a),h.test(a)?a.replace(c,"&").replace(d,"<").replace(e,">").replace(f,"'").replace(g,"""):a}a.Template=function(a,c,d,e){this.r=a||this.r,this.c=d,this.options=e,this.text=c||"",this.buf=b?[]:""},a.Template.prototype={r:function(a,b,c){return""},v:j,t:i,render:function(b,c,d){return this.ri([b],c||{},d)},ri:function(a,b,c){return this.r(a,b,c)},rp:function(a,b,c,d){var e=c[a];return e?(this.c&&typeof e=="string"&&(e=this.c.compile(e,this.options)),e.ri(b,c,d)):""},rs:function(a,b,c){var d=a[a.length-1];if(!k(d)){c(a,b,this);return}for(var e=0;e<d.length;e++)a.push(d[e]),c(a,b,this),a.pop()},s:function(a,b,c,d,e,f,g){var h;return k(a)&&a.length===0?!1:(typeof a=="function"&&(a=this.ls(a,b,c,d,e,f,g)),h=a===""||!!a,!d&&h&&b&&b.push(typeof a=="object"?a:b[b.length-1]),h)},d:function(a,b,c,d){var e=a.split("."),f=this.f(e[0],b,c,d),g=null;if(a==="."&&k(b[b.length-2]))return b[b.length-1];for(var h=1;h<e.length;h++)f&&typeof f=="object"&&e[h]in f?(g=f,f=f[e[h]]):f="";return d&&!f?!1:(!d&&typeof f=="function"&&(b.push(g),f=this.lv(f,b,c),b.pop()),f)},f:function(a,b,c,d){var e=!1,f=null,g=!1;for(var h=b.length-1;h>=0;h--){f=b[h];if(f&&typeof f=="object"&&a in f){e=f[a],g=!0;break}}return g?(!d&&typeof e=="function"&&(e=this.lv(e,b,c)),e):d?!1:""},ho:function(a,b,c,d,e){var f=this.c,g=this.options;g.delimiters=e;var h=a.call(b,d,function(a){return f.compile(a,g).render(b,c)});return this.b(f.compile(h.toString(),g).render(b,c)),!1},b:b?function(a){this.buf.push(a)}:function(a){this.buf+=a},fl:b?function(){var a=this.buf.join("");return this.buf=[],a}:function(){var a=this.buf;return this.buf="",a},ls:function(a,b,c,d,e,f,g){var h=b[b.length-1],i=null;if(!d&&this.c&&a.length>0)return this.ho(a,h,c,this.text.substring(e,f),g);i=a.call(h);if(typeof i=="function"){if(d)return!0;if(this.c)return this.ho(i,h,c,this.text.substring(e,f),g)}return i},lv:function(a,b,c){var d=b[b.length-1],e=a.call(d);return typeof e=="function"&&(e=e.call(d)),e=i(e),this.c&&~e.indexOf("{{")?this.c.compile(e,this.options).render(d,c):e}};var c=/&/g,d=/</g,e=/>/g,f=/\'/g,g=/\"/g,h=/[&<>\"\']/,k=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"}})(typeof exports!="undefined"?exports:Hogan) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
847563
89
19280
1
3
4