diff options
Diffstat (limited to 'specs/interpolation.yml')
-rw-r--r-- | specs/interpolation.yml | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/specs/interpolation.yml b/specs/interpolation.yml index 18dfd98..2237b55 100644 --- a/specs/interpolation.yml +++ b/specs/interpolation.yml @@ -7,13 +7,19 @@ overview: | 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) Walk the context stack from top to bottom, finding the first context + 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. - 2) If the context is a hash, the data is the value associated with the + 3) If the context is a hash, the data is the value associated with the name. - 3) If the context is an object, the data is the value returned by the + 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. @@ -115,6 +121,56 @@ tests: 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 |