summaryrefslogtreecommitdiff
path: root/specs/sections.yml
diff options
context:
space:
mode:
Diffstat (limited to 'specs/sections.yml')
-rw-r--r--specs/sections.yml42
1 files changed, 37 insertions, 5 deletions
diff --git a/specs/sections.yml b/specs/sections.yml
index 30815c9..2d1e982 100644
--- a/specs/sections.yml
+++ b/specs/sections.yml
@@ -53,14 +53,42 @@ tests:
template: '"{{#context}}Hi {{name}}.{{/context}}"'
expected: '"Hi Joe."'
+ - name: Parent contexts
+ desc: Names missing in the current context are looked up in the stack.
+ data: { a: "foo", b: "wrong", sec: { b: "bar" }, c : { d : "baz" } }
+ template: '"{{#sec}}{{a}}, {{b}}, {{c.d}}{{/sec}}"'
+ expected: '"foo, bar, baz"'
+
+ - name: Variable test
+ desc: |
+ Non-false sections have their value at the top of context,
+ accessible as {{.}} or through the parent context. This gives
+ a simple way to display content conditionally if a variable exists.
+ data: { foo: "bar" }
+ template: '"{{#foo}} {{.}} is {{foo}} {{/foo}}"'
+ expected: '"bar is bar"'
+
+ - name: List Contexts
+ desc: All elements on the context stack should be accessible within lists.
+ data:
+ tops:
+ - tname:
+ upper: "A"
+ lower: "a"
+ middles:
+ - mname: "1"
+ bottoms:
+ - bname: "x"
+ - bname: "y"
+ template: '{{#tops}}{{#middles}}{{tname.lower}}{{mname}}.{{#bottoms}}{{tname.upper}}{{mname}}{{bname}}.{{/bottoms}}{{/middles}}{{/tops}}'
+ expected: 'a1.A1x.A1y.'
+
- 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 }
+ c: { three: 3, d : { four : 4, five : 5 } }
template: |
{{#a}}
{{one}}
@@ -70,9 +98,11 @@ tests:
{{one}}{{two}}{{three}}{{two}}{{one}}
{{#d}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
- {{#e}}
+ {{#five}}
{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
- {{/e}}
+ {{one}}{{two}}{{three}}{{four}}{{.}}6{{.}}{{four}}{{three}}{{two}}{{one}}
+ {{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
+ {{/five}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
{{/d}}
{{one}}{{two}}{{three}}{{two}}{{one}}
@@ -87,6 +117,8 @@ tests:
12321
1234321
123454321
+ 12345654321
+ 123454321
1234321
12321
121