Skip to content

Commit 22bc4b3

Browse files
committed
Whitespace around {{else}} and {{^}} not stripped in pretty print mode fix #584
1 parent 0ba9c89 commit 22bc4b3

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

handlebars/src/main/java/com/github/jknack/handlebars/internal/MustacheSpec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public void enterUnless(final UnlessContext ctx) {
136136
hasTag(true);
137137
}
138138

139+
@Override public void enterElseBlock(HbsParser.ElseBlockContext ctx) {
140+
hasTag(true);
141+
}
142+
139143
@Override
140144
public void exitUnless(final UnlessContext ctx) {
141145
hasTag(true);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.github.jknack.handlebars.issues;
2+
3+
import com.github.jknack.handlebars.Handlebars;
4+
import com.github.jknack.handlebars.v4Test;
5+
import org.junit.Test;
6+
7+
import java.io.IOException;
8+
9+
public class Issue584 extends v4Test {
10+
11+
@Override protected void configure(Handlebars handlebars) {
12+
handlebars.setPrettyPrint(true);
13+
}
14+
15+
@Test
16+
public void shouldRemoveBlankAroundElse()
17+
throws IOException {
18+
shouldCompileTo("A\n"
19+
+ "{{#if someVariableWhichIsFalse}}\n"
20+
+ "B\n"
21+
+ "{{else}}\n"
22+
+ "C\n"
23+
+ "{{/if}}\n"
24+
+ "D", $, "A\n"
25+
+ "C\n"
26+
+ "D");
27+
28+
shouldCompileTo("A\n"
29+
+ "{{#if someVariableWhichIsFalse}}\n"
30+
+ "B\n"
31+
+ "{{^}}\n"
32+
+ "C\n"
33+
+ "{{/if}}\n"
34+
+ "D", $, "A\n"
35+
+ "C\n"
36+
+ "D");
37+
}
38+
39+
}

handlebars/src/test/resources/com/github/jknack/handlebars/helpers.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ tests:
179179
180180
expected: |
181181
<div class="entry">
182-
183182
<h1>Unknown Author</h1>
184183
</div>
185184

0 commit comments

Comments
 (0)