mirror of
https://github.com/twbs/bootstrap.git
synced 2025-10-01 15:56:45 +02:00
add templates for doc generation
This commit is contained in:
8
docs/build/node_modules/hogan.js/test/html/list.html
generated
vendored
Normal file
8
docs/build/node_modules/hogan.js/test/html/list.html
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<ul>
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
</ul>
|
13
docs/build/node_modules/hogan.js/test/index.html
generated
vendored
Normal file
13
docs/build/node_modules/hogan.js/test/index.html
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>test</title>
|
||||
<script src="https://raw.github.com/douglascrockford/JSON-js/master/json2.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<code id="console"></code>
|
||||
<script>var Hogan = {};</script>
|
||||
<script src="../lib/template.js"></script>
|
||||
<script src="../lib/compiler.js"></script>
|
||||
<script src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
848
docs/build/node_modules/hogan.js/test/index.js
generated
vendored
Normal file
848
docs/build/node_modules/hogan.js/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,848 @@
|
||||
/*
|
||||
* Copyright 2011 Twitter, Inc.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var Hogan = Hogan || require('../lib/hogan')
|
||||
, doc = this["document"]
|
||||
|
||||
function testScanTextNoTags() {
|
||||
var text = "<h2>hi</h2>";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 1, "One token");
|
||||
is(tokens[0]+'', text, "text is equal to first token");
|
||||
}
|
||||
|
||||
function testScanOneTag() {
|
||||
var text = "{{hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 1, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
}
|
||||
|
||||
function testScanMultipleTags() {
|
||||
var text = "asdf{{hmm}}asdf2{{hmm2}}asdf3";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 5, "3 text tokens, 2 tag tokens.");
|
||||
is(tokens[0]+'', "asdf", "first token is text");
|
||||
is(tokens[1].n, "hmm", "second token is tag");
|
||||
is(tokens[1].tag, "_v", "second token is a variable");
|
||||
is(tokens[2]+'', "asdf2", "third token is text");
|
||||
is(tokens[3].n, "hmm2", "fourth token is tag");
|
||||
is(tokens[3].tag, "_v", "fourth token is a variable");
|
||||
is(tokens[4]+'', "asdf3", "Fifth token is text");
|
||||
}
|
||||
|
||||
function testScanSectionOpen() {
|
||||
var text = "{{#hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 1, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[0].tag, "#", "First token is a section.");
|
||||
}
|
||||
|
||||
function testScanSectionClose() {
|
||||
var text = "{{/hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 1, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[0].tag, "/", "First token is a section.");
|
||||
}
|
||||
|
||||
function testScanSection() {
|
||||
var text = "{{#hmm}}{{/hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 2, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[0].tag, "#", "First token is a section.");
|
||||
is(tokens[1].n, "hmm", "Second token content is variable name.");
|
||||
is(tokens[1].tag, "/", "Second token is a section.");
|
||||
}
|
||||
|
||||
function testScanSectionInContent() {
|
||||
var text = "abc{{#hmm}}def{{/hmm}}ghi";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 5, "3 text tokens, 2 tag tokens.");
|
||||
is(tokens[0]+'', "abc", "first token is text");
|
||||
is(tokens[1].n, "hmm", "second token is tag");
|
||||
is(tokens[1].tag, "#", "second token is a variable");
|
||||
is(tokens[2]+'', "def", "third token is text");
|
||||
is(tokens[3].n, "hmm", "fourth token is tag");
|
||||
is(tokens[3].tag, "/", "fourth token is a variable");
|
||||
is(tokens[4]+'', "ghi", "Fifth token is text");
|
||||
}
|
||||
|
||||
function testScanNegativeSection() {
|
||||
var text = "{{^hmm}}{{/hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 2, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[0].tag, "^", "First token is a negative section.");
|
||||
is(tokens[1].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[1].tag, "/", "Second token is a section.");
|
||||
}
|
||||
|
||||
function testScanPartial() {
|
||||
var text = "{{>hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 1, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[0].tag, ">", "First token is a partial.");
|
||||
}
|
||||
|
||||
|
||||
function testScanBackwardPartial() {
|
||||
var text = "{{<hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 1, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[0].tag, "<", "First token is a backward partial.");
|
||||
}
|
||||
|
||||
function testScanAmpersandNoEscapeTag() {
|
||||
var text = "{{&hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 1, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[0].tag, "&", "First token is an ampersand no-escape.");
|
||||
}
|
||||
|
||||
function testScanTripleStache() {
|
||||
var text = "{{{hmm}}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 1, "One token");
|
||||
is(tokens[0].n, "hmm", "First token content is variable name.");
|
||||
is(tokens[0].tag, "{", "First token is a triple-stache.");
|
||||
}
|
||||
|
||||
function testScanSectionWithTripleStacheInside() {
|
||||
var text = "a{{#yo}}b{{{hmm}}}c{{/yo}}d";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 7, "One token");
|
||||
is(tokens[0]+'', "a", "First token content is correct text.");
|
||||
is(tokens[1].n, "yo", "Second token content is correct text.");
|
||||
is(tokens[1].tag, "#", "Second token is a section.");
|
||||
is(tokens[2]+'', "b", "Third token content is correct text.");
|
||||
is(tokens[3].n, "hmm", "Fourth token content is correct text.");
|
||||
is(tokens[3].tag, "{", "Fourth token is a triple stache.");
|
||||
is(tokens[4]+'', "c", "Fifth token content is correct text.");
|
||||
is(tokens[5].n, "yo", "Sixth token content is correct text.");
|
||||
is(tokens[5].tag, "/", "Sixth token is a close.");
|
||||
is(tokens[6]+'', "d", "Seventh token content is correct text.");
|
||||
}
|
||||
|
||||
function testScanSetDelimiter() {
|
||||
var text = "a{{=<% %>=}}b";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 2, "change delimiter doesn't appear as token.");
|
||||
is(tokens[0]+'', "a", "text before change delimiter is processed.");
|
||||
is(tokens[1]+'', "b", "text after change delimiter is processed.");
|
||||
}
|
||||
|
||||
function testScanResetDelimiter() {
|
||||
var text = "a{{=<% %>=}}b<%hmm%>c<%={{ }}=%>d{{hmm}}";
|
||||
var tokens = Hogan.scan(text);
|
||||
is(tokens.length, 6, "8 tokens, delimiter changes don't count.");
|
||||
is(tokens[0]+'', "a", "first token is correct.");
|
||||
is(tokens[1]+'', "b", "third token is correct.");
|
||||
is(tokens[2].tag, "_v", "third token is correct tag.");
|
||||
is(tokens[2].n, "hmm", "third token is correct name.");
|
||||
is(tokens[3]+'', "c", "fifth token is correct.");
|
||||
is(tokens[4]+'', "d", "seventh token is correct.");
|
||||
is(tokens[5].tag, "_v", "eighth token is correct tag.");
|
||||
is(tokens[5].n, "hmm", "eighth token is correct name.");
|
||||
}
|
||||
|
||||
function testSingleCharDelimiter() {
|
||||
var text = '({{foo}} {{=[ ]=}}[text])';
|
||||
var tokens = Hogan.scan(text);
|
||||
|
||||
var t = Hogan.compile(text);
|
||||
s = t.render({foo: "bar", text: 'It worked!'});
|
||||
is(s, '(bar It worked!)', "Hogan substitution worked after custom delimiters.");
|
||||
}
|
||||
|
||||
function testSetDelimiterWithWhitespace() {
|
||||
var text = "{{= | | =}}|foo|";
|
||||
var t = Hogan.compile(text);
|
||||
s = t.render({foo: "bar"});
|
||||
is(s, 'bar', "custom delimiters with whitespace works.")
|
||||
}
|
||||
|
||||
function testParseBasic() {
|
||||
var text = "test";
|
||||
var tree = Hogan.parse(Hogan.scan(text));
|
||||
is(tree.length, 1, "one parse node");
|
||||
is(tree[0]+'', "test", "text is correct");
|
||||
}
|
||||
|
||||
function testParseVariables() {
|
||||
var text = "test{{foo}}test!{{bar}}test!!{{baz}}test!!!";
|
||||
var tree = Hogan.parse(Hogan.scan(text));
|
||||
is(tree.length, 7, "one parse node");
|
||||
is(tree[0]+'', "test", "first text is correct");
|
||||
is(tree[2]+'', "test!", "second text is correct")
|
||||
is(tree[4]+'', "test!!", "third text is correct")
|
||||
is(tree[6]+'', "test!!!", "last text is correct")
|
||||
is(tree[1].n, "foo", "first var is correct");
|
||||
is(tree[3].n, "bar", "second var is correct");
|
||||
is(tree[5].n, "baz", "third var is correct");
|
||||
}
|
||||
|
||||
function testParseSection() {
|
||||
var text = "a{{#foo}}b{{/foo}}c";
|
||||
var tree = Hogan.parse(Hogan.scan(text));
|
||||
is(tree.length, 3, "three nodes at base");
|
||||
is(tree[0]+'', "a", "correct text in first node");
|
||||
is(tree[1].hasOwnProperty('nodes'), true, "second node is a section");
|
||||
is(tree[1].tag, '#', "second node is a section");
|
||||
is(tree[1].n, "foo", "correct name for section");
|
||||
is(tree[1].nodes[0]+'', "b", "correct text in section");
|
||||
is(tree[2]+'', "c", "correct text in last node");
|
||||
}
|
||||
|
||||
function testParseIndexes() {
|
||||
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() {
|
||||
var text = "a{{^foo}}b{{/foo}}c";
|
||||
var tree = Hogan.parse(Hogan.scan(text));
|
||||
|
||||
is(tree.length, 3, "three nodes at base");
|
||||
is(tree[0]+'', "a", "correct text in first node");
|
||||
is(tree[1].hasOwnProperty('nodes'), true, "second node is a section");
|
||||
is(tree[1].tag, '^', "second node is a negative section");
|
||||
is(tree[1].n, "foo", "correct name for section");
|
||||
is(tree[1].nodes[0]+'', "b", "correct text in section");
|
||||
is(tree[2]+'', "c", "correct text in last node");
|
||||
}
|
||||
|
||||
function testParseNestedSections() {
|
||||
var text = "{{#bar}}{{#foo}}c{{/foo}}{{/bar}}"
|
||||
var tree = Hogan.parse(Hogan.scan(text));
|
||||
|
||||
is(tree.length, 1, "one node at base");
|
||||
is(tree[0].tag, "#", "open section is first node");
|
||||
is(tree[0].n, "bar", "first section name is 'bar'");
|
||||
is(tree[0].nodes.length, 1, "first section contains one node.");
|
||||
is(tree[0].nodes[0].n, "foo", "correct name for nested section");
|
||||
is(tree[0].nodes[0].nodes[0]+'', "c", "correct text in nested section");
|
||||
}
|
||||
|
||||
function testMissingClosingTag() {
|
||||
var text = "a{{#foo}}bc";
|
||||
var msg = '';
|
||||
try {
|
||||
var tree = Hogan.parse(Hogan.scan(text));
|
||||
} catch (e) {
|
||||
msg = e.message;
|
||||
}
|
||||
is(msg, "missing closing tag: foo", "Error is generated");
|
||||
}
|
||||
|
||||
function testBadNesting() {
|
||||
var text = "a{{#foo}}{{#bar}}b{{/foo}}{{/bar}}c";
|
||||
var msg = '';
|
||||
try {
|
||||
var tree = Hogan.parse(Hogan.scan(text));
|
||||
} catch (e) {
|
||||
msg = e.message;
|
||||
}
|
||||
is(msg, "Nesting error: bar vs. foo", "Error is generated");
|
||||
}
|
||||
|
||||
function testBasicOutput() {
|
||||
var text = "test";
|
||||
var t = Hogan.compile(text);
|
||||
is(t.render(), text, "template renders one text node");
|
||||
}
|
||||
|
||||
function testBasicOutputAsString() {
|
||||
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() {
|
||||
var text = "test {{foo}} test";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo:'bar'});
|
||||
is(s, "test bar test", "basic variable substitution works.");
|
||||
}
|
||||
|
||||
function testOneVariableAsString() {
|
||||
var text = "test {{foo}} test";
|
||||
var funcText = Hogan.compile(text, true);
|
||||
is(funcText, "function(context, partials){this.buffer.push('test ');\nthis.buffer.push(this.find('foo', context));\nthis.buffer.push(' test');};",
|
||||
"Function text is correct with variable substitution.");
|
||||
}
|
||||
|
||||
function testRenderWithWhitespace() {
|
||||
var text = "{{ string }}";
|
||||
var t = Hogan.compile(text);
|
||||
is(t.render({string: "---" }), "---", "tags with whitespace render correctly.");
|
||||
}
|
||||
|
||||
function testRenderWithWhitespaceAroundTripleStache() {
|
||||
var text = " {{{string}}}\n";
|
||||
var t = Hogan.compile(text);
|
||||
is(t.render({string: "---" }), " ---\n", "triple stache surrounded by whitespace render correctly.");
|
||||
}
|
||||
|
||||
function testRenderWithWhitespaceAroundAmpersand() {
|
||||
var text = " {{& string }}\n";
|
||||
var t = Hogan.compile(text);
|
||||
is(t.render({string: "---" }), " ---\n", "ampersand surrounded by whitespace render correctly.");
|
||||
}
|
||||
|
||||
function testMultipleVariables() {
|
||||
var text = "test {{foo}} test {{bar}} test {{baz}} test {{foo}} test";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo:'42', bar: '43', baz: '44'});
|
||||
is(s, "test 42 test 43 test 44 test 42 test", "all variables render correctly.");
|
||||
}
|
||||
|
||||
function testNumberValues() {
|
||||
var text = "integer: {{foo}} float: {{bar}} negative: {{baz}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo: 42, bar: 42.42, baz: -42});
|
||||
is(s, "integer: 42 float: 42.42 negative: -42", "numbers render correctly");
|
||||
}
|
||||
|
||||
function testObjectRender() {
|
||||
var text = "object: {{foo}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo: {}});
|
||||
is(s, "object: [object Object]", "objects render default toString.");
|
||||
}
|
||||
|
||||
function testObjectToStringRender() {
|
||||
var text = "object: {{foo}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo: {toString: function(){ return "yo!"}}});
|
||||
is(s, "object: yo!", "objects render supplied toString.");
|
||||
}
|
||||
|
||||
function testArrayRender() {
|
||||
var text = "array: {{foo}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo: ["a","b","c"]});
|
||||
is(s, "array: a,b,c", "arrays render default toString.");
|
||||
}
|
||||
|
||||
function testEscaping() {
|
||||
var text = "{{foo}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render();
|
||||
var s = t.render({foo: "< > <div> \' \" &"});
|
||||
is(s, "< > <div> ' " &", "input correctly escaped.");
|
||||
|
||||
var ec ={ "'": "'", '"': """, "<": "<", ">": ">", "&": "&"}
|
||||
for (var char in ec) {
|
||||
var s = t.render({foo: char + " just me"});
|
||||
is(s, ec[char] + " just me", "input correctly escaped.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function testMustacheInjection() {
|
||||
var text = "{{foo}}";
|
||||
var t = Hogan.compile(text);
|
||||
s = t.render({foo:"{{{<42}}}"})
|
||||
is(s, "{{{<42}}}", "Can't inject mustache");
|
||||
}
|
||||
|
||||
function testTripleStache() {
|
||||
var text = "{{{foo}}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo: "< > <div> \' \" &"});
|
||||
is(s, "< > <div> \' \" &", "input correctly not-escaped.");
|
||||
}
|
||||
|
||||
function testAmpNoEscaping() {
|
||||
var text = "{{&foo}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo: "< > <div> \' \" &"});
|
||||
is(s, "< > <div> \' \" &", "input correctly not-escaped.");
|
||||
}
|
||||
|
||||
function testPartial() {
|
||||
var partialText = "this is text from the partial--the magic number {{foo}} is from a variable";
|
||||
var p = Hogan.compile(partialText);
|
||||
|
||||
var text = "This template contains a partial ({{>testPartial}})."
|
||||
var t = Hogan.compile(text);
|
||||
|
||||
var s = t.render({foo: 42}, {testPartial: p});
|
||||
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() {
|
||||
var partialText = "this is text from the partial--the magic number {{foo}} is from a variable";
|
||||
var p = Hogan.compile(partialText);
|
||||
|
||||
var partialText2 = "This template contains a partial ({{>testPartial}})."
|
||||
var p2 = Hogan.compile(partialText2);
|
||||
|
||||
var text = "This template contains a partial that contains a partial [{{>testPartial2}}]."
|
||||
var t = Hogan.compile(text);
|
||||
|
||||
var s = t.render({foo: 42}, {testPartial: p, testPartial2: p2});
|
||||
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() {
|
||||
var text = "This template {{^foo}}BOO {{/foo}}contains an inverted section."
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render();
|
||||
is(s, "This template BOO contains an inverted section.", "inverted sections with no context work");
|
||||
|
||||
s = t.render({foo:[]});
|
||||
is(s, "This template BOO contains an inverted section.", "inverted sections with empty list context work");
|
||||
|
||||
s = t.render({ foo:false });
|
||||
is(s, "This template BOO contains an inverted section.", "inverted sections with false context work");
|
||||
|
||||
s = t.render({foo:''});
|
||||
is(s, "This template contains an inverted section.", "inverted sections with empty string context work");
|
||||
|
||||
s = t.render({foo:true});
|
||||
is(s, "This template contains an inverted section.", "inverted sections with true context work");
|
||||
|
||||
s = t.render({foo: function() { return false; }});
|
||||
is(s, "This template BOO contains an inverted section.", "inverted sections with false returning method in context work");
|
||||
}
|
||||
|
||||
function testSectionElision() {
|
||||
var text = "This template {{#foo}}BOO {{/foo}}contains a section."
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render();
|
||||
is(s, "This template contains a section.", "sections with no context work");
|
||||
|
||||
s = t.render({foo:[]});
|
||||
is(s, "This template contains a section.", "sections with empty list context work");
|
||||
|
||||
s = t.render({foo:false});
|
||||
is(s, "This template contains a section.", "sections with false context work");
|
||||
}
|
||||
|
||||
function testSectionObjectContext() {
|
||||
var text = "This template {{#foo}}{{bar}} {{/foo}}contains a section."
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo:{bar:42}});
|
||||
is(s, "This template 42 contains a section.", "sections with object context work");
|
||||
}
|
||||
|
||||
function testSectionArrayContext() {
|
||||
var text = "This template {{#foo}}{{bar}} {{/foo}}contains a section."
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo:[{bar:42}, {bar:43}, {bar:44}]});
|
||||
is(s, "This template 42 43 44 contains a section.", "sections with object ctx and array values work");
|
||||
}
|
||||
|
||||
function testFalsyVariableNoRender() {
|
||||
var text = "I ({{cannot}}) be seen!";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render();
|
||||
is(s, "I () be seen!", "missing value doesn't render.");
|
||||
}
|
||||
|
||||
function testSectionExtensions() {
|
||||
var text = "Test {{_//|__foo}}bar{{/foo}}";
|
||||
var options = {sectionTags:[{o:'_//|__foo', c:'foo'}]};
|
||||
var tree = Hogan.parse(Hogan.scan(text), options);
|
||||
is(tree[1].tag, "#", "_//|__foo node transformed to section");
|
||||
is(tree[1].n, "_//|__foo", "_//|__foo node transformed to section");
|
||||
|
||||
var t = Hogan.compile(text, options );
|
||||
var s = t.render({'_//|__foo':true});
|
||||
is(s, "Test bar", "Custom sections work");
|
||||
}
|
||||
|
||||
function testMisnestedSectionExtensions() {
|
||||
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;
|
||||
}
|
||||
is(msg, "Nesting error: __foo vs. bar", "Error is generated");
|
||||
}
|
||||
|
||||
function testNestedSection() {
|
||||
var text = "{{#foo}}{{#bar}}{{baz}}{{/bar}}{{/foo}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo: 42, bar: 42, baz:42});
|
||||
is(s, "42", "can reach up context stack");
|
||||
}
|
||||
|
||||
function testDottedNames() {
|
||||
var text = '"{{person.name}}" == "{{#person}}{{name}}{{/person}}"';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({person:{name:'Joe'}});
|
||||
is(s, '"Joe" == "Joe"', "dotted names work");
|
||||
}
|
||||
|
||||
function testImplicitIterator() {
|
||||
var text = '{{#stuff}} {{.}} {{/stuff}}';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({stuff:[42,43,44]});
|
||||
is(s, " 42 43 44 ", "implicit iterators work");
|
||||
}
|
||||
|
||||
function testPartialsAndDelimiters() {
|
||||
var text = '{{>include}}*\n{{= | | =}}\n*|>include|';
|
||||
var partialText = ' .{{value}}. ';
|
||||
var partial = Hogan.compile(partialText);
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({value:"yes"}, {'include':partial});
|
||||
is(s, " .yes. *\n* .yes. ", "partials work around delimiters");
|
||||
}
|
||||
|
||||
function testStringPartials() {
|
||||
var text = "foo{{>mypartial}}baz";
|
||||
var partialText = " bar ";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({}, {'mypartial': partialText});
|
||||
is(s, "foo bar baz", "string partial works.");
|
||||
}
|
||||
|
||||
function testMissingPartials() {
|
||||
var text = "foo{{>mypartial}} bar";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({});
|
||||
is(s, "foo bar", "missing partial works.");
|
||||
}
|
||||
|
||||
function testIndentedStandaloneComment() {
|
||||
var text = 'Begin.\n {{! Indented Comment Block! }}\nEnd.';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render();
|
||||
is(s, 'Begin.\nEnd.', "Standalone comment blocks are removed.");
|
||||
}
|
||||
|
||||
function testNewLineBetweenDelimiterChanges() {
|
||||
var data = { section: true, data: 'I got interpolated.' };
|
||||
var text = '\n{{#section}}\n {{data}}\n |data|\n{{/section}}x\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render(data);
|
||||
is(s, '\n I got interpolated.\n |data|\nx\n\n {{data}}\n I got interpolated.\n', 'render correct')
|
||||
}
|
||||
|
||||
function testMustacheJSApostrophe() {
|
||||
var text = '{{apos}}{{control}}';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({'apos':"'", 'control':"X"});
|
||||
is(s, ''X', 'Apostrophe is escaped.');
|
||||
}
|
||||
|
||||
function testMustacheJSArrayOfImplicitPartials() {
|
||||
var text = 'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}\n';
|
||||
var partialText = '{{.}}\n';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({numbers:[1,2,3,4]}, {partial: partialText});
|
||||
is(s, 'Here is some stuff!\n1\n2\n3\n4\n', 'Partials with implicit iterators work.');
|
||||
}
|
||||
|
||||
function testMustacheJSArrayOfPartials() {
|
||||
var text = 'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}\n';
|
||||
var partialText = '{{i}}\n';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({numbers:[{i:1},{i:2},{i:3},{i:4}]}, {partial: partialText});
|
||||
is(s, 'Here is some stuff!\n1\n2\n3\n4\n', 'Partials with arrays work.');
|
||||
}
|
||||
|
||||
function testMustacheJSArrayOfStrings() {
|
||||
var text = '{{#strings}}{{.}} {{/strings}}';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({strings:['foo', 'bar', 'baz']});
|
||||
is(s, 'foo bar baz ', 'array of strings works with implicit iterators.');
|
||||
}
|
||||
|
||||
function testMustacheJSUndefinedString() {
|
||||
var text = 'foo{{bar}}baz';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({bar:undefined});
|
||||
is(s, 'foobaz', 'undefined value does not render.');
|
||||
}
|
||||
|
||||
function testMustacheJSTripleStacheAltDelimiter() {
|
||||
var text = '{{=<% %>=}}<% foo %> {{foo}} <%{bar}%> {{{bar}}}';
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({foo:'yeah', bar:'hmm'});
|
||||
is(s, 'yeah {{foo}} hmm {{{bar}}}', 'triple stache inside alternate delimiter works.');
|
||||
}
|
||||
|
||||
/* shootout benchmark tests */
|
||||
|
||||
function testShootOutString() {
|
||||
var text = "Hello World!";
|
||||
var expected = "Hello World!"
|
||||
var t = Hogan.compile(text)
|
||||
var s = t.render({})
|
||||
is(s, expected, "Shootout String compiled correctly");
|
||||
}
|
||||
|
||||
function testShootOutReplace() {
|
||||
var text = "Hello {{name}}! You have {{count}} new messages.";
|
||||
var expected = "Hello Mick! You have 30 new messages.";
|
||||
var t = Hogan.compile(text)
|
||||
var s = t.render({ name: "Mick", count: 30 })
|
||||
is(s, expected, "Shootout Replace compiled correctly");
|
||||
}
|
||||
|
||||
function testShootOutArray() {
|
||||
var text = "{{#names}}{{name}}{{/names}}";
|
||||
var expected = "MoeLarryCurlyShemp";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({ names: [{name: "Moe"}, {name: "Larry"}, {name: "Curly"}, {name: "Shemp"}] })
|
||||
is(s, expected, "Shootout Array compiled correctly");
|
||||
}
|
||||
|
||||
function testShootOutObject() {
|
||||
var text = "{{#person}}{{name}}{{age}}{{/person}}";
|
||||
var expected = "Larry45";
|
||||
var t = Hogan.compile(text)
|
||||
var s = t.render({ person: { name: "Larry", age: 45 } })
|
||||
is(s, expected, "Shootout Object compiled correctly");
|
||||
}
|
||||
|
||||
function testShootOutPartial() {
|
||||
var text = "{{#peeps}}{{>replace}}{{/peeps}}";
|
||||
var t = Hogan.compile(text);
|
||||
var partial = Hogan.compile(" Hello {{name}}! You have {{count}} new messages.");
|
||||
var s = t.render({ peeps: [{name: "Moe", count: 15}, {name: "Larry", count: 5}, {name: "Curly", count: 2}] }, { replace: partial });
|
||||
var expected = " Hello Moe! You have 15 new messages. Hello Larry! You have 5 new messages. Hello Curly! You have 2 new messages.";
|
||||
is(s, expected, "Shootout Partial compiled correctly");
|
||||
}
|
||||
|
||||
function testShootOutRecurse() {
|
||||
var text = "{{name}}{{#kids}}{{>recursion}}{{/kids}}";
|
||||
var t = Hogan.compile(text);
|
||||
var partial = Hogan.compile("{{name}}{{#kids}}{{>recursion}}{{/kids}}");
|
||||
var s = t.render({
|
||||
name: '1',
|
||||
kids: [
|
||||
{
|
||||
name: '1.1',
|
||||
kids: [
|
||||
{ name: '1.1.1', kids: [] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}, { recursion: partial });
|
||||
var expected = "11.11.1.1";
|
||||
is(s, expected, "Shootout Recurse compiled correctly");
|
||||
}
|
||||
|
||||
function testShootOutFilter() {
|
||||
var text = "{{#filter}}foo {{bar}}{{/filter}}";
|
||||
var t = Hogan.compile(text);
|
||||
var s = t.render({
|
||||
filter: function() {
|
||||
return function(text, render) {
|
||||
return render(text).toUpperCase();
|
||||
}
|
||||
},
|
||||
bar: "bar"
|
||||
});
|
||||
var expected = "FOO BAR"
|
||||
is(s, expected, "Shootout Filter compiled correctly");
|
||||
}
|
||||
|
||||
function testShootOutComplex() {
|
||||
var text =
|
||||
"<h1>{{header}}</h1>" +
|
||||
"{{#hasItems}}" +
|
||||
"<ul>" +
|
||||
"{{#items}}" +
|
||||
"{{#current}}" +
|
||||
"<li><strong>{{name}}</strong></li>" +
|
||||
"{{/current}}" +
|
||||
"{{^current}}" +
|
||||
"<li><a href=\"{{url}}\">{{name}}</a></li>" +
|
||||
"{{/current}}" +
|
||||
"{{/items}}" +
|
||||
"</ul>" +
|
||||
"{{/hasItems}}" +
|
||||
"{{^hasItems}}" +
|
||||
"<p>The list is empty.</p>" +
|
||||
"{{/hasItems}}";
|
||||
|
||||
var expected = "<h1>Colors</h1><ul><li><strong>red</strong></li><li><a href=\"#Green\">green</a></li><li><a href=\"#Blue\">blue</a></li></ul>";
|
||||
var t = Hogan.compile(text)
|
||||
var s = t.render({
|
||||
header: function() {
|
||||
return "Colors";
|
||||
},
|
||||
items: [
|
||||
{name: "red", current: true, url: "#Red"},
|
||||
{name: "green", current: false, url: "#Green"},
|
||||
{name: "blue", current: false, url: "#Blue"}
|
||||
],
|
||||
hasItems: function() {
|
||||
return this.items.length !== 0;
|
||||
},
|
||||
empty: function() {
|
||||
return this.items.length === 0;
|
||||
}
|
||||
})
|
||||
|
||||
is(s, expected, "Shootout Complex compiled correctly");
|
||||
}
|
||||
|
||||
function testRenderOutput() {
|
||||
if (doc) return
|
||||
var fs = require('fs');
|
||||
var inPath = 'test/templates';
|
||||
var outPath = 'test/html';
|
||||
|
||||
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() {
|
||||
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();
|
||||
}
|
90
docs/build/node_modules/hogan.js/test/mustache.js
generated
vendored
Normal file
90
docs/build/node_modules/hogan.js/test/mustache.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2011 Twitter, Inc.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var doc = this['document'];
|
||||
var fs = require('fs');
|
||||
|
||||
var passed = 0;
|
||||
var failed = 0;
|
||||
|
||||
if (!this['output']) {
|
||||
var output = function (string) {
|
||||
return doc ? doc.write(string + '<br/>') : console.log(string);
|
||||
};
|
||||
}
|
||||
|
||||
var Hogan = require(__dirname + '/../lib/hogan');
|
||||
var template = fs.readFileSync(__dirname + '/../lib/template.js').toString();
|
||||
var compiler = fs.readFileSync(__dirname + '/../lib/compiler.js').toString();
|
||||
var mustache_wrapper = fs.readFileSync(__dirname + '/../wrappers/mustache.js.mustache').toString();
|
||||
|
||||
// Create a Mustache.js emulator from the distribution template
|
||||
var engines = (new Function(Hogan.compile(mustache_wrapper).render({template: template, compiler: compiler}) +
|
||||
'; return {Hogan: Hogan, Mustache: Mustache};'))();
|
||||
|
||||
var Mustache = engines.Mustache;
|
||||
var Hogan2 = engines.Hogan;
|
||||
|
||||
|
||||
// sanity check
|
||||
is(Mustache.hasOwnProperty('to_html'), true, 'Mustache has to_html method.');
|
||||
|
||||
// Check for Mustache.js partial resolution behavior.
|
||||
var context = {
|
||||
foo: 'bar',
|
||||
mypartial: {
|
||||
baz: 'qux'
|
||||
}
|
||||
}
|
||||
var text = 'abc {{foo}} def {{>mypartial}} ghi';
|
||||
var partialText = '{{baz}}';
|
||||
var s = Mustache.to_html(text, context, {'mypartial': partialText});
|
||||
is(s, 'abc bar def qux ghi', 'Correct emulation of Mustache.js partial-name-in-context resolution.');
|
||||
|
||||
// Now check to see that the Hogan resolution is unaffected.
|
||||
var t = Hogan2.compile(text);
|
||||
s = t.render(context, {'mypartial': partialText});
|
||||
is(s, 'abc bar def ghi', 'Hogan behavior not changed by Mustache.js emulation.');
|
||||
|
||||
// Check for sendFun behavior
|
||||
var buf = "";
|
||||
function send(s) {
|
||||
buf += "-FOO " + s + " FOO-";
|
||||
}
|
||||
var s = Mustache.to_html(text, context, {'mypartial': partialText}, send);
|
||||
is(buf, '-FOO abc bar def qux ghi FOO-', 'Correct emulation of Mustache.js sendFun.');
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
complete();
|
77
docs/build/node_modules/hogan.js/test/spec.js
generated
vendored
Normal file
77
docs/build/node_modules/hogan.js/test/spec.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2011 Twitter, Inc.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var Hogan = Hogan || require('../lib/hogan');
|
||||
var doc = this["document"];
|
||||
var fs = require('fs');
|
||||
|
||||
var passed = 0;
|
||||
var failed = 0;
|
||||
|
||||
if (!this["output"]) {
|
||||
var output = function (string) {
|
||||
return doc ? doc.write(string + '<br/>') : console.log(string);
|
||||
};
|
||||
}
|
||||
|
||||
function runTest(tests) {
|
||||
tests.forEach(function(test) {
|
||||
var partials = {};
|
||||
for (var i in test.partials) {
|
||||
partials[i] = Hogan.compile(test.partials[i]);
|
||||
}
|
||||
var t = Hogan.compile(test.template);
|
||||
|
||||
if (test.data.lambda) {
|
||||
var func = (new Function ('return ' + test.data.lambda.js)());
|
||||
test.data.lambda = function() { return func; };
|
||||
}
|
||||
|
||||
var s = t.render(test.data, partials);
|
||||
is(s, test.expected, test.name + ': ' + test.desc);
|
||||
});
|
||||
}
|
||||
|
||||
var testDir = './test/spec/specs';
|
||||
var files = fs.readdirSync(testDir)
|
||||
.filter(function(f) { return f.indexOf('.json') > 0; })
|
||||
.map(function(f) { return testDir + '/' + f});
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var test = JSON.parse(fs.readFileSync(files[i]).toString());
|
||||
runTest(test.tests);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
complete();
|
31
docs/build/node_modules/hogan.js/test/spec/Changes
generated
vendored
Normal file
31
docs/build/node_modules/hogan.js/test/spec/Changes
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
2011-03-20: v1.1.2
|
||||
Added tests for standalone tags at string boundaries.
|
||||
Added tests for rendering lambda returns after delimiter changes.
|
||||
|
||||
2011-03-20: v1.0.3
|
||||
Added tests for standalone tags at string boundaries.
|
||||
Added tests for rendering lambda returns after delimiter changes.
|
||||
|
||||
2011-03-05: v1.1.1
|
||||
Added tests for indented inline sections.
|
||||
Added tests for Windows-style newlines.
|
||||
|
||||
2011-03-05: v1.0.2
|
||||
Added tests for indented inline sections.
|
||||
Added tests for Windows-style newlines.
|
||||
|
||||
2011-03-04: v1.1.0
|
||||
Implicit iterators.
|
||||
A single period (`.`) may now be used as a name in Interpolation tags,
|
||||
which represents the top of stack (cast as a String).
|
||||
Dotted names.
|
||||
Names containing one or more periods should be resolved as chained
|
||||
properties; naïvely, this is like nesting section tags, but with some
|
||||
built-in scoping protections.
|
||||
|
||||
2011-03-02: v1.0.1
|
||||
Clarifying a point in the README about version compliance.
|
||||
Adding high-level documentation to each spec file.
|
||||
|
||||
2011-02-28: v1.0.0
|
||||
Initial Release
|
65
docs/build/node_modules/hogan.js/test/spec/README.md
generated
vendored
Normal file
65
docs/build/node_modules/hogan.js/test/spec/README.md
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
The repository at https://github.com/mustache/spec is the formal standard for
|
||||
Mustache. It defines both normal usage and edge-case behavior for libraries
|
||||
parsing the Mustache templating language (or a superset thereof).
|
||||
|
||||
The specification is developed as a series of YAML files, under the `specs`
|
||||
directory.
|
||||
|
||||
Versioning
|
||||
----------
|
||||
This specification is being [semantically versioned](http://semver.org).
|
||||
Roughly described, major version changes will always represent backwards
|
||||
incompatible changes, minor version changes will always represent new language
|
||||
features and will be backwards compatible, and patch ('tiny') version changes
|
||||
will always be bug fixes. For the purposes of semantic versioning, the public
|
||||
API is the contents of the `specs` directory and the algorithm for testing
|
||||
against it.
|
||||
|
||||
Mustache implementations SHOULD report the most recent version of the spec
|
||||
(major and minor version numbers). If an implementation has support for any
|
||||
optional modules, they SHOULD indicate so with a remark attached to the
|
||||
version number (e.g. "vX.Y, including lambdas" or "v.X.Y+λ"). It is
|
||||
RECOMMENDED that implementations not supporting at least v1.0.0 of this spec
|
||||
refer to themselves as "Mustache-like", or "Mustache-inspired".
|
||||
|
||||
Alternate Formats
|
||||
-----------------
|
||||
|
||||
Since YAML is a reasonably complex format that not every language has good
|
||||
tools for working with, we also provide JSON versions of the specs on a
|
||||
best-effort basis.
|
||||
|
||||
These should be identical to the YAML specifications, but if you find the need
|
||||
to regenerate them, they can be trivially rebuilt by invoking `rake build`.
|
||||
|
||||
It is also worth noting that some specifications (notably, the lambda module)
|
||||
rely on YAML "tags" to denote special types of data (e.g. source code). Since
|
||||
JSON offers no way to denote this, a special key ("`__tag__`") is injected
|
||||
with the name of the tag as its value. See `TESTING.md` for more information
|
||||
about handling tagged data.
|
||||
|
||||
Optional Modules
|
||||
----------------
|
||||
|
||||
Specification files beginning with a tilde (`~`) describe optional modules.
|
||||
At present, the only module being described as optional is regarding support
|
||||
for lambdas. As a guideline, a module may be a candidate for optionality
|
||||
when:
|
||||
|
||||
* It does not affect the core syntax of the language.
|
||||
* It does not significantly affect the output of rendered templates.
|
||||
* It concerns implementation language features or data types that are not
|
||||
common to or core in every targeted language.
|
||||
* The lack of support by an implementation does not diminish the usage of
|
||||
Mustache in the target language.
|
||||
|
||||
As an example, the lambda module is primarily concerned with the handling of a
|
||||
particular data type (code). This is a type of data that may be difficult to
|
||||
support in some languages, and users of those languages will not see the lack
|
||||
as an 'inconsistency' between implementations.
|
||||
|
||||
Support for specific pragmas or syntax extensions, however, are best managed
|
||||
outside this core specification, as adjunct specifications.
|
||||
|
||||
Implementors are strongly encouraged to support any and all modules they are
|
||||
reasonably capable of supporting.
|
27
docs/build/node_modules/hogan.js/test/spec/Rakefile
generated
vendored
Normal file
27
docs/build/node_modules/hogan.js/test/spec/Rakefile
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'json'
|
||||
require 'yaml'
|
||||
|
||||
# Our custom YAML tags must retain their magic.
|
||||
%w[ code ].each do |tag|
|
||||
YAML::add_builtin_type(tag) { |_,val| val.merge(:__tag__ => tag) }
|
||||
end
|
||||
|
||||
desc 'Build all alternate versions of the specs.'
|
||||
multitask :build => [ 'build:json' ]
|
||||
|
||||
namespace :build do
|
||||
note = 'Do not edit this file; changes belong in the appropriate YAML file.'
|
||||
|
||||
desc 'Build JSON versions of the specs.'
|
||||
task :json do
|
||||
rm(Dir['specs/*.json'], :verbose => false)
|
||||
Dir.glob('specs/*.yml').each do |filename|
|
||||
json_file = filename.gsub('.yml', '.json')
|
||||
|
||||
File.open(json_file, 'w') do |file|
|
||||
doc = YAML.load_file(filename)
|
||||
file << doc.merge(:__ATTN__ => note).to_json()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
46
docs/build/node_modules/hogan.js/test/spec/TESTING.md
generated
vendored
Normal file
46
docs/build/node_modules/hogan.js/test/spec/TESTING.md
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
Testing your Mustache implementation against this specification should be
|
||||
relatively simple. If you have a readily available testing framework on your
|
||||
platform, your task may be even simpler.
|
||||
|
||||
In general, the process for each `.yml` file is as follows:
|
||||
|
||||
1. Use a YAML parser to load the file.
|
||||
|
||||
2. For each test in the 'tests' array:
|
||||
|
||||
1. Ensure that each element of the 'partials' hash (if it exists) is
|
||||
stored in a place where the interpreter will look for it.
|
||||
|
||||
2. If your implementation will not support lambdas, feel free to skip over
|
||||
the optional '~lambdas.yml' file.
|
||||
|
||||
2.1. If your implementation will support lambdas, ensure that each member of
|
||||
'data' tagged with '!code' is properly processed into a language-
|
||||
specific lambda reference.
|
||||
|
||||
* e.g. Given this YAML data hash:
|
||||
|
||||
`{ x: !code { ruby: 'proc { "x" }', perl: 'sub { "x" }' } }`
|
||||
|
||||
a Ruby-based Mustache implementation would process it such that it
|
||||
was equivalent to this Ruby hash:
|
||||
|
||||
`{ 'x' => proc { "x" } }`
|
||||
|
||||
* If your implementation language does not currently have lambda
|
||||
examples in the spec, feel free to implement them and send a pull
|
||||
request.
|
||||
|
||||
* The JSON version of the spec represents these tagged values as a hash
|
||||
with a '`__tag__`' key of 'code'.
|
||||
|
||||
3. Render the template (stored in the 'template' key) with the given 'data'
|
||||
hash.
|
||||
|
||||
4. Compare the results of your rendering against the 'expected' value; any
|
||||
differences should be reported, along with any useful debugging
|
||||
information.
|
||||
|
||||
* Of note, the 'desc' key contains a rough one-line description of the
|
||||
behavior being tested -- this is most useful in conjunction with the
|
||||
file name and test 'name'.
|
1
docs/build/node_modules/hogan.js/test/spec/specs/comments.json
generated
vendored
Normal file
1
docs/build/node_modules/hogan.js/test/spec/specs/comments.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Comment tags represent content that should never appear in the resulting\noutput.\n\nThe tag's content may contain any substring (including newlines) EXCEPT the\nclosing delimiter.\n\nComment tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Inline","data":{},"expected":"1234567890","template":"12345{{! Comment Block! }}67890","desc":"Comment blocks should be removed from the template."},{"name":"Multiline","data":{},"expected":"1234567890\n","template":"12345{{!\n This is a\n multi-line comment...\n}}67890\n","desc":"Multiline comments should be permitted."},{"name":"Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{! Comment Block! }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{! Indented Comment Block! }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n|","template":"|\r\n{{! Standalone Comment }}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{},"expected":"!","template":" {{! I'm Still Standalone }}\n!","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{},"expected":"!\n","template":"!\n {{! I'm Still Standalone }}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Multiline Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{!\nSomething's going on here...\n}}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Multiline Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{!\n Something's going on here...\n }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Inline","data":{},"expected":" 12 \n","template":" 12 {{! 34 }}\n","desc":"Inline comments should not strip whitespace"},{"name":"Surrounding Whitespace","data":{},"expected":"12345 67890","template":"12345 {{! Comment Block! }} 67890","desc":"Comment removal should preserve surrounding whitespace."}]}
|
103
docs/build/node_modules/hogan.js/test/spec/specs/comments.yml
generated
vendored
Normal file
103
docs/build/node_modules/hogan.js/test/spec/specs/comments.yml
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
overview: |
|
||||
Comment tags represent content that should never appear in the resulting
|
||||
output.
|
||||
|
||||
The tag's content may contain any substring (including newlines) EXCEPT the
|
||||
closing delimiter.
|
||||
|
||||
Comment tags SHOULD be treated as standalone when appropriate.
|
||||
tests:
|
||||
- name: Inline
|
||||
desc: Comment blocks should be removed from the template.
|
||||
data: { }
|
||||
template: '12345{{! Comment Block! }}67890'
|
||||
expected: '1234567890'
|
||||
|
||||
- name: Multiline
|
||||
desc: Multiline comments should be permitted.
|
||||
data: { }
|
||||
template: |
|
||||
12345{{!
|
||||
This is a
|
||||
multi-line comment...
|
||||
}}67890
|
||||
expected: |
|
||||
1234567890
|
||||
|
||||
- name: Standalone
|
||||
desc: All standalone comment lines should be removed.
|
||||
data: { }
|
||||
template: |
|
||||
Begin.
|
||||
{{! Comment Block! }}
|
||||
End.
|
||||
expected: |
|
||||
Begin.
|
||||
End.
|
||||
|
||||
- name: Indented Standalone
|
||||
desc: All standalone comment lines should be removed.
|
||||
data: { }
|
||||
template: |
|
||||
Begin.
|
||||
{{! Indented Comment Block! }}
|
||||
End.
|
||||
expected: |
|
||||
Begin.
|
||||
End.
|
||||
|
||||
- name: Standalone Line Endings
|
||||
desc: '"\r\n" should be considered a newline for standalone tags.'
|
||||
data: { }
|
||||
template: "|\r\n{{! Standalone Comment }}\r\n|"
|
||||
expected: "|\r\n|"
|
||||
|
||||
- name: Standalone Without Previous Line
|
||||
desc: Standalone tags should not require a newline to precede them.
|
||||
data: { }
|
||||
template: " {{! I'm Still Standalone }}\n!"
|
||||
expected: "!"
|
||||
|
||||
- name: Standalone Without Newline
|
||||
desc: Standalone tags should not require a newline to follow them.
|
||||
data: { }
|
||||
template: "!\n {{! I'm Still Standalone }}"
|
||||
expected: "!\n"
|
||||
|
||||
- name: Multiline Standalone
|
||||
desc: All standalone comment lines should be removed.
|
||||
data: { }
|
||||
template: |
|
||||
Begin.
|
||||
{{!
|
||||
Something's going on here...
|
||||
}}
|
||||
End.
|
||||
expected: |
|
||||
Begin.
|
||||
End.
|
||||
|
||||
- name: Indented Multiline Standalone
|
||||
desc: All standalone comment lines should be removed.
|
||||
data: { }
|
||||
template: |
|
||||
Begin.
|
||||
{{!
|
||||
Something's going on here...
|
||||
}}
|
||||
End.
|
||||
expected: |
|
||||
Begin.
|
||||
End.
|
||||
|
||||
- name: Indented Inline
|
||||
desc: Inline comments should not strip whitespace
|
||||
data: { }
|
||||
template: " 12 {{! 34 }}\n"
|
||||
expected: " 12 \n"
|
||||
|
||||
- name: Surrounding Whitespace
|
||||
desc: Comment removal should preserve surrounding whitespace.
|
||||
data: { }
|
||||
template: '12345 {{! Comment Block! }} 67890'
|
||||
expected: '12345 67890'
|
1
docs/build/node_modules/hogan.js/test/spec/specs/delimiters.json
generated
vendored
Normal file
1
docs/build/node_modules/hogan.js/test/spec/specs/delimiters.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Set Delimiter tags are used to change the tag delimiters for all content\nfollowing the tag in the current compilation unit.\n\nThe tag's content MUST be any two non-whitespace sequences (separated by\nwhitespace) EXCEPT an equals sign ('=') followed by the current closing\ndelimiter.\n\nSet Delimiter tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Pair Behavior","data":{"text":"Hey!"},"expected":"(Hey!)","template":"{{=<% %>=}}(<%text%>)","desc":"The equals sign (used on both sides) should permit delimiter changes."},{"name":"Special Characters","data":{"text":"It worked!"},"expected":"(It worked!)","template":"({{=[ ]=}}[text])","desc":"Characters with special meaning regexen should be valid delimiters."},{"name":"Sections","data":{"section":true,"data":"I got interpolated."},"expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n","template":"[\n{{#section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|\n]\n","desc":"Delimiters set outside sections should persist."},{"name":"Inverted Sections","data":{"section":false,"data":"I got interpolated."},"expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n","template":"[\n{{^section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|^section|\n {{data}}\n |data|\n|/section|\n]\n","desc":"Delimiters set outside inverted sections should persist."},{"name":"Partial Inheritence","data":{"value":"yes"},"expected":"[ .yes. ]\n[ .yes. ]\n","template":"[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n","desc":"Delimiters set in a parent template should not affect a partial.","partials":{"include":".{{value}}."}},{"name":"Post-Partial Behavior","data":{"value":"yes"},"expected":"[ .yes. .yes. ]\n[ .yes. .|value|. ]\n","template":"[ {{>include}} ]\n[ .{{value}}. .|value|. ]\n","desc":"Delimiters set in a partial should not affect the parent template.","partials":{"include":".{{value}}. {{= | | =}} .|value|."}},{"name":"Surrounding Whitespace","data":{},"expected":"| |","template":"| {{=@ @=}} |","desc":"Surrounding whitespace should be left untouched."},{"name":"Outlying Whitespace (Inline)","data":{},"expected":" | \n","template":" | {{=@ @=}}\n","desc":"Whitespace should be left untouched."},{"name":"Standalone Tag","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{=@ @=}}\nEnd.\n","desc":"Standalone lines should be removed from the template."},{"name":"Indented Standalone Tag","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{=@ @=}}\nEnd.\n","desc":"Indented standalone lines should be removed from the template."},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n|","template":"|\r\n{{= @ @ =}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{},"expected":"=","template":" {{=@ @=}}\n=","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{},"expected":"=\n","template":"=\n {{=@ @=}}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Pair with Padding","data":{},"expected":"||","template":"|{{= @ @ =}}|","desc":"Superfluous in-tag whitespace should be ignored."}]}
|
158
docs/build/node_modules/hogan.js/test/spec/specs/delimiters.yml
generated
vendored
Normal file
158
docs/build/node_modules/hogan.js/test/spec/specs/delimiters.yml
generated
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
overview: |
|
||||
Set Delimiter tags are used to change the tag delimiters for all content
|
||||
following the tag in the current compilation unit.
|
||||
|
||||
The tag's content MUST be any two non-whitespace sequences (separated by
|
||||
whitespace) EXCEPT an equals sign ('=') followed by the current closing
|
||||
delimiter.
|
||||
|
||||
Set Delimiter tags SHOULD be treated as standalone when appropriate.
|
||||
tests:
|
||||
- name: Pair Behavior
|
||||
desc: The equals sign (used on both sides) should permit delimiter changes.
|
||||
data: { text: 'Hey!' }
|
||||
template: '{{=<% %>=}}(<%text%>)'
|
||||
expected: '(Hey!)'
|
||||
|
||||
- name: Special Characters
|
||||
desc: Characters with special meaning regexen should be valid delimiters.
|
||||
data: { text: 'It worked!' }
|
||||
template: '({{=[ ]=}}[text])'
|
||||
expected: '(It worked!)'
|
||||
|
||||
- name: Sections
|
||||
desc: Delimiters set outside sections should persist.
|
||||
data: { section: true, data: 'I got interpolated.' }
|
||||
template: |
|
||||
[
|
||||
{{#section}}
|
||||
{{data}}
|
||||
|data|
|
||||
{{/section}}
|
||||
|
||||
{{= | | =}}
|
||||
|#section|
|
||||
{{data}}
|
||||
|data|
|
||||
|/section|
|
||||
]
|
||||
expected: |
|
||||
[
|
||||
I got interpolated.
|
||||
|data|
|
||||
|
||||
{{data}}
|
||||
I got interpolated.
|
||||
]
|
||||
|
||||
- name: Inverted Sections
|
||||
desc: Delimiters set outside inverted sections should persist.
|
||||
data: { section: false, data: 'I got interpolated.' }
|
||||
template: |
|
||||
[
|
||||
{{^section}}
|
||||
{{data}}
|
||||
|data|
|
||||
{{/section}}
|
||||
|
||||
{{= | | =}}
|
||||
|^section|
|
||||
{{data}}
|
||||
|data|
|
||||
|/section|
|
||||
]
|
||||
expected: |
|
||||
[
|
||||
I got interpolated.
|
||||
|data|
|
||||
|
||||
{{data}}
|
||||
I got interpolated.
|
||||
]
|
||||
|
||||
- name: Partial Inheritence
|
||||
desc: Delimiters set in a parent template should not affect a partial.
|
||||
data: { value: 'yes' }
|
||||
partials:
|
||||
include: '.{{value}}.'
|
||||
template: |
|
||||
[ {{>include}} ]
|
||||
{{= | | =}}
|
||||
[ |>include| ]
|
||||
expected: |
|
||||
[ .yes. ]
|
||||
[ .yes. ]
|
||||
|
||||
- name: Post-Partial Behavior
|
||||
desc: Delimiters set in a partial should not affect the parent template.
|
||||
data: { value: 'yes' }
|
||||
partials:
|
||||
include: '.{{value}}. {{= | | =}} .|value|.'
|
||||
template: |
|
||||
[ {{>include}} ]
|
||||
[ .{{value}}. .|value|. ]
|
||||
expected: |
|
||||
[ .yes. .yes. ]
|
||||
[ .yes. .|value|. ]
|
||||
|
||||
# Whitespace Sensitivity
|
||||
|
||||
- name: Surrounding Whitespace
|
||||
desc: Surrounding whitespace should be left untouched.
|
||||
data: { }
|
||||
template: '| {{=@ @=}} |'
|
||||
expected: '| |'
|
||||
|
||||
- name: Outlying Whitespace (Inline)
|
||||
desc: Whitespace should be left untouched.
|
||||
data: { }
|
||||
template: " | {{=@ @=}}\n"
|
||||
expected: " | \n"
|
||||
|
||||
- name: Standalone Tag
|
||||
desc: Standalone lines should be removed from the template.
|
||||
data: { }
|
||||
template: |
|
||||
Begin.
|
||||
{{=@ @=}}
|
||||
End.
|
||||
expected: |
|
||||
Begin.
|
||||
End.
|
||||
|
||||
- name: Indented Standalone Tag
|
||||
desc: Indented standalone lines should be removed from the template.
|
||||
data: { }
|
||||
template: |
|
||||
Begin.
|
||||
{{=@ @=}}
|
||||
End.
|
||||
expected: |
|
||||
Begin.
|
||||
End.
|
||||
|
||||
- name: Standalone Line Endings
|
||||
desc: '"\r\n" should be considered a newline for standalone tags.'
|
||||
data: { }
|
||||
template: "|\r\n{{= @ @ =}}\r\n|"
|
||||
expected: "|\r\n|"
|
||||
|
||||
- name: Standalone Without Previous Line
|
||||
desc: Standalone tags should not require a newline to precede them.
|
||||
data: { }
|
||||
template: " {{=@ @=}}\n="
|
||||
expected: "="
|
||||
|
||||
- name: Standalone Without Newline
|
||||
desc: Standalone tags should not require a newline to follow them.
|
||||
data: { }
|
||||
template: "=\n {{=@ @=}}"
|
||||
expected: "=\n"
|
||||
|
||||
# Whitespace Insensitivity
|
||||
|
||||
- name: Pair with Padding
|
||||
desc: Superfluous in-tag whitespace should be ignored.
|
||||
data: { }
|
||||
template: '|{{= @ @ =}}|'
|
||||
expected: '||'
|
1
docs/build/node_modules/hogan.js/test/spec/specs/interpolation.json
generated
vendored
Normal file
1
docs/build/node_modules/hogan.js/test/spec/specs/interpolation.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
230
docs/build/node_modules/hogan.js/test/spec/specs/interpolation.yml
generated
vendored
Normal file
230
docs/build/node_modules/hogan.js/test/spec/specs/interpolation.yml
generated
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
overview: |
|
||||
Interpolation tags are used to integrate dynamic content into the template.
|
||||
|
||||
The tag's content MUST be a non-whitespace character sequence NOT containing
|
||||
the current closing delimiter.
|
||||
|
||||
This tag's content names the data to replace the tag. A single period (`.`)
|
||||
indicates that the item currently sitting atop the context stack should be
|
||||
used; otherwise, name resolution is as follows:
|
||||
1) Split the name on periods; the first part is the name to resolve, any
|
||||
remaining parts should be retained.
|
||||
2) Walk the context stack from top to bottom, finding the first context
|
||||
that is a) a hash containing the name as a key OR b) an object responding
|
||||
to a method with the given name.
|
||||
3) If the context is a hash, the data is the value associated with the
|
||||
name.
|
||||
4) If the context is an object, the data is the value returned by the
|
||||
method with the given name.
|
||||
5) If any name parts were retained in step 1, each should be resolved
|
||||
against a context stack containing only the result from the former
|
||||
resolution. If any part fails resolution, the result should be considered
|
||||
falsey, and should interpolate as the empty string.
|
||||
Data should be coerced into a string (and escaped, if appropriate) before
|
||||
interpolation.
|
||||
|
||||
The Interpolation tags MUST NOT be treated as standalone.
|
||||
tests:
|
||||
- name: No Interpolation
|
||||
desc: Mustache-free templates should render as-is.
|
||||
data: { }
|
||||
template: |
|
||||
Hello from {Mustache}!
|
||||
expected: |
|
||||
Hello from {Mustache}!
|
||||
|
||||
- name: Basic Interpolation
|
||||
desc: Unadorned tags should interpolate content into the template.
|
||||
data: { subject: "world" }
|
||||
template: |
|
||||
Hello, {{subject}}!
|
||||
expected: |
|
||||
Hello, world!
|
||||
|
||||
- name: HTML Escaping
|
||||
desc: Basic interpolation should be HTML escaped.
|
||||
data: { forbidden: '& " < >' }
|
||||
template: |
|
||||
These characters should be HTML escaped: {{forbidden}}
|
||||
expected: |
|
||||
These characters should be HTML escaped: & " < >
|
||||
|
||||
- name: Triple Mustache
|
||||
desc: Triple mustaches should interpolate without HTML escaping.
|
||||
data: { forbidden: '& " < >' }
|
||||
template: |
|
||||
These characters should not be HTML escaped: {{{forbidden}}}
|
||||
expected: |
|
||||
These characters should not be HTML escaped: & " < >
|
||||
|
||||
- name: Ampersand
|
||||
desc: Ampersand should interpolate without HTML escaping.
|
||||
data: { forbidden: '& " < >' }
|
||||
template: |
|
||||
These characters should not be HTML escaped: {{&forbidden}}
|
||||
expected: |
|
||||
These characters should not be HTML escaped: & " < >
|
||||
|
||||
- name: Basic Integer Interpolation
|
||||
desc: Integers should interpolate seamlessly.
|
||||
data: { mph: 85 }
|
||||
template: '"{{mph}} miles an hour!"'
|
||||
expected: '"85 miles an hour!"'
|
||||
|
||||
- name: Triple Mustache Integer Interpolation
|
||||
desc: Integers should interpolate seamlessly.
|
||||
data: { mph: 85 }
|
||||
template: '"{{{mph}}} miles an hour!"'
|
||||
expected: '"85 miles an hour!"'
|
||||
|
||||
- name: Ampersand Integer Interpolation
|
||||
desc: Integers should interpolate seamlessly.
|
||||
data: { mph: 85 }
|
||||
template: '"{{&mph}} miles an hour!"'
|
||||
expected: '"85 miles an hour!"'
|
||||
|
||||
- name: Basic Decimal Interpolation
|
||||
desc: Decimals should interpolate seamlessly with proper significance.
|
||||
data: { power: 1.210 }
|
||||
template: '"{{power}} jiggawatts!"'
|
||||
expected: '"1.21 jiggawatts!"'
|
||||
|
||||
- name: Triple Mustache Decimal Interpolation
|
||||
desc: Decimals should interpolate seamlessly with proper significance.
|
||||
data: { power: 1.210 }
|
||||
template: '"{{{power}}} jiggawatts!"'
|
||||
expected: '"1.21 jiggawatts!"'
|
||||
|
||||
- name: Ampersand Decimal Interpolation
|
||||
desc: Decimals should interpolate seamlessly with proper significance.
|
||||
data: { power: 1.210 }
|
||||
template: '"{{&power}} jiggawatts!"'
|
||||
expected: '"1.21 jiggawatts!"'
|
||||
|
||||
# Context Misses
|
||||
|
||||
- name: Basic Context Miss Interpolation
|
||||
desc: Failed context lookups should default to empty strings.
|
||||
data: { }
|
||||
template: "I ({{cannot}}) be seen!"
|
||||
expected: "I () be seen!"
|
||||
|
||||
- name: Triple Mustache Context Miss Interpolation
|
||||
desc: Failed context lookups should default to empty strings.
|
||||
data: { }
|
||||
template: "I ({{{cannot}}}) be seen!"
|
||||
expected: "I () be seen!"
|
||||
|
||||
- name: Ampersand Context Miss Interpolation
|
||||
desc: Failed context lookups should default to empty strings.
|
||||
data: { }
|
||||
template: "I ({{&cannot}}) be seen!"
|
||||
expected: "I () be seen!"
|
||||
|
||||
# Dotted Names
|
||||
|
||||
- name: Dotted Names - Basic Interpolation
|
||||
desc: Dotted names should be considered a form of shorthand for sections.
|
||||
data: { person: { name: 'Joe' } }
|
||||
template: '"{{person.name}}" == "{{#person}}{{name}}{{/person}}"'
|
||||
expected: '"Joe" == "Joe"'
|
||||
|
||||
- name: Dotted Names - Triple Mustache Interpolation
|
||||
desc: Dotted names should be considered a form of shorthand for sections.
|
||||
data: { person: { name: 'Joe' } }
|
||||
template: '"{{{person.name}}}" == "{{#person}}{{{name}}}{{/person}}"'
|
||||
expected: '"Joe" == "Joe"'
|
||||
|
||||
- name: Dotted Names - Ampersand Interpolation
|
||||
desc: Dotted names should be considered a form of shorthand for sections.
|
||||
data: { person: { name: 'Joe' } }
|
||||
template: '"{{&person.name}}" == "{{#person}}{{&name}}{{/person}}"'
|
||||
expected: '"Joe" == "Joe"'
|
||||
|
||||
- name: Dotted Names - Arbitrary Depth
|
||||
desc: Dotted names should be functional to any level of nesting.
|
||||
data:
|
||||
a: { b: { c: { d: { e: { name: 'Phil' } } } } }
|
||||
template: '"{{a.b.c.d.e.name}}" == "Phil"'
|
||||
expected: '"Phil" == "Phil"'
|
||||
|
||||
- name: Dotted Names - Broken Chains
|
||||
desc: Any falsey value prior to the last part of the name should yield ''.
|
||||
data:
|
||||
a: { }
|
||||
template: '"{{a.b.c}}" == ""'
|
||||
expected: '"" == ""'
|
||||
|
||||
- name: Dotted Names - Broken Chain Resolution
|
||||
desc: Each part of a dotted name should resolve only against its parent.
|
||||
data:
|
||||
a: { b: { } }
|
||||
c: { name: 'Jim' }
|
||||
template: '"{{a.b.c.name}}" == ""'
|
||||
expected: '"" == ""'
|
||||
|
||||
- name: Dotted Names - Initial Resolution
|
||||
desc: The first part of a dotted name should resolve as any other name.
|
||||
data:
|
||||
a: { b: { c: { d: { e: { name: 'Phil' } } } } }
|
||||
b: { c: { d: { e: { name: 'Wrong' } } } }
|
||||
template: '"{{#a}}{{b.c.d.e.name}}{{/a}}" == "Phil"'
|
||||
expected: '"Phil" == "Phil"'
|
||||
|
||||
# Whitespace Sensitivity
|
||||
|
||||
- name: Interpolation - Surrounding Whitespace
|
||||
desc: Interpolation should not alter surrounding whitespace.
|
||||
data: { string: '---' }
|
||||
template: '| {{string}} |'
|
||||
expected: '| --- |'
|
||||
|
||||
- name: Triple Mustache - Surrounding Whitespace
|
||||
desc: Interpolation should not alter surrounding whitespace.
|
||||
data: { string: '---' }
|
||||
template: '| {{{string}}} |'
|
||||
expected: '| --- |'
|
||||
|
||||
- name: Ampersand - Surrounding Whitespace
|
||||
desc: Interpolation should not alter surrounding whitespace.
|
||||
data: { string: '---' }
|
||||
template: '| {{&string}} |'
|
||||
expected: '| --- |'
|
||||
|
||||
- name: Interpolation - Standalone
|
||||
desc: Standalone interpolation should not alter surrounding whitespace.
|
||||
data: { string: '---' }
|
||||
template: " {{string}}\n"
|
||||
expected: " ---\n"
|
||||
|
||||
- name: Triple Mustache - Standalone
|
||||
desc: Standalone interpolation should not alter surrounding whitespace.
|
||||
data: { string: '---' }
|
||||
template: " {{{string}}}\n"
|
||||
expected: " ---\n"
|
||||
|
||||
- name: Ampersand - Standalone
|
||||
desc: Standalone interpolation should not alter surrounding whitespace.
|
||||
data: { string: '---' }
|
||||
template: " {{&string}}\n"
|
||||
expected: " ---\n"
|
||||
|
||||
# Whitespace Insensitivity
|
||||
|
||||
- name: Interpolation With Padding
|
||||
desc: Superfluous in-tag whitespace should be ignored.
|
||||
data: { string: "---" }
|
||||
template: '|{{ string }}|'
|
||||
expected: '|---|'
|
||||
|
||||
- name: Triple Mustache With Padding
|
||||
desc: Superfluous in-tag whitespace should be ignored.
|
||||
data: { string: "---" }
|
||||
template: '|{{{ string }}}|'
|
||||
expected: '|---|'
|
||||
|
||||
- name: Ampersand With Padding
|
||||
desc: Superfluous in-tag whitespace should be ignored.
|
||||
data: { string: "---" }
|
||||
template: '|{{& string }}|'
|
||||
expected: '|---|'
|
1
docs/build/node_modules/hogan.js/test/spec/specs/inverted.json
generated
vendored
Normal file
1
docs/build/node_modules/hogan.js/test/spec/specs/inverted.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
193
docs/build/node_modules/hogan.js/test/spec/specs/inverted.yml
generated
vendored
Normal file
193
docs/build/node_modules/hogan.js/test/spec/specs/inverted.yml
generated
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
overview: |
|
||||
Inverted Section tags and End Section tags are used in combination to wrap a
|
||||
section of the template.
|
||||
|
||||
These tags' content MUST be a non-whitespace character sequence NOT
|
||||
containing the current closing delimiter; each Inverted Section tag MUST be
|
||||
followed by an End Section tag with the same content within the same
|
||||
section.
|
||||
|
||||
This tag's content names the data to replace the tag. Name resolution is as
|
||||
follows:
|
||||
1) Split the name on periods; the first part is the name to resolve, any
|
||||
remaining parts should be retained.
|
||||
2) Walk the context stack from top to bottom, finding the first context
|
||||
that is a) a hash containing the name as a key OR b) an object responding
|
||||
to a method with the given name.
|
||||
3) If the context is a hash, the data is the value associated with the
|
||||
name.
|
||||
4) If the context is an object and the method with the given name has an
|
||||
arity of 1, the method SHOULD be called with a String containing the
|
||||
unprocessed contents of the sections; the data is the value returned.
|
||||
5) Otherwise, the data is the value returned by calling the method with
|
||||
the given name.
|
||||
6) If any name parts were retained in step 1, each should be resolved
|
||||
against a context stack containing only the result from the former
|
||||
resolution. If any part fails resolution, the result should be considered
|
||||
falsey, and should interpolate as the empty string.
|
||||
If the data is not of a list type, it is coerced into a list as follows: if
|
||||
the data is truthy (e.g. `!!data == true`), use a single-element list
|
||||
containing the data, otherwise use an empty list.
|
||||
|
||||
This section MUST NOT be rendered unless the data list is empty.
|
||||
|
||||
Inverted Section and End Section tags SHOULD be treated as standalone when
|
||||
appropriate.
|
||||
tests:
|
||||
- name: Falsey
|
||||
desc: Falsey sections should have their contents rendered.
|
||||
data: { boolean: false }
|
||||
template: '"{{^boolean}}This should be rendered.{{/boolean}}"'
|
||||
expected: '"This should be rendered."'
|
||||
|
||||
- name: Truthy
|
||||
desc: Truthy sections should have their contents omitted.
|
||||
data: { boolean: true }
|
||||
template: '"{{^boolean}}This should not be rendered.{{/boolean}}"'
|
||||
expected: '""'
|
||||
|
||||
- name: Context
|
||||
desc: Objects and hashes should behave like truthy values.
|
||||
data: { context: { name: 'Joe' } }
|
||||
template: '"{{^context}}Hi {{name}}.{{/context}}"'
|
||||
expected: '""'
|
||||
|
||||
- name: List
|
||||
desc: Lists should behave like truthy values.
|
||||
data: { list: [ { n: 1 }, { n: 2 }, { n: 3 } ] }
|
||||
template: '"{{^list}}{{n}}{{/list}}"'
|
||||
expected: '""'
|
||||
|
||||
- name: Empty List
|
||||
desc: Empty lists should behave like falsey values.
|
||||
data: { list: [ ] }
|
||||
template: '"{{^list}}Yay lists!{{/list}}"'
|
||||
expected: '"Yay lists!"'
|
||||
|
||||
- name: Doubled
|
||||
desc: Multiple inverted sections per template should be permitted.
|
||||
data: { bool: false, two: 'second' }
|
||||
template: |
|
||||
{{^bool}}
|
||||
* first
|
||||
{{/bool}}
|
||||
* {{two}}
|
||||
{{^bool}}
|
||||
* third
|
||||
{{/bool}}
|
||||
expected: |
|
||||
* first
|
||||
* second
|
||||
* third
|
||||
|
||||
- name: Nested (Falsey)
|
||||
desc: Nested falsey sections should have their contents rendered.
|
||||
data: { bool: false }
|
||||
template: "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
|
||||
expected: "| A B C D E |"
|
||||
|
||||
- name: Nested (Truthy)
|
||||
desc: Nested truthy sections should be omitted.
|
||||
data: { bool: true }
|
||||
template: "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
|
||||
expected: "| A E |"
|
||||
|
||||
- name: Context Misses
|
||||
desc: Failed context lookups should be considered falsey.
|
||||
data: { }
|
||||
template: "[{{^missing}}Cannot find key 'missing'!{{/missing}}]"
|
||||
expected: "[Cannot find key 'missing'!]"
|
||||
|
||||
# Dotted Names
|
||||
|
||||
- name: Dotted Names - Truthy
|
||||
desc: Dotted names should be valid for Inverted Section tags.
|
||||
data: { a: { b: { c: true } } }
|
||||
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == ""'
|
||||
expected: '"" == ""'
|
||||
|
||||
- name: Dotted Names - Falsey
|
||||
desc: Dotted names should be valid for Inverted Section tags.
|
||||
data: { a: { b: { c: false } } }
|
||||
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == "Not Here"'
|
||||
expected: '"Not Here" == "Not Here"'
|
||||
|
||||
- name: Dotted Names - Broken Chains
|
||||
desc: Dotted names that cannot be resolved should be considered falsey.
|
||||
data: { a: { } }
|
||||
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == "Not Here"'
|
||||
expected: '"Not Here" == "Not Here"'
|
||||
|
||||
# Whitespace Sensitivity
|
||||
|
||||
- name: Surrounding Whitespace
|
||||
desc: Inverted sections should not alter surrounding whitespace.
|
||||
data: { boolean: false }
|
||||
template: " | {{^boolean}}\t|\t{{/boolean}} | \n"
|
||||
expected: " | \t|\t | \n"
|
||||
|
||||
- name: Internal Whitespace
|
||||
desc: Inverted should not alter internal whitespace.
|
||||
data: { boolean: false }
|
||||
template: " | {{^boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
|
||||
expected: " | \n | \n"
|
||||
|
||||
- name: Indented Inline Sections
|
||||
desc: Single-line sections should not alter surrounding whitespace.
|
||||
data: { boolean: false }
|
||||
template: " {{^boolean}}NO{{/boolean}}\n {{^boolean}}WAY{{/boolean}}\n"
|
||||
expected: " NO\n WAY\n"
|
||||
|
||||
- name: Standalone Lines
|
||||
desc: Standalone lines should be removed from the template.
|
||||
data: { boolean: false }
|
||||
template: |
|
||||
| This Is
|
||||
{{^boolean}}
|
||||
|
|
||||
{{/boolean}}
|
||||
| A Line
|
||||
expected: |
|
||||
| This Is
|
||||
|
|
||||
| A Line
|
||||
|
||||
- name: Standalone Indented Lines
|
||||
desc: Standalone indented lines should be removed from the template.
|
||||
data: { boolean: false }
|
||||
template: |
|
||||
| This Is
|
||||
{{^boolean}}
|
||||
|
|
||||
{{/boolean}}
|
||||
| A Line
|
||||
expected: |
|
||||
| This Is
|
||||
|
|
||||
| A Line
|
||||
|
||||
- name: Standalone Line Endings
|
||||
desc: '"\r\n" should be considered a newline for standalone tags.'
|
||||
data: { boolean: false }
|
||||
template: "|\r\n{{^boolean}}\r\n{{/boolean}}\r\n|"
|
||||
expected: "|\r\n|"
|
||||
|
||||
- name: Standalone Without Previous Line
|
||||
desc: Standalone tags should not require a newline to precede them.
|
||||
data: { boolean: false }
|
||||
template: " {{^boolean}}\n^{{/boolean}}\n/"
|
||||
expected: "^\n/"
|
||||
|
||||
- name: Standalone Without Newline
|
||||
desc: Standalone tags should not require a newline to follow them.
|
||||
data: { boolean: false }
|
||||
template: "^{{^boolean}}\n/\n {{/boolean}}"
|
||||
expected: "^\n/\n"
|
||||
|
||||
# Whitespace Insensitivity
|
||||
|
||||
- name: Padding
|
||||
desc: Superfluous in-tag whitespace should be ignored.
|
||||
data: { boolean: false }
|
||||
template: '|{{^ boolean }}={{/ boolean }}|'
|
||||
expected: '|=|'
|
1
docs/build/node_modules/hogan.js/test/spec/specs/partials.json
generated
vendored
Normal file
1
docs/build/node_modules/hogan.js/test/spec/specs/partials.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Partial tags are used to expand an external template into the current\ntemplate.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the partial to inject. Set Delimiter tags MUST NOT\naffect the parsing of a partial. The partial MUST be rendered against the\ncontext stack local to the tag. If the named partial cannot be found, the\nempty string SHOULD be used instead, as in interpolations.\n\nPartial tags SHOULD be treated as standalone when appropriate. If this tag\nis used standalone, any whitespace preceding the tag should treated as\nindentation, and prepended to each line of the partial before rendering.\n","tests":[{"name":"Basic Behavior","data":{},"expected":"\"from partial\"","template":"\"{{>text}}\"","desc":"The greater-than operator should expand to the named partial.","partials":{"text":"from partial"}},{"name":"Failed Lookup","data":{},"expected":"\"\"","template":"\"{{>text}}\"","desc":"The empty string should be used when the named partial is not found.","partials":{}},{"name":"Context","data":{"text":"content"},"expected":"\"*content*\"","template":"\"{{>partial}}\"","desc":"The greater-than operator should operate within the current context.","partials":{"partial":"*{{text}}*"}},{"name":"Recursion","data":{"content":"X","nodes":[{"content":"Y","nodes":[]}]},"expected":"X<Y<>>","template":"{{>node}}","desc":"The greater-than operator should properly recurse.","partials":{"node":"{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"}},{"name":"Surrounding Whitespace","data":{},"expected":"| \t|\t |","template":"| {{>partial}} |","desc":"The greater-than operator should not alter surrounding whitespace.","partials":{"partial":"\t|\t"}},{"name":"Inline Indentation","data":{"data":"|"},"expected":" | >\n>\n","template":" {{data}} {{> partial}}\n","desc":"Whitespace should be left untouched.","partials":{"partial":">\n>"}},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n>|","template":"|\r\n{{>partial}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","partials":{"partial":">"}},{"name":"Standalone Without Previous Line","data":{},"expected":" >\n >>","template":" {{>partial}}\n>","desc":"Standalone tags should not require a newline to precede them.","partials":{"partial":">\n>"}},{"name":"Standalone Without Newline","data":{},"expected":">\n >\n >","template":">\n {{>partial}}","desc":"Standalone tags should not require a newline to follow them.","partials":{"partial":">\n>"}},{"name":"Standalone Indentation","data":{"content":"<\n->"},"expected":"\\\n |\n <\n->\n |\n/\n","template":"\\\n {{>partial}}\n/\n","desc":"Each line of the partial should be indented before rendering.","partials":{"partial":"|\n{{{content}}}\n|\n"}},{"name":"Padding Whitespace","data":{"boolean":true},"expected":"|[]|","template":"|{{> partial }}|","desc":"Superfluous in-tag whitespace should be ignored.","partials":{"partial":"[]"}}]}
|
109
docs/build/node_modules/hogan.js/test/spec/specs/partials.yml
generated
vendored
Normal file
109
docs/build/node_modules/hogan.js/test/spec/specs/partials.yml
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
overview: |
|
||||
Partial tags are used to expand an external template into the current
|
||||
template.
|
||||
|
||||
The tag's content MUST be a non-whitespace character sequence NOT containing
|
||||
the current closing delimiter.
|
||||
|
||||
This tag's content names the partial to inject. Set Delimiter tags MUST NOT
|
||||
affect the parsing of a partial. The partial MUST be rendered against the
|
||||
context stack local to the tag. If the named partial cannot be found, the
|
||||
empty string SHOULD be used instead, as in interpolations.
|
||||
|
||||
Partial tags SHOULD be treated as standalone when appropriate. If this tag
|
||||
is used standalone, any whitespace preceding the tag should treated as
|
||||
indentation, and prepended to each line of the partial before rendering.
|
||||
tests:
|
||||
- name: Basic Behavior
|
||||
desc: The greater-than operator should expand to the named partial.
|
||||
data: { }
|
||||
template: '"{{>text}}"'
|
||||
partials: { text: 'from partial' }
|
||||
expected: '"from partial"'
|
||||
|
||||
- name: Failed Lookup
|
||||
desc: The empty string should be used when the named partial is not found.
|
||||
data: { }
|
||||
template: '"{{>text}}"'
|
||||
partials: { }
|
||||
expected: '""'
|
||||
|
||||
- name: Context
|
||||
desc: The greater-than operator should operate within the current context.
|
||||
data: { text: 'content' }
|
||||
template: '"{{>partial}}"'
|
||||
partials: { partial: '*{{text}}*' }
|
||||
expected: '"*content*"'
|
||||
|
||||
- name: Recursion
|
||||
desc: The greater-than operator should properly recurse.
|
||||
data: { content: "X", nodes: [ { content: "Y", nodes: [] } ] }
|
||||
template: '{{>node}}'
|
||||
partials: { node: '{{content}}<{{#nodes}}{{>node}}{{/nodes}}>' }
|
||||
expected: 'X<Y<>>'
|
||||
|
||||
# Whitespace Sensitivity
|
||||
|
||||
- name: Surrounding Whitespace
|
||||
desc: The greater-than operator should not alter surrounding whitespace.
|
||||
data: { }
|
||||
template: '| {{>partial}} |'
|
||||
partials: { partial: "\t|\t" }
|
||||
expected: "| \t|\t |"
|
||||
|
||||
- name: Inline Indentation
|
||||
desc: Whitespace should be left untouched.
|
||||
data: { data: '|' }
|
||||
template: " {{data}} {{> partial}}\n"
|
||||
partials: { partial: ">\n>" }
|
||||
expected: " | >\n>\n"
|
||||
|
||||
- name: Standalone Line Endings
|
||||
desc: '"\r\n" should be considered a newline for standalone tags.'
|
||||
data: { }
|
||||
template: "|\r\n{{>partial}}\r\n|"
|
||||
partials: { partial: ">" }
|
||||
expected: "|\r\n>|"
|
||||
|
||||
- name: Standalone Without Previous Line
|
||||
desc: Standalone tags should not require a newline to precede them.
|
||||
data: { }
|
||||
template: " {{>partial}}\n>"
|
||||
partials: { partial: ">\n>"}
|
||||
expected: " >\n >>"
|
||||
|
||||
- name: Standalone Without Newline
|
||||
desc: Standalone tags should not require a newline to follow them.
|
||||
data: { }
|
||||
template: ">\n {{>partial}}"
|
||||
partials: { partial: ">\n>" }
|
||||
expected: ">\n >\n >"
|
||||
|
||||
- name: Standalone Indentation
|
||||
desc: Each line of the partial should be indented before rendering.
|
||||
data: { content: "<\n->" }
|
||||
template: |
|
||||
\
|
||||
{{>partial}}
|
||||
/
|
||||
partials:
|
||||
partial: |
|
||||
|
|
||||
{{{content}}}
|
||||
|
|
||||
expected: |
|
||||
\
|
||||
|
|
||||
<
|
||||
->
|
||||
|
|
||||
/
|
||||
|
||||
# Whitespace Insensitivity
|
||||
|
||||
- name: Padding Whitespace
|
||||
desc: Superfluous in-tag whitespace should be ignored.
|
||||
data: { boolean: true }
|
||||
template: "|{{> partial }}|"
|
||||
partials: { partial: "[]" }
|
||||
expected: '|[]|'
|
1
docs/build/node_modules/hogan.js/test/spec/specs/sections.json
generated
vendored
Normal file
1
docs/build/node_modules/hogan.js/test/spec/specs/sections.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
256
docs/build/node_modules/hogan.js/test/spec/specs/sections.yml
generated
vendored
Normal file
256
docs/build/node_modules/hogan.js/test/spec/specs/sections.yml
generated
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
overview: |
|
||||
Section tags and End Section tags are used in combination to wrap a section
|
||||
of the template for iteration
|
||||
|
||||
These tags' content MUST be a non-whitespace character sequence NOT
|
||||
containing the current closing delimiter; each Section tag MUST be followed
|
||||
by an End Section tag with the same content within the same section.
|
||||
|
||||
This tag's content names the data to replace the tag. Name resolution is as
|
||||
follows:
|
||||
1) Split the name on periods; the first part is the name to resolve, any
|
||||
remaining parts should be retained.
|
||||
2) Walk the context stack from top to bottom, finding the first context
|
||||
that is a) a hash containing the name as a key OR b) an object responding
|
||||
to a method with the given name.
|
||||
3) If the context is a hash, the data is the value associated with the
|
||||
name.
|
||||
4) If the context is an object and the method with the given name has an
|
||||
arity of 1, the method SHOULD be called with a String containing the
|
||||
unprocessed contents of the sections; the data is the value returned.
|
||||
5) Otherwise, the data is the value returned by calling the method with
|
||||
the given name.
|
||||
6) If any name parts were retained in step 1, each should be resolved
|
||||
against a context stack containing only the result from the former
|
||||
resolution. If any part fails resolution, the result should be considered
|
||||
falsey, and should interpolate as the empty string.
|
||||
If the data is not of a list type, it is coerced into a list as follows: if
|
||||
the data is truthy (e.g. `!!data == true`), use a single-element list
|
||||
containing the data, otherwise use an empty list.
|
||||
|
||||
For each element in the data list, the element MUST be pushed onto the
|
||||
context stack, the section MUST be rendered, and the element MUST be popped
|
||||
off the context stack.
|
||||
|
||||
Section and End Section tags SHOULD be treated as standalone when
|
||||
appropriate.
|
||||
tests:
|
||||
- name: Truthy
|
||||
desc: Truthy sections should have their contents rendered.
|
||||
data: { boolean: true }
|
||||
template: '"{{#boolean}}This should be rendered.{{/boolean}}"'
|
||||
expected: '"This should be rendered."'
|
||||
|
||||
- name: Falsey
|
||||
desc: Falsey sections should have their contents omitted.
|
||||
data: { boolean: false }
|
||||
template: '"{{#boolean}}This should not be rendered.{{/boolean}}"'
|
||||
expected: '""'
|
||||
|
||||
- name: Context
|
||||
desc: Objects and hashes should be pushed onto the context stack.
|
||||
data: { context: { name: 'Joe' } }
|
||||
template: '"{{#context}}Hi {{name}}.{{/context}}"'
|
||||
expected: '"Hi Joe."'
|
||||
|
||||
- name: Deeply Nested Contexts
|
||||
desc: All elements on the context stack should be accessible.
|
||||
data:
|
||||
a: { one: 1 }
|
||||
b: { two: 2 }
|
||||
c: { three: 3 }
|
||||
d: { four: 4 }
|
||||
e: { five: 5 }
|
||||
template: |
|
||||
{{#a}}
|
||||
{{one}}
|
||||
{{#b}}
|
||||
{{one}}{{two}}{{one}}
|
||||
{{#c}}
|
||||
{{one}}{{two}}{{three}}{{two}}{{one}}
|
||||
{{#d}}
|
||||
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
|
||||
{{#e}}
|
||||
{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
|
||||
{{/e}}
|
||||
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
|
||||
{{/d}}
|
||||
{{one}}{{two}}{{three}}{{two}}{{one}}
|
||||
{{/c}}
|
||||
{{one}}{{two}}{{one}}
|
||||
{{/b}}
|
||||
{{one}}
|
||||
{{/a}}
|
||||
expected: |
|
||||
1
|
||||
121
|
||||
12321
|
||||
1234321
|
||||
123454321
|
||||
1234321
|
||||
12321
|
||||
121
|
||||
1
|
||||
|
||||
- name: List
|
||||
desc: Lists should be iterated; list items should visit the context stack.
|
||||
data: { list: [ { item: 1 }, { item: 2 }, { item: 3 } ] }
|
||||
template: '"{{#list}}{{item}}{{/list}}"'
|
||||
expected: '"123"'
|
||||
|
||||
- name: Empty List
|
||||
desc: Empty lists should behave like falsey values.
|
||||
data: { list: [ ] }
|
||||
template: '"{{#list}}Yay lists!{{/list}}"'
|
||||
expected: '""'
|
||||
|
||||
- name: Doubled
|
||||
desc: Multiple sections per template should be permitted.
|
||||
data: { bool: true, two: 'second' }
|
||||
template: |
|
||||
{{#bool}}
|
||||
* first
|
||||
{{/bool}}
|
||||
* {{two}}
|
||||
{{#bool}}
|
||||
* third
|
||||
{{/bool}}
|
||||
expected: |
|
||||
* first
|
||||
* second
|
||||
* third
|
||||
|
||||
- name: Nested (Truthy)
|
||||
desc: Nested truthy sections should have their contents rendered.
|
||||
data: { bool: true }
|
||||
template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
|
||||
expected: "| A B C D E |"
|
||||
|
||||
- name: Nested (Falsey)
|
||||
desc: Nested falsey sections should be omitted.
|
||||
data: { bool: false }
|
||||
template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
|
||||
expected: "| A E |"
|
||||
|
||||
- name: Context Misses
|
||||
desc: Failed context lookups should be considered falsey.
|
||||
data: { }
|
||||
template: "[{{#missing}}Found key 'missing'!{{/missing}}]"
|
||||
expected: "[]"
|
||||
|
||||
# Implicit Iterators
|
||||
|
||||
- name: Implicit Iterator - String
|
||||
desc: Implicit iterators should directly interpolate strings.
|
||||
data:
|
||||
list: [ 'a', 'b', 'c', 'd', 'e' ]
|
||||
template: '"{{#list}}({{.}}){{/list}}"'
|
||||
expected: '"(a)(b)(c)(d)(e)"'
|
||||
|
||||
- name: Implicit Iterator - Integer
|
||||
desc: Implicit iterators should cast integers to strings and interpolate.
|
||||
data:
|
||||
list: [ 1, 2, 3, 4, 5 ]
|
||||
template: '"{{#list}}({{.}}){{/list}}"'
|
||||
expected: '"(1)(2)(3)(4)(5)"'
|
||||
|
||||
- name: Implicit Iterator - Decimal
|
||||
desc: Implicit iterators should cast decimals to strings and interpolate.
|
||||
data:
|
||||
list: [ 1.10, 2.20, 3.30, 4.40, 5.50 ]
|
||||
template: '"{{#list}}({{.}}){{/list}}"'
|
||||
expected: '"(1.1)(2.2)(3.3)(4.4)(5.5)"'
|
||||
|
||||
# Dotted Names
|
||||
|
||||
- name: Dotted Names - Truthy
|
||||
desc: Dotted names should be valid for Section tags.
|
||||
data: { a: { b: { c: true } } }
|
||||
template: '"{{#a.b.c}}Here{{/a.b.c}}" == "Here"'
|
||||
expected: '"Here" == "Here"'
|
||||
|
||||
- name: Dotted Names - Falsey
|
||||
desc: Dotted names should be valid for Section tags.
|
||||
data: { a: { b: { c: false } } }
|
||||
template: '"{{#a.b.c}}Here{{/a.b.c}}" == ""'
|
||||
expected: '"" == ""'
|
||||
|
||||
- name: Dotted Names - Broken Chains
|
||||
desc: Dotted names that cannot be resolved should be considered falsey.
|
||||
data: { a: { } }
|
||||
template: '"{{#a.b.c}}Here{{/a.b.c}}" == ""'
|
||||
expected: '"" == ""'
|
||||
|
||||
# Whitespace Sensitivity
|
||||
|
||||
- name: Surrounding Whitespace
|
||||
desc: Sections should not alter surrounding whitespace.
|
||||
data: { boolean: true }
|
||||
template: " | {{#boolean}}\t|\t{{/boolean}} | \n"
|
||||
expected: " | \t|\t | \n"
|
||||
|
||||
- name: Internal Whitespace
|
||||
desc: Sections should not alter internal whitespace.
|
||||
data: { boolean: true }
|
||||
template: " | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
|
||||
expected: " | \n | \n"
|
||||
|
||||
- name: Indented Inline Sections
|
||||
desc: Single-line sections should not alter surrounding whitespace.
|
||||
data: { boolean: true }
|
||||
template: " {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n"
|
||||
expected: " YES\n GOOD\n"
|
||||
|
||||
- name: Standalone Lines
|
||||
desc: Standalone lines should be removed from the template.
|
||||
data: { boolean: true }
|
||||
template: |
|
||||
| This Is
|
||||
{{#boolean}}
|
||||
|
|
||||
{{/boolean}}
|
||||
| A Line
|
||||
expected: |
|
||||
| This Is
|
||||
|
|
||||
| A Line
|
||||
|
||||
- name: Indented Standalone Lines
|
||||
desc: Indented standalone lines should be removed from the template.
|
||||
data: { boolean: true }
|
||||
template: |
|
||||
| This Is
|
||||
{{#boolean}}
|
||||
|
|
||||
{{/boolean}}
|
||||
| A Line
|
||||
expected: |
|
||||
| This Is
|
||||
|
|
||||
| A Line
|
||||
|
||||
- name: Standalone Line Endings
|
||||
desc: '"\r\n" should be considered a newline for standalone tags.'
|
||||
data: { boolean: true }
|
||||
template: "|\r\n{{#boolean}}\r\n{{/boolean}}\r\n|"
|
||||
expected: "|\r\n|"
|
||||
|
||||
- name: Standalone Without Previous Line
|
||||
desc: Standalone tags should not require a newline to precede them.
|
||||
data: { boolean: true }
|
||||
template: " {{#boolean}}\n#{{/boolean}}\n/"
|
||||
expected: "#\n/"
|
||||
|
||||
- name: Standalone Without Newline
|
||||
desc: Standalone tags should not require a newline to follow them.
|
||||
data: { boolean: true }
|
||||
template: "#{{#boolean}}\n/\n {{/boolean}}"
|
||||
expected: "#\n/\n"
|
||||
|
||||
# Whitespace Insensitivity
|
||||
|
||||
- name: Padding
|
||||
desc: Superfluous in-tag whitespace should be ignored.
|
||||
data: { boolean: true }
|
||||
template: '|{{# boolean }}={{/ boolean }}|'
|
||||
expected: '|=|'
|
1
docs/build/node_modules/hogan.js/test/spec/specs/~lambdas.json
generated
vendored
Normal file
1
docs/build/node_modules/hogan.js/test/spec/specs/~lambdas.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
149
docs/build/node_modules/hogan.js/test/spec/specs/~lambdas.yml
generated
vendored
Normal file
149
docs/build/node_modules/hogan.js/test/spec/specs/~lambdas.yml
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
overview: |
|
||||
Lambdas are a special-cased data type for use in interpolations and
|
||||
sections.
|
||||
|
||||
When used as the data value for an Interpolation tag, the lambda MUST be
|
||||
treatable as an arity 0 function, and invoked as such. The returned value
|
||||
MUST be rendered against the default delimiters, then interpolated in place
|
||||
of the lambda.
|
||||
|
||||
When used as the data value for a Section tag, the lambda MUST be treatable
|
||||
as an arity 1 function, and invoked as such (passing a String containing the
|
||||
unprocessed section contents). The returned value MUST be rendered against
|
||||
the current delimiters, then interpolated in place of the section.
|
||||
tests:
|
||||
- name: Interpolation
|
||||
desc: A lambda's return value should be interpolated.
|
||||
data:
|
||||
lambda: !code
|
||||
ruby: 'proc { "world" }'
|
||||
perl: 'sub { "world" }'
|
||||
js: 'function() { return "world" }'
|
||||
php: 'return "world";'
|
||||
python: 'lambda: "world"'
|
||||
clojure: '(fn [] "world")'
|
||||
template: "Hello, {{lambda}}!"
|
||||
expected: "Hello, world!"
|
||||
|
||||
- name: Interpolation - Expansion
|
||||
desc: A lambda's return value should be parsed.
|
||||
data:
|
||||
planet: "world"
|
||||
lambda: !code
|
||||
ruby: 'proc { "{{planet}}" }'
|
||||
perl: 'sub { "{{planet}}" }'
|
||||
js: 'function() { return "{{planet}}" }'
|
||||
php: 'return "{{planet}}";'
|
||||
python: 'lambda: "{{planet}}"'
|
||||
clojure: '(fn [] "{{planet}}")'
|
||||
template: "Hello, {{lambda}}!"
|
||||
expected: "Hello, world!"
|
||||
|
||||
- name: Interpolation - Alternate Delimiters
|
||||
desc: A lambda's return value should parse with the default delimiters.
|
||||
data:
|
||||
planet: "world"
|
||||
lambda: !code
|
||||
ruby: 'proc { "|planet| => {{planet}}" }'
|
||||
perl: 'sub { "|planet| => {{planet}}" }'
|
||||
js: 'function() { return "|planet| => {{planet}}" }'
|
||||
php: 'return "|planet| => {{planet}}";'
|
||||
python: 'lambda: "|planet| => {{planet}}"'
|
||||
clojure: '(fn [] "|planet| => {{planet}}")'
|
||||
template: "{{= | | =}}\nHello, (|&lambda|)!"
|
||||
expected: "Hello, (|planet| => world)!"
|
||||
|
||||
- name: Interpolation - Multiple Calls
|
||||
desc: Interpolated lambdas should not be cached.
|
||||
data:
|
||||
lambda: !code
|
||||
ruby: 'proc { $calls ||= 0; $calls += 1 }'
|
||||
perl: 'sub { no strict; $calls += 1 }'
|
||||
js: 'function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }'
|
||||
php: 'global $calls; return ++$calls;'
|
||||
python: 'lambda: globals().update(calls=globals().get("calls",0)+1) or calls'
|
||||
clojure: '(def g (atom 0)) (fn [] (swap! g inc))'
|
||||
template: '{{lambda}} == {{{lambda}}} == {{lambda}}'
|
||||
expected: '1 == 2 == 3'
|
||||
|
||||
- name: Escaping
|
||||
desc: Lambda results should be appropriately escaped.
|
||||
data:
|
||||
lambda: !code
|
||||
ruby: 'proc { ">" }'
|
||||
perl: 'sub { ">" }'
|
||||
js: 'function() { return ">" }'
|
||||
php: 'return ">";'
|
||||
python: 'lambda: ">"'
|
||||
clojure: '(fn [] ">")'
|
||||
template: "<{{lambda}}{{{lambda}}}"
|
||||
expected: "<>>"
|
||||
|
||||
- name: Section
|
||||
desc: Lambdas used for sections should receive the raw section string.
|
||||
data:
|
||||
x: 'Error!'
|
||||
lambda: !code
|
||||
ruby: 'proc { |text| text == "{{x}}" ? "yes" : "no" }'
|
||||
perl: 'sub { $_[0] eq "{{x}}" ? "yes" : "no" }'
|
||||
js: 'function(txt) { return (txt == "{{x}}" ? "yes" : "no") }'
|
||||
php: 'return ($text == "{{x}}") ? "yes" : "no";'
|
||||
python: 'lambda text: text == "{{x}}" and "yes" or "no"'
|
||||
clojure: '(fn [text] (if (= text "{{x}}") "yes" "no"))'
|
||||
template: "<{{#lambda}}{{x}}{{/lambda}}>"
|
||||
expected: "<yes>"
|
||||
|
||||
- name: Section - Expansion
|
||||
desc: Lambdas used for sections should have their results parsed.
|
||||
data:
|
||||
planet: "Earth"
|
||||
lambda: !code
|
||||
ruby: 'proc { |text| "#{text}{{planet}}#{text}" }'
|
||||
perl: 'sub { $_[0] . "{{planet}}" . $_[0] }'
|
||||
js: 'function(txt) { return txt + "{{planet}}" + txt }'
|
||||
php: 'return $text . "{{planet}}" . $text;'
|
||||
python: 'lambda text: "%s{{planet}}%s" % (text, text)'
|
||||
clojure: '(fn [text] (str text "{{planet}}" text))'
|
||||
template: "<{{#lambda}}-{{/lambda}}>"
|
||||
expected: "<-Earth->"
|
||||
|
||||
- name: Section - Alternate Delimiters
|
||||
desc: Lambdas used for sections should parse with the current delimiters.
|
||||
data:
|
||||
planet: "Earth"
|
||||
lambda: !code
|
||||
ruby: 'proc { |text| "#{text}{{planet}} => |planet|#{text}" }'
|
||||
perl: 'sub { $_[0] . "{{planet}} => |planet|" . $_[0] }'
|
||||
js: 'function(txt) { return txt + "{{planet}} => |planet|" + txt }'
|
||||
php: 'return $text . "{{planet}} => |planet|" . $text;'
|
||||
python: 'lambda text: "%s{{planet}} => |planet|%s" % (text, text)'
|
||||
clojure: '(fn [text] (str text "{{planet}} => |planet|" text))'
|
||||
template: "{{= | | =}}<|#lambda|-|/lambda|>"
|
||||
expected: "<-{{planet}} => Earth->"
|
||||
|
||||
- name: Section - Multiple Calls
|
||||
desc: Lambdas used for sections should not be cached.
|
||||
data:
|
||||
lambda: !code
|
||||
ruby: 'proc { |text| "__#{text}__" }'
|
||||
perl: 'sub { "__" . $_[0] . "__" }'
|
||||
js: 'function(txt) { return "__" + txt + "__" }'
|
||||
php: 'return "__" . $text . "__";'
|
||||
python: 'lambda text: "__%s__" % (text)'
|
||||
clojure: '(fn [text] (str "__" text "__"))'
|
||||
template: '{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}'
|
||||
expected: '__FILE__ != __LINE__'
|
||||
|
||||
- name: Inverted Section
|
||||
desc: Lambdas used for inverted sections should be considered truthy.
|
||||
data:
|
||||
static: 'static'
|
||||
lambda: !code
|
||||
ruby: 'proc { |text| false }'
|
||||
perl: 'sub { 0 }'
|
||||
js: 'function(txt) { return false }'
|
||||
php: 'return false;'
|
||||
python: 'lambda text: 0'
|
||||
clojure: '(fn [text] false)'
|
||||
template: "<{{^lambda}}{{static}}{{/lambda}}>"
|
||||
expected: "<>"
|
8
docs/build/node_modules/hogan.js/test/templates/list.mustache
generated
vendored
Normal file
8
docs/build/node_modules/hogan.js/test/templates/list.mustache
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<ul>
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
</ul>
|
Reference in New Issue
Block a user