Skip to content

Commit a60f4d1

Browse files
committed
Populate and run ExecutionMode's prepareContext method
1 parent 7d009f5 commit a60f4d1

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public JinjavaInterpreter(
8383
this.config = renderConfig;
8484
this.application = application;
8585

86+
this.config.getExecutionMode().prepareContext(this.context);
87+
8688
switch (config.getRandomNumberGeneratorStrategy()) {
8789
case THREAD_LOCAL:
8890
random = ThreadLocalRandom.current();

src/main/java/com/hubspot/jinjava/mode/EagerExecutionMode.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.hubspot.jinjava.mode;
22

33
import com.hubspot.jinjava.interpret.Context;
4+
import com.hubspot.jinjava.lib.tag.eager.EagerTagDecorator;
5+
import com.hubspot.jinjava.lib.tag.eager.EagerTagFactory;
6+
import java.util.Optional;
47

58
public class EagerExecutionMode implements ExecutionMode {
69

@@ -11,6 +14,13 @@ public boolean isPreserveRawTags() {
1114

1215
@Override
1316
public void prepareContext(Context context) {
14-
// TODO register eager tags & expression node
17+
context
18+
.getAllTags()
19+
.stream()
20+
.filter(tag -> !(tag instanceof EagerTagDecorator))
21+
.map(tag -> EagerTagFactory.getEagerTagDecorator(tag.getClass()))
22+
.filter(Optional::isPresent)
23+
.forEach(maybeEagerTag -> context.registerTag(maybeEagerTag.get()));
24+
// TODO prepare expression node
1525
}
1626
}

src/test/java/com/hubspot/jinjava/EagerTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ public Optional<LocationResolver> getLocationResolver() {
7979
new ExpectedTemplateInterpreter(jinjava, interpreter, "eager");
8080
localContext = interpreter.getContext();
8181

82-
localContext
83-
.getAllTags()
84-
.stream()
85-
.map(tag -> EagerTagFactory.getEagerTagDecorator(tag.getClass()))
86-
.filter(Optional::isPresent)
87-
.forEach(maybeEagerTag -> localContext.registerTag(maybeEagerTag.get()));
88-
8982
localContext.put("deferred", DeferredValue.instance());
9083
localContext.put("resolved", "resolvedValue");
9184
localContext.put("dict", ImmutableSet.of("a", "b", "c"));
@@ -723,15 +716,6 @@ public void itWrapsCertainOutputInRaw() {
723716
config
724717
);
725718
JinjavaInterpreter noNestedInterpreter = new JinjavaInterpreter(parentInterpreter);
726-
noNestedInterpreter
727-
.getContext()
728-
.getAllTags()
729-
.stream()
730-
.map(tag -> EagerTagFactory.getEagerTagDecorator(tag.getClass()))
731-
.filter(Optional::isPresent)
732-
.forEach(
733-
maybeEagerTag -> noNestedInterpreter.getContext().registerTag(maybeEagerTag.get())
734-
);
735719

736720
JinjavaInterpreter.pushCurrent(noNestedInterpreter);
737721
try {

0 commit comments

Comments
 (0)