summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranomal00us <95467104+anomal00us@users.noreply.github.com>2022-07-21 14:45:23 +0200
committerroot <root@delphi.lan>2022-08-08 21:08:27 +0200
commit6e9b75d723b081048dd5dd863c31cd650a67b2a0 (patch)
tree1ee159ce4ac9d188f86e7c5aea5b1a779bb1f98e
parent956cfa41988cc1b59892a495d5072adaa3791e38 (diff)
downloadmustache-spec-6e9b75d723b081048dd5dd863c31cd650a67b2a0.tar.gz
adding rationale and a new test
-rw-r--r--specs/~dynamic-names.json16
-rw-r--r--specs/~dynamic-names.yml17
2 files changed, 32 insertions, 1 deletions
diff --git a/specs/~dynamic-names.json b/specs/~dynamic-names.json
index 93ea278..84a5473 100644
--- a/specs/~dynamic-names.json
+++ b/specs/~dynamic-names.json
@@ -1,5 +1,5 @@
{
- "overview": "Dynamic 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 latter follows the same notation as in an\nInterpolation tag.\n\nThis tag's dotted name, which is equal to the Dynamic Name excluding the\nleading asterisk, refers to 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",
+ "overview": "Rationale: this special notation was introduced specifically to allow the\ndynamic loading of partials. Although there are already solutions that allow\nto dynamically load partials possible, these solutions either require the use\nof optional (and complex) features such as lambdas, or require mechanisms that\nin interpreted programming languages are rather tedious to implement and are\nalso rather inefficient, both in terms of space, due to a possible necessary\noverhead of the included partials, and in terms of computational efficiency,\nregarding a possible necessary pre-buffering.\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 latter follows the same notation as in an\nInterpolation tag.\n\nThis tag's dotted name, which is equal to the Dynamic Name excluding the\nleading asterisk, refers to 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",
@@ -14,6 +14,20 @@
"expected": "\"Hello, world!\""
},
{
+ "name": "Basic Behavior - Name Resolution",
+ "desc": "The asterisk is not part of the name that will be resolved in the contex.\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": {},
diff --git a/specs/~dynamic-names.yml b/specs/~dynamic-names.yml
index a9bf913..c7bf7ab 100644
--- a/specs/~dynamic-names.yml
+++ b/specs/~dynamic-names.yml
@@ -1,4 +1,13 @@
overview: |
+ Rationale: this special notation was introduced specifically to allow the
+ dynamic loading of partials. Although there are already solutions that allow
+ to dynamically load partials possible, these solutions either require the use
+ of optional (and complex) features such as lambdas, or require mechanisms that
+ in interpreted programming languages are rather tedious to implement and are
+ also rather inefficient, both in terms of space, due to a possible necessary
+ overhead of the included partials, and in terms of computational efficiency,
+ regarding a possible necessary pre-buffering.
+
Dynamic Names are a special notation to dynamically determine a tag's content.
Dynamic Names MUST be a non-whitespace character sequence NOT containing
@@ -29,6 +38,14 @@ tests:
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 contex.
+ 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: { }