Skip to content

Commit e5fba60

Browse files
committed
Add 3.0 version of LegacyOverrides, that will be turned on by default.
Remove isWhitespaceRequiredWithinTokens option as it is a BuiltinFeature now
1 parent ebeb04f commit e5fba60

3 files changed

Lines changed: 28 additions & 19 deletions

File tree

src/main/java/com/hubspot/jinjava/LegacyOverrides.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@
1111
@JinjavaImmutableStyle.WithStyle
1212
public interface LegacyOverrides extends WithLegacyOverrides {
1313
LegacyOverrides NONE = new Builder().build();
14+
LegacyOverrides THREE_POINT_0 = new Builder()
15+
.withEvaluateMapKeys(true)
16+
.withIterateOverMapKeys(true)
17+
.withUsePyishObjectMapper(true)
18+
.withUseSnakeCasePropertyNaming(true)
19+
.withUseNaturalOperatorPrecedence(true)
20+
.withParseWhitespaceControlStrictly(true)
21+
.withAllowAdjacentTextNodes(true)
22+
.withUseTrimmingForNotesAndExpressions(true)
23+
.withKeepNullableLoopValues(true)
24+
.build();
1425
LegacyOverrides ALL = new Builder()
1526
.withEvaluateMapKeys(true)
1627
.withIterateOverMapKeys(true)
1728
.withUsePyishObjectMapper(true)
1829
.withUseSnakeCasePropertyNaming(true)
19-
.withWhitespaceRequiredWithinTokens(true)
2030
.withUseNaturalOperatorPrecedence(true)
2131
.withParseWhitespaceControlStrictly(true)
2232
.withAllowAdjacentTextNodes(true)
@@ -44,11 +54,6 @@ default boolean isUseSnakeCasePropertyNaming() {
4454
return false;
4555
}
4656

47-
@Value.Default
48-
default boolean isWhitespaceRequiredWithinTokens() {
49-
return false;
50-
}
51-
5257
@Value.Default
5358
default boolean isUseNaturalOperatorPrecedence() {
5459
return false;
@@ -77,7 +82,7 @@ default boolean isKeepNullableLoopValues() {
7782
class Builder extends ImmutableLegacyOverrides.Builder {}
7883

7984
static Builder newBuilder() {
80-
return builder();
85+
return new Builder();
8186
}
8287

8388
static Builder builder() {

src/main/java/com/hubspot/jinjava/tree/parse/TokenScanner.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ private Token getNextToken() {
9797
if (
9898
config
9999
.getFeatures()
100-
.isActive(BuiltInFeatures.WHITESPACE_REQUIRED_WITHIN_TOKENS) ||
101-
config.getLegacyOverrides().isWhitespaceRequiredWithinTokens()
100+
.isActive(BuiltInFeatures.WHITESPACE_REQUIRED_WITHIN_TOKENS)
102101
) {
103102
boolean hasNextChar = (currPost + 1) < length;
104103
boolean nextCharIsWhitespace = hasNextChar && (' ' == is[currPost + 1]);

src/test/java/com/hubspot/jinjava/tree/parse/TokenScannerTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.google.common.collect.Lists;
88
import com.google.common.io.Resources;
99
import com.hubspot.jinjava.JinjavaConfig;
10-
import com.hubspot.jinjava.LegacyOverrides;
10+
import com.hubspot.jinjava.features.BuiltInFeatures;
11+
import com.hubspot.jinjava.features.FeatureConfig;
12+
import com.hubspot.jinjava.features.FeatureStrategies;
1113
import java.nio.charset.StandardCharsets;
1214
import java.util.List;
1315
import java.util.stream.Collectors;
@@ -25,7 +27,7 @@ public class TokenScannerTest {
2527

2628
@Before
2729
public void setup() {
28-
config = JinjavaConfig.newBuilder().build();
30+
config = JinjavaConfig.builder().build();
2931
symbols = config.getTokenScannerSymbols();
3032
}
3133

@@ -266,13 +268,17 @@ public void testCommentWithWhitespaceChar() {
266268
List<Token> tokens = tokens("comment-without-whitespace");
267269
assertThat(tokens.get(0).content.trim()).isEqualTo("$");
268270

269-
LegacyOverrides legacyOverrides = LegacyOverrides
270-
.newBuilder()
271-
.withWhitespaceRequiredWithinTokens(true)
272-
.build();
273271
JinjavaConfig config = JinjavaConfig
274-
.newBuilder()
275-
.withLegacyOverrides(legacyOverrides)
272+
.builder()
273+
.withFeatureConfig(
274+
FeatureConfig
275+
.newBuilder()
276+
.add(
277+
BuiltInFeatures.WHITESPACE_REQUIRED_WITHIN_TOKENS,
278+
FeatureStrategies.ACTIVE
279+
)
280+
.build()
281+
)
276282
.build();
277283
TokenScanner scanner = fixture("comment-without-whitespace", config);
278284
tokens = Lists.newArrayList(scanner);
@@ -299,8 +305,7 @@ public void testEscapedBackslashWithinAttrValue() {
299305

300306
@Test
301307
public void testLstripBlocks() {
302-
config =
303-
JinjavaConfig.newBuilder().withLstripBlocks(true).withTrimBlocks(true).build();
308+
config = JinjavaConfig.builder().withLstripBlocks(true).withTrimBlocks(true).build();
304309

305310
List<Token> tokens = tokens("tag-with-trim-chars");
306311
assertThat(tokens).isNotEmpty();

0 commit comments

Comments
 (0)