Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/conditional block #22

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions specs/conditionals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"\nConditional tags are used to check for truthyness/falsyness\nvalues. They are similar to section, but don't iterate. Also, an\nelse case can be specified.\n\nWhen and Unless tags SHOULD be treated as standalone when\nappropriate.\n","tests":[{"name":"Truthy When","data":{"value":true},"expected":"This should be rendered.","template":"{{?value}}This should be rendered.{{/value}}","desc":"Truthy Whens should have their contents rendered."},{"name":"Falsy When","data":{"value":false},"expected":"","template":"{{?value}}This should not be rendered.{{/value}}","desc":"Falsy Whens should not have their contents rendered."},{"name":"Falsy Unless","data":{"value":false},"expected":"This should be rendered.","template":"{{^value}}This should be rendered.{{/value}}","desc":"Falsy Unless should have their contents rendered."},{"name":"Truthy Unless","data":{"value":true},"expected":"","template":"{{^value}}This should not be rendered.{{/value}}","desc":"Truthy Unless should not have their contents rendered."},{"name":"When Unless aka If Then Else","data":{"value":true},"expected":"YES","template":"{{?value}}YES{{^value}}NO{{/value}}","desc":"When and Unless can be chained"},{"name":"When Unless aka If Then Else with Falsy value","data":{"value":false},"expected":"NO","template":"{{?value}}YES{{^value}}NO{{/value}}","desc":"When and Unless can be chained"},{"name":"When Unless aka If Then Else can be inverted","data":{"value":false},"expected":"NO","template":"{{^value}}NO{{?value}}YES{{/value}}","desc":"When and Unless can be inverted"},{"name":"When should not iterate","data":{"list":[{"item":1},{"item":2},{"item":3}],"item":"item"},"expected":"item","template":"{{?list}}{{item}}{{/list}}","desc":"When is not a section"},{"name":"Surrounding Whitespace","data":{"boolean":true},"expected":" | \t|\t | \n","template":" | {{?boolean}}\t|\t{{/boolean}} | \n","desc":"Whens should not alter surrounding whitespace."},{"name":"Internal Whitespace","data":{"boolean":true},"expected":" | \n | \n","template":" | {{?boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n","desc":"Whens should not alter internal whitespace."},{"name":"Indented Inline Sections","data":{"boolean":true},"expected":" YES\n GOOD\n","template":" {{?boolean}}YES{{/boolean}}\n {{?boolean}}GOOD{{/boolean}}\n","desc":"Single-line Whens should not alter surrounding whitespace."},{"name":"Standalone Lines","data":{"boolean":true},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n{{?boolean}}\n|\n{{/boolean}}\n| A Line\n","desc":"Standalone lines should be removed from the template."},{"name":"Indented Standalone Lines","data":{"boolean":true},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n {{?boolean}}\n|\n {{/boolean}}\n| A Line\n","desc":"Indented standalone lines should be removed from the template."},{"name":"Standalone Line Endings","data":{"boolean":true},"expected":"|\r\n|","template":"|\r\n{{?boolean}}\r\n{{/boolean}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{"boolean":true},"expected":"#\n/","template":" {{?boolean}}\n#{{/boolean}}\n/","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{"boolean":true},"expected":"#\n/\n","template":"#{{?boolean}}\n/\n {{/boolean}}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Padding","data":{"boolean":true},"expected":"|=|","template":"|{{? boolean }}={{/ boolean }}|","desc":"Superfluous in-tag whitespace should be ignored."}]}
134 changes: 134 additions & 0 deletions specs/conditionals.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
overview: |

Conditional tags are used to check for truthyness/falsyness
values. They are similar to section, but don't iterate. Also, an
else case can be specified.

When and Unless tags SHOULD be treated as standalone when
appropriate.
tests:
- name: Truthy When
desc: Truthy Whens should have their contents rendered.
data: { value: true }
template: '{{?value}}This should be rendered.{{/value}}'
expected: 'This should be rendered.'

- name: Falsy When
desc: Falsy Whens should not have their contents rendered.
data: { value: false }
template: '{{?value}}This should not be rendered.{{/value}}'
expected: ''

- name: Falsy Unless
desc: Falsy Unless should have their contents rendered.
data: { value: false }
template: '{{^value}}This should be rendered.{{/value}}'
expected: 'This should be rendered.'

- name: Truthy Unless
desc: Truthy Unless should not have their contents rendered.
data: { value: true }
template: '{{^value}}This should not be rendered.{{/value}}'
expected: ''

- name: When Unless aka If Then Else
desc: When and Unless can be chained
data: { value: true }
template: '{{?value}}YES{{^value}}NO{{/value}}'
expected: 'YES'

- name: When Unless aka If Then Else with Falsy value
desc: When and Unless can be chained
data: { value: false }
template: '{{?value}}YES{{^value}}NO{{/value}}'
expected: 'NO'

- name: When Unless aka If Then Else can be inverted
desc: When and Unless can be inverted
data: { value: false }
template: '{{^value}}NO{{?value}}YES{{/value}}'
expected: 'NO'

# No iteration

- name: When should not iterate
desc: When is not a section
data:
list: [ { item: 1 }, { item: 2 }, { item: 3 } ]
item: 'item'
template: '{{?list}}{{item}}{{/list}}'
expected: 'item'

# Whitespace Sensitivy
- name: Surrounding Whitespace
desc: Whens should not alter surrounding whitespace.
data: { boolean: true }
template: " | {{?boolean}}\t|\t{{/boolean}} | \n"
expected: " | \t|\t | \n"

- name: Internal Whitespace
desc: Whens should not alter internal whitespace.
data: { boolean: true }
template: " | {{?boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
expected: " | \n | \n"

- name: Indented Inline Sections
desc: Single-line Whens should not alter surrounding whitespace.
data: { boolean: true }
template: " {{?boolean}}YES{{/boolean}}\n {{?boolean}}GOOD{{/boolean}}\n"
expected: " YES\n GOOD\n"

- name: Standalone Lines
desc: Standalone lines should be removed from the template.
data: { boolean: true }
template: |
| This Is
{{?boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line

- name: Indented Standalone Lines
desc: Indented standalone lines should be removed from the template.
data: { boolean: true }
template: |
| This Is
{{?boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line

- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { boolean: true }
template: "|\r\n{{?boolean}}\r\n{{/boolean}}\r\n|"
expected: "|\r\n|"

- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { boolean: true }
template: " {{?boolean}}\n#{{/boolean}}\n/"
expected: "#\n/"

- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { boolean: true }
template: "#{{?boolean}}\n/\n {{/boolean}}"
expected: "#\n/\n"

# Whitespace Insensitivity

- name: Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { boolean: true }
template: '|{{? boolean }}={{/ boolean }}|'
expected: '|=|'

2 changes: 1 addition & 1 deletion specs/partials.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Partial tags are used to expand an external template into the current\ntemplate.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the partial to inject. Set Delimiter tags MUST NOT\naffect the parsing of a partial. The partial MUST be rendered against the\ncontext stack local to the tag. If the named partial cannot be found, the\nempty string SHOULD be used instead, as in interpolations.\n\nPartial tags SHOULD be treated as standalone when appropriate. If this tag\nis used standalone, any whitespace preceding the tag should treated as\nindentation, and prepended to each line of the partial before rendering.\n","tests":[{"name":"Basic Behavior","data":{},"expected":"\"from partial\"","template":"\"{{>text}}\"","desc":"The greater-than operator should expand to the named partial.","partials":{"text":"from partial"}},{"name":"Failed Lookup","data":{},"expected":"\"from partial\"","template":"\"{{>text}}\"","desc":"The empty string should be used when the named partial is not found.","partials":{}},{"name":"Context","data":{"text":"content"},"expected":"\"*content*\"","template":"\"{{>partial}}\"","desc":"The greater-than operator should operate within the current context.","partials":{"partial":"*{{text}}*"}},{"name":"Recursion","data":{"content":"X","nodes":[{"content":"Y","nodes":[]}]},"expected":"X<Y<>>","template":"{{>node}}","desc":"The greater-than operator should properly recurse.","partials":{"node":"{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"}},{"name":"Surrounding Whitespace","data":{},"expected":"| \t|\t |","template":"| {{>partial}} |","desc":"The greater-than operator should not alter surrounding whitespace.","partials":{"partial":"\t|\t"}},{"name":"Inline Indentation","data":{"data":"|"},"expected":" | >\n>\n","template":" {{data}} {{> partial}}\n","desc":"Whitespace should be left untouched.","partials":{"partial":">\n>"}},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n>|","template":"|\r\n{{>partial}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","partials":{"partial":">"}},{"name":"Standalone Without Previous Line","data":{},"expected":" >\n >>","template":" {{>partial}}\n>","desc":"Standalone tags should not require a newline to precede them.","partials":{"partial":">\n>"}},{"name":"Standalone Without Newline","data":{},"expected":">\n >\n >","template":">\n {{>partial}}","desc":"Standalone tags should not require a newline to follow them.","partials":{"partial":">\n>"}},{"name":"Standalone Indentation","data":{"content":"<\n->"},"expected":"\\\n |\n <\n->\n |\n/\n","template":"\\\n {{>partial}}\n/\n","desc":"Each line of the partial should be indented before rendering.","partials":{"partial":"|\n{{{content}}}\n|\n"}},{"name":"Padding Whitespace","data":{"boolean":true},"expected":"|[]|","template":"|{{> partial }}|","desc":"Superfluous in-tag whitespace should be ignored.","partials":{"partial":"[]"}}]}
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Partial tags are used to expand an external template into the current\ntemplate.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the partial to inject. Set Delimiter tags MUST NOT\naffect the parsing of a partial. The partial MUST be rendered against the\ncontext stack local to the tag. If the named partial cannot be found, the\nempty string SHOULD be used instead, as in interpolations.\n\nPartial tags SHOULD be treated as standalone when appropriate. If this tag\nis used standalone, any whitespace preceding the tag should treated as\nindentation, and prepended to each line of the partial before rendering.\n","tests":[{"name":"Basic Behavior","data":{},"expected":"\"from partial\"","template":"\"{{>text}}\"","desc":"The greater-than operator should expand to the named partial.","partials":{"text":"from partial"}},{"name":"Failed Lookup","data":{},"expected":"\"\"","template":"\"{{>text}}\"","desc":"The empty string should be used when the named partial is not found.","partials":{}},{"name":"Context","data":{"text":"content"},"expected":"\"*content*\"","template":"\"{{>partial}}\"","desc":"The greater-than operator should operate within the current context.","partials":{"partial":"*{{text}}*"}},{"name":"Recursion","data":{"content":"X","nodes":[{"content":"Y","nodes":[]}]},"expected":"X<Y<>>","template":"{{>node}}","desc":"The greater-than operator should properly recurse.","partials":{"node":"{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"}},{"name":"Surrounding Whitespace","data":{},"expected":"| \t|\t |","template":"| {{>partial}} |","desc":"The greater-than operator should not alter surrounding whitespace.","partials":{"partial":"\t|\t"}},{"name":"Inline Indentation","data":{"data":"|"},"expected":" | >\n>\n","template":" {{data}} {{> partial}}\n","desc":"Whitespace should be left untouched.","partials":{"partial":">\n>"}},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n>|","template":"|\r\n{{>partial}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","partials":{"partial":">"}},{"name":"Standalone Without Previous Line","data":{},"expected":" >\n >>","template":" {{>partial}}\n>","desc":"Standalone tags should not require a newline to precede them.","partials":{"partial":">\n>"}},{"name":"Standalone Without Newline","data":{},"expected":">\n >\n >","template":">\n {{>partial}}","desc":"Standalone tags should not require a newline to follow them.","partials":{"partial":">\n>"}},{"name":"Standalone Indentation","data":{"content":"<\n->"},"expected":"\\\n |\n <\n->\n |\n/\n","template":"\\\n {{>partial}}\n/\n","desc":"Each line of the partial should be indented before rendering.","partials":{"partial":"|\n{{{content}}}\n|\n"}},{"name":"Padding Whitespace","data":{"boolean":true},"expected":"|[]|","template":"|{{> partial }}|","desc":"Superfluous in-tag whitespace should be ignored.","partials":{"partial":"[]"}}]}
2 changes: 1 addition & 1 deletion specs/partials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tests:
data: { }
template: '"{{>text}}"'
partials: { }
expected: '"from partial"'
expected: '""'

- name: Context
desc: The greater-than operator should operate within the current context.
Expand Down