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

Additional inheritance specs for block reindentation #131

Merged
merged 3 commits into from
Jan 26, 2024
Merged
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
56 changes: 56 additions & 0 deletions specs/~inheritance.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,62 @@
"parent": "{{#nested}}{{$block}}You say {{fruit}}.{{/block}}{{/nested}}"
},
"expected": "I say bananas."
},
{
"name": "Standalone parent",
"desc": "A parent's opening and closing tags need not be on separate lines in order to be standalone",
"data": {
},
"template": "Hi,\n {{<parent}}{{/parent}}\n",
"partials": {
"parent": "one\ntwo\n"
},
"expected": "Hi,\n one\n two\n"
},
{
"name": "Standalone block",
"desc": "A block's opening and closing tags need not be on separate lines in order to be standalone",
"data": {
},
"template": "{{<parent}}{{$block}}\none\ntwo{{/block}}\n{{/parent}}\n",
"partials": {
"parent": "Hi,\n {{$block}}{{/block}}\n"
},
"expected": "Hi,\n one\n two\n"
},
{
"name": "Block reindentation",
"desc": "Block indentation is removed at the site of definition and added at the site of expansion",
"data": {
},
"template": "{{<parent}}{{$block}}\n one\n two\n{{/block}}{{/parent}}\n",
"partials": {
"parent": "Hi,\n {{$block}}\n {{/block}}\n"
},
"expected": "Hi,\n one\n two\n"
},
{
"name": "Intrinsic indentation",
"desc": "When the block opening tag is standalone, indentation is determined by default content",
"data": {
},
"template": "{{<parent}}{{$block}}\none\ntwo\n{{/block}}{{/parent}}\n",
"partials": {
"parent": "Hi,\n{{$block}}\n default\n{{/block}}\n"
},
"expected": "Hi,\n one\n two\n"
},
{
"name": "Nested block reindentation",
"desc": "Nested blocks are reindented relative to the surrounding block",
"data": {
},
"template": "{{<parent}}{{$nested}}\nthree\n{{/nested}}{{/parent}}\n",
"partials": {
"parent": "{{<grandparent}}{{$block}}\n one\n {{$nested}}\n two\n {{/nested}}\n{{/block}}{{/grandparent}}\n",
"grandparent": "{{$block}}default{{/block}}"
},
"expected": "one\n three\n"
}
]
}
89 changes: 89 additions & 0 deletions specs/~inheritance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,92 @@ tests:
partials:
parent: "{{#nested}}{{$block}}You say {{fruit}}.{{/block}}{{/nested}}"
expected: I say bananas.

- name: Standalone parent
desc: A parent's opening and closing tags need not be on separate lines in order to be standalone
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, this pair of tags behaves exactly like a single standalone partial tag.

data: {}
template: |
Hi,
{{<parent}}{{/parent}}
partials:
parent: |
one
two
expected: |
Hi,
one
two

- name: Standalone block
desc: A block's opening and closing tags need not be on separate lines in order to be standalone
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is however not exactly the same as a single standalone partial tag, because that would conflict with the existing "Inherit indentation" spec on lines 154-164. "Standalone" here mostly refers to whether the block as a whole will be indented. Contrary to the previous spec, if the end section tag is not standalone by itself, then the trailing newline will not be removed from the output if the block ends up being empty.

data: {}
template: |
{{<parent}}{{$block}}
one
two{{/block}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this little tweak I had to make here. If I had put the {{/block}} at the start of the next line instead, I would have to include double newlines at the end of the expected output, for consistency with the pre-existing "Inherit indentation" spec.

{{/parent}}
partials:
parent: |
Hi,
{{$block}}{{/block}}
expected: |
Hi,
one
two

- name: Block reindentation
desc: Block indentation is removed at the site of definition and added at the site of expansion
data: {}
template: |
{{<parent}}{{$block}}
one
two
{{/block}}{{/parent}}
partials:
parent: |
Hi,
{{$block}}
{{/block}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I'm avoiding the double newline problem by making the block tag and the end section tag standalone by themselves, so their trailing newlines are removed from the output.

expected: |
Hi,
one
two

- name: Intrinsic indentation
desc: When the block opening tag is standalone, indentation is determined by default content
data: {}
template: |
{{<parent}}{{$block}}
one
two
{{/block}}{{/parent}}
partials:
parent: |
Hi,
{{$block}}
default
{{/block}}
expected: |
Hi,
one
two

- name: Nested block reindentation
desc: Nested blocks are reindented relative to the surrounding block
data: {}
template: |
{{<parent}}{{$nested}}
three
{{/nested}}{{/parent}}
partials:
parent: |
{{<grandparent}}{{$block}}
one
{{$nested}}
two
{{/nested}}
{{/block}}{{/grandparent}}
grandparent: "{{$block}}default{{/block}}"
expected: |
one
three