Skip to content
Draft
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
19 changes: 12 additions & 7 deletions src/main/java/com/hubspot/jinjava/LegacyOverrides.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@
@JinjavaImmutableStyle.WithStyle
public interface LegacyOverrides extends WithLegacyOverrides {
LegacyOverrides NONE = new Builder().build();
LegacyOverrides THREE_POINT_0 = new Builder()
.withEvaluateMapKeys(true)
.withIterateOverMapKeys(true)
.withUsePyishObjectMapper(true)
.withUseSnakeCasePropertyNaming(true)
.withUseNaturalOperatorPrecedence(true)
.withParseWhitespaceControlStrictly(true)
.withAllowAdjacentTextNodes(true)
.withUseTrimmingForNotesAndExpressions(true)
.withKeepNullableLoopValues(true)
.build();
LegacyOverrides ALL = new Builder()
.withEvaluateMapKeys(true)
.withIterateOverMapKeys(true)
.withUsePyishObjectMapper(true)
.withUseSnakeCasePropertyNaming(true)
.withWhitespaceRequiredWithinTokens(true)
.withUseNaturalOperatorPrecedence(true)
.withParseWhitespaceControlStrictly(true)
.withAllowAdjacentTextNodes(true)
Expand Down Expand Up @@ -44,11 +54,6 @@ default boolean isUseSnakeCasePropertyNaming() {
return false;
}

@Value.Default
default boolean isWhitespaceRequiredWithinTokens() {
return false;
}

@Value.Default
default boolean isUseNaturalOperatorPrecedence() {
return false;
Expand Down Expand Up @@ -77,7 +82,7 @@ default boolean isKeepNullableLoopValues() {
class Builder extends ImmutableLegacyOverrides.Builder {}

static Builder newBuilder() {
return builder();
return new Builder();
}

static Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ private Token getNextToken() {
if (
config
.getFeatures()
.isActive(BuiltInFeatures.WHITESPACE_REQUIRED_WITHIN_TOKENS) ||
config.getLegacyOverrides().isWhitespaceRequiredWithinTokens()
.isActive(BuiltInFeatures.WHITESPACE_REQUIRED_WITHIN_TOKENS)
) {
boolean hasNextChar = (currPost + 1) < length;
boolean nextCharIsWhitespace = hasNextChar && (' ' == is[currPost + 1]);
Expand Down
25 changes: 15 additions & 10 deletions src/test/java/com/hubspot/jinjava/tree/parse/TokenScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import com.hubspot.jinjava.JinjavaConfig;
import com.hubspot.jinjava.LegacyOverrides;
import com.hubspot.jinjava.features.BuiltInFeatures;
import com.hubspot.jinjava.features.FeatureConfig;
import com.hubspot.jinjava.features.FeatureStrategies;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -25,7 +27,7 @@ public class TokenScannerTest {

@Before
public void setup() {
config = JinjavaConfig.newBuilder().build();
config = JinjavaConfig.builder().build();
symbols = config.getTokenScannerSymbols();
}

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

LegacyOverrides legacyOverrides = LegacyOverrides
.newBuilder()
.withWhitespaceRequiredWithinTokens(true)
.build();
JinjavaConfig config = JinjavaConfig
.newBuilder()
.withLegacyOverrides(legacyOverrides)
.builder()
.withFeatureConfig(
FeatureConfig
.newBuilder()
.add(
BuiltInFeatures.WHITESPACE_REQUIRED_WITHIN_TOKENS,
FeatureStrategies.ACTIVE
)
.build()
)
.build();
TokenScanner scanner = fixture("comment-without-whitespace", config);
tokens = Lists.newArrayList(scanner);
Expand All @@ -299,8 +305,7 @@ public void testEscapedBackslashWithinAttrValue() {

@Test
public void testLstripBlocks() {
config =
JinjavaConfig.newBuilder().withLstripBlocks(true).withTrimBlocks(true).build();
config = JinjavaConfig.builder().withLstripBlocks(true).withTrimBlocks(true).build();

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