-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
Fix indent after if #650
Fix indent after if #650
Conversation
Hm, this is a little overzealous now if blocks don't contain direct text at all. Breaking Counterexample
Expected Output
Actual Output
|
Just had a quick look at the template of nested if case [src/registry.rs:789:9] &tpl = Template {
name: None,
elements: [
RawString(
"\n",
),
DecoratorBlock(
DecoratorTemplate {
name: Name(
"inline",
),
params: [
Literal(
String("nested_partial"),
),
],
hash: {},
template: Some(
Template {
name: None,
elements: [
RawString(
"<div>\n foobar\n</div>\n",
),
],
mapping: [
TemplateMapping(
3,
1,
),
],
},
),
indent: None,
},
),
RawString(
"",
),
DecoratorBlock(
DecoratorTemplate {
name: Name(
"inline",
),
params: [
Literal(
String("partial"),
),
],
hash: {},
template: Some(
Template {
name: None,
elements: [
RawString(
"<div>\n",
),
HelperBlock(
HelperTemplate {
name: Name(
"if",
),
params: [
Path(
Relative(
(
[
Named(
"foo",
),
],
"foo",
),
),
),
],
hash: {},
block_param: None,
template: Some(
Template {
name: None,
elements: [
Indent,
RawString(
"",
),
HelperBlock(
HelperTemplate {
name: Name(
"if",
),
params: [
Path(
Relative(
(
[
Named(
"foo",
),
],
"foo",
),
),
),
],
hash: {},
block_param: None,
template: Some(
Template {
name: None,
elements: [
Indent,
RawString(
" ",
),
PartialExpression(
DecoratorTemplate {
name: Name(
"nested_partial",
),
params: [],
hash: {},
template: None,
indent: Some(
" ",
),
},
),
RawString(
"",
),
],
mapping: [
TemplateMapping(
11,
5,
),
TemplateMapping(
11,
5,
),
TemplateMapping(
11,
5,
),
TemplateMapping(
12,
5,
),
],
},
),
inverse: None,
block: true,
chain: false,
},
),
RawString(
"",
),
],
mapping: [
TemplateMapping(
10,
5,
),
TemplateMapping(
10,
5,
),
TemplateMapping(
10,
5,
),
TemplateMapping(
13,
5,
),
],
},
),
inverse: None,
block: true,
chain: false,
},
),
Indent,
RawString(
"</div>\n",
),
],
mapping: [
TemplateMapping(
8,
1,
),
TemplateMapping(
9,
5,
),
TemplateMapping(
14,
1,
),
TemplateMapping(
14,
1,
),
],
},
),
indent: None,
},
),
RawString(
"<div>\n ",
),
PartialExpression(
DecoratorTemplate {
name: Name(
"partial",
),
params: [],
hash: {},
template: None,
indent: Some(
" ",
),
},
),
Indent,
RawString(
"</div>\n",
),
],
mapping: [
TemplateMapping(
1,
1,
),
TemplateMapping(
2,
1,
),
TemplateMapping(
7,
1,
),
TemplateMapping(
7,
1,
),
TemplateMapping(
16,
1,
),
TemplateMapping(
17,
5,
),
TemplateMapping(
18,
1,
),
TemplateMapping(
18,
1,
),
],
} Perhaps we want to avoid the |
Yep, that's the issue. The first {{if}} shouldn't indent, but the second one should, despite both containing a single nested block. The correct solution is probably to just make templates/partials themselves start with an Do you have a better idea? Otherwise I think I could get to trying this approach some time this week. |
Superseded by #654 |
Expands on #646 to fix indentation for
{{#if}}
blocks.Example Input
Output Before
Output Now