{ "overview": "Rationale: this special notation was introduced primarly to allow the dynamic\nloading of partials. The main advantage that this notation offers is to allow\ndynamic loading of partials, which is particularly useful in cases where\npolymorphic data needs to be rendered in different ways, or in cases where a\npartial template needs to be included by multiple parent templates; cases\nwhich would otherwise be possible to render only with solutions that are\nconvoluted, inefficient, or both.\n\nDynamic Names are a special notation to dynamically determine a tag's content.\n\nDynamic Names MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter. A Dynamic Name consists of an asterisk,\nfollowed by a dotted name. The dotted name follows the same notation as in an\nInterpolation tag.\n\nThis tag's dotted name, which is the Dynamic Name excluding the\nleading asterisk, references a key in the context whose value will be used in\nplace of the Dynamic Name itself as content of the tag. The dotted name\nresolution produces the same value as an Interpolation tag and does not affect\nthe context for further processing.\n\nSet Delimiter tags MUST NOT affect the resolution of a Dynamic Name. The\nDynamic Names MUST be resolved against the context stack local to the tag.\nFailed resolution of the dynamic name SHOULD result in nothing being rendered.\n\nEngines that implement Dynamic Names MUST support their use in Partial tags.\nIn engines that also implement the optional inheritance spec, Dynamic Names\ninside Parent tags SHOULD be supported as well. Dynamic Names cannot be\nresolved more than once (Dynamic Names cannot be nested).\n", "tests": [ { "name": "Basic Behavior - Partial", "desc": "The asterisk operator is used for dynamic partials.", "data": { "dynamic": "content" }, "template": "\"{{>*dynamic}}\"", "partials": { "content": "Hello, world!" }, "expected": "\"Hello, world!\"" }, { "name": "Basic Behavior - Name Resolution", "desc": "The asterisk is not part of the name that will be resolved in the context.\n", "data": { "dynamic": "content", "*dynamic": "wrong" }, "template": "\"{{>*dynamic}}\"", "partials": { "content": "Hello, world!", "wrong": "Invisible" }, "expected": "\"Hello, world!\"" }, { "name": "Context Misses - Partial", "desc": "Failed context lookups should be considered falsey.", "data": {}, "template": "\"{{>*missing}}\"", "partials": { "missing": "Hello, world!" }, "expected": "\"\"" }, { "name": "Failed Lookup - Partial", "desc": "The empty string should be used when the named partial is not found.", "data": { "dynamic": "content" }, "template": "\"{{>*dynamic}}\"", "partials": { "foobar": "Hello, world!" }, "expected": "\"\"" }, { "name": "Context", "desc": "The dynamic partial should operate within the current context.", "data": { "text": "Hello, world!", "example": "partial" }, "template": "\"{{>*example}}\"", "partials": { "partial": "*{{text}}*" }, "expected": "\"*Hello, world!*\"" }, { "name": "Dotted Names", "desc": "The dynamic partial should operate within the current context.", "data": { "text": "Hello, world!", "foo": { "bar": { "baz": "partial" } } }, "template": "\"{{>*foo.bar.baz}}\"", "partials": { "partial": "*{{text}}*" }, "expected": "\"*Hello, world!*\"" }, { "name": "Dotted Names - Operator Precedence", "desc": "The dotted name should be resolved entirely before being dereferenced.", "data": { "text": "Hello, world!", "foo": "test", "test": { "bar": { "baz": "partial" } } }, "template": "\"{{>*foo.bar.baz}}\"", "partials": { "partial": "*{{text}}*" }, "expected": "\"\"" }, { "name": "Dotted Names - Failed Lookup", "desc": "The dynamic partial should operate within the current context.", "data": { "foo": { "text": "Hello, world!", "bar": { "baz": "partial" } } }, "template": "\"{{>*foo.bar.baz}}\"", "partials": { "partial": "*{{text}}*" }, "expected": "\"**\"" }, { "name": "Dotted names - Context Stacking", "desc": "Dotted names should not push a new frame on the context stack.", "data": { "section1": { "value": "section1" }, "section2": { "dynamic": "partial", "value": "section2" } }, "template": "{{#section1}}{{>*section2.dynamic}}{{/section1}}", "partials": { "partial": "\"{{value}}\"" }, "expected": "\"section1\"" }, { "name": "Dotted names - Context Stacking Under Repetition", "desc": "Dotted names should not push a new frame on the context stack.", "data": { "value": "test", "section1": [ 1, 2 ], "section2": { "dynamic": "partial", "value": "section2" } }, "template": "{{#section1}}{{>*section2.dynamic}}{{/section1}}", "partials": { "partial": "{{value}}" }, "expected": "testtest" }, { "name": "Dotted names - Context Stacking Failed Lookup", "desc": "Dotted names should resolve against the proper context stack.", "data": { "section1": [ 1, 2 ], "section2": { "dynamic": "partial", "value": "section2" } }, "template": "{{#section1}}{{>*section2.dynamic}}{{/section1}}", "partials": { "partial": "\"{{value}}\"" }, "expected": "\"\"\"\"" }, { "name": "Recursion", "desc": "Dynamic partials should properly recurse.", "data": { "template": "node", "content": "X", "nodes": [ { "content": "Y", "nodes": [] } ] }, "template": "{{>*template}}", "partials": { "node": "{{content}}<{{#nodes}}{{>*template}}{{/nodes}}>" }, "expected": "X>" }, { "name": "Dynamic Names - Dobule Dereferencing", "desc": "Dynamic Names can't be dereferenced more than once.", "data": { "dynamic": "test", "test": "content" }, "template": "\"{{>**dynamic}}\"", "partials": { "content": "Hello, world!" }, "expected": "\"\"" }, { "name": "Dynamic Names - Composed Dereferencing", "desc": "Dynamic Names cannot have composed dereferencing.", "data": { "foo": "fizz", "bar": "buzz", "fizz": { "buzz": { "content": null } } }, "template": "\"{{>*foo.*bar}}\"", "partials": { "content": "Hello, world!" }, "expected": "\"\"" }, { "name": "Surrounding Whitespace", "desc": "A dynamic partial should not alter surrounding whitespace; any\nwhitespace preceding the tag should be treated as indentation while any\nwhitespace succeding the tag should be left untouched.\n", "data": { "partial": "foobar" }, "template": "| {{>*partial}} |", "partials": { "foobar": "\t|\t" }, "expected": "| \t|\t |" }, { "name": "Inline Indentation", "desc": "Whitespace should be left untouched: whitespaces preceding the tag\nshould be treated as indentation.\n", "data": { "dynamic": "partial", "data": "|" }, "template": " {{data}} {{>*dynamic}}\n", "partials": { "partial": ">\n>" }, "expected": " | >\n>\n" }, { "name": "Standalone Line Endings", "desc": "\"\\r\\n\" should be considered a newline for standalone tags.", "data": { "dynamic": "partial" }, "template": "|\r\n{{>*dynamic}}\r\n|", "partials": { "partial": ">" }, "expected": "|\r\n>|" }, { "name": "Standalone Without Previous Line", "desc": "Standalone tags should not require a newline to precede them.", "data": { "dynamic": "partial" }, "template": " {{>*dynamic}}\n>", "partials": { "partial": ">\n>" }, "expected": " >\n >>" }, { "name": "Standalone Without Newline", "desc": "Standalone tags should not require a newline to follow them.", "data": { "dynamic": "partial" }, "template": ">\n {{>*dynamic}}", "partials": { "partial": ">\n>" }, "expected": ">\n >\n >" }, { "name": "Standalone Indentation", "desc": "Each line of the partial should be indented before rendering.", "data": { "dynamic": "partial", "content": "<\n->" }, "template": "\\\n {{>*dynamic}}\n/\n", "partials": { "partial": "|\n{{{content}}}\n|\n" }, "expected": "\\\n |\n <\n->\n |\n/\n" }, { "name": "Padding Whitespace", "desc": "Superfluous in-tag whitespace should be ignored.", "data": { "dynamic": "partial", "boolean": true }, "template": "|{{> * dynamic }}|", "partials": { "partial": "[]" }, "expected": "|[]|" } ] }