Package com.hubspot.jinjava.util
Class EagerContextWatcher
- java.lang.Object
-
- com.hubspot.jinjava.util.EagerContextWatcher
-
@Beta public class EagerContextWatcher extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EagerContextWatcher.EagerChildContextConfig
-
Constructor Summary
Constructors Constructor Description EagerContextWatcher()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static EagerExecutionResult
executeInChildContext(Function<JinjavaInterpreter,EagerExpressionResolver.EagerExpressionResult> function, JinjavaInterpreter interpreter, EagerContextWatcher.EagerChildContextConfig eagerChildContextConfig)
Execute the specified functions within a protected context.
-
-
-
Method Detail
-
executeInChildContext
public static EagerExecutionResult executeInChildContext(Function<JinjavaInterpreter,EagerExpressionResolver.EagerExpressionResult> function, JinjavaInterpreter interpreter, EagerContextWatcher.EagerChildContextConfig eagerChildContextConfig)
Execute the specified functions within a protected context. Additionally, if the execution causes existing values on the context to become deferred, then their previous values will wrapped in aset
tag that gets prepended to the returned result. Thefunction
is run in deferredExecutionMode=true, where the context needs to be protected from having values updated or set, such as when evaluating both the positive and negative nodes in an if statement.- Parameters:
function
- Function to run within a "protected" child contextinterpreter
- JinjavaInterpreter to create a child from.eagerChildContextConfig
- Configuration for evaluation as defined inEagerContextWatcher.EagerChildContextConfig
- Returns:
- An
EagerExecutionResult
where:result
is the string result offunction
.prefixToPreserveState
is either blank or aset
tag that preserves the state within the output for a second rendering pass.
-
-