summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranomal00us <95467104+anomal00us@users.noreply.github.com>2021-12-04 17:15:10 +0100
committerGitHub <noreply@github.com>2021-12-04 17:15:10 +0100
commit7da3ef2cfea6bc3d66a095ec3ae1e75bff9dcbbe (patch)
tree2f5e70a9bcf56c0365aac1f593dd30d6de8f6063
parent45650e76ef5e8fc961337f5a8f0d2a774b6e5722 (diff)
downloadmustache-spec-7da3ef2cfea6bc3d66a095ec3ae1e75bff9dcbbe.tar.gz
Dynamic partials (json)
-rw-r--r--specs/dynamic.json147
1 files changed, 147 insertions, 0 deletions
diff --git a/specs/dynamic.json b/specs/dynamic.json
new file mode 100644
index 0000000..8fa5cf4
--- /dev/null
+++ b/specs/dynamic.json
@@ -0,0 +1,147 @@
+{
+ "overview": "Dynamic partials tags are used to dynamically expand an external template into\nthe current template.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names a key in the context whose value is the name of the\npartial that will be loaded. If the dynamically named partial cannot be found,\nthe empty string SHOULD be used instead, as in interpolations. Set Delimiter\ntags MUST NOT affect the parsing of a partial. The partial MUST be rendered\nagainst the context stack local to the tag. Failed resolutions of the key\n(context lookups) should be considered falsey and should interpolate as the\nempty string. If the partial, whose name is retrieved from the context stack,\ncannot be found, the empty string SHOULD be used instead, as in\ninterpolations.\n\nDynamic partial tags SHOULD be treated as standalone when appropriate. If\nthis tag is used standalone, any whitespace preceding the tag should treated\nas indentation, and prepended to each line of the partial before rendering.\n",
+ "tests": [
+ {
+ "name": "Basic Behavior",
+ "desc": "The asterisk operator is used for dynamic partials.",
+ "data": {
+ "dynamic": "content"
+ },
+ "template": "\"{{*dynamic}}\"",
+ "partials": {
+ "content": "Hello, world!"
+ },
+ "expected": "\"Hello, world!\""
+ },
+ {
+ "name": "Context Misses",
+ "desc": "Failed context lookups should be considered falsey.",
+ "data": {},
+ "template": "\"{{*missing}}\"",
+ "partials": {},
+ "expected": "\"\""
+ },
+ {
+ "name": "Failed Lookup",
+ "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 asterisk operator should operate within the current context.",
+ "data": {
+ "text": "Hello, world!",
+ "example": "partial"
+ },
+ "template": "\"{{*example}}\"",
+ "partials": {
+ "partial": "*{{text}}*"
+ },
+ "expected": "\"*Hello, world!*\""
+ },
+ {
+ "name": "Recursion",
+ "desc": "The asterisk operator should properly recurse.",
+ "data": "{\n template: 'node',\n content: 'X',\n nodes: [ { content: 'Y', nodes: [] } ]\n}\n",
+ "template": "{{*template}}",
+ "partials": {
+ "node": "{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"
+ },
+ "expected": "X<Y<>>"
+ },
+ {
+ "name": "Surrounding Whitespace",
+ "desc": "The asterisk operator should not alter surrounding whitespace.",
+ "data": {
+ "partial": "foobar"
+ },
+ "template": "| {{*partial}} |",
+ "partials": {
+ "foobar": "\t|\t"
+ },
+ "expected": "| \t|\t |"
+ },
+ {
+ "name": "Inline Indentation",
+ "desc": "Whitespace should be left untouched.",
+ "data": {
+ "dynamic": "partial",
+ "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": {
+ "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": "|[]|"
+ }
+ ]
+}