Package com.hubspot.jinjava.interpret
Class JinjavaInterpreter
java.lang.Object
com.hubspot.jinjava.interpret.JinjavaInterpreter
- All Implemented Interfaces:
PyWrapper
,PyishSerializable
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from interface com.hubspot.jinjava.objects.serialization.PyishSerializable
SELF_WRITER
-
Constructor Summary
ConstructorsConstructorDescriptionJinjavaInterpreter
(Jinjava application, Context context, JinjavaConfig renderConfig) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllChildErrors
(String childTemplateName, Collection<TemplateError> childErrors) void
addAllErrors
(Collection<TemplateError> other) Deprecated.void
void
addError
(TemplateError templateError) void
addExtendParentRoot
(Node root) <T extends Appendable & CharSequence>
TappendPyishString
(T appendable) Allows for a class to append the custom string representation in Jinjava.static void
checkOutputSize
(String string) void
void
Creates a new variable scope, extending from the current scope.enterScope
(Map<Context.Library, Set<String>> disabled) getAsString
(Object object) Deprecated.static JinjavaInterpreter
static Optional
<JinjavaInterpreter> int
int
getResource
(String resource) int
static boolean
isOutputTooLarge
(String string) boolean
void
static void
static void
pushCurrent
(JinjavaInterpreter interpreter) void
Render the given root node, processing extend parents.Render the given root node with an option to process extend parents.Parse the given string into a root Node, and then renders it processing extend parents.Parse the given string into a root Node, and then renders it processing extend parents.renderFlat
(String template) Parse the given string into a root Node, and then render it without processing any extend parents.renderFlat
(String template, long renderLimit) Parse the given string into a root Node, and then render it without processing any extend parents.resolveELExpression
(String expression, int lineNumber) Resolve expression against current context.resolveELExpression
(String expression, int lineNumber, int position) Resolve expression against current context.resolveELExpressionSilently
(String expression) Resolve expression against current context, but does not add the expression to the set of resolved expressions.resolveObject
(String variable, int lineNumber) resolveObject
(String variable, int lineNumber, int startPosition) Resolve a variable into an object value.resolveProperty
(Object object, String propertyName) Resolve property of bean.resolveProperty
(Object object, List<String> propertyNames) Resolve property of bean.resolveResourceLocation
(String location) resolveString
(String variable, int lineNumber) resolveString
(String variable, int lineNumber, int startPosition) Resolve a variable into a string value.retraceVariable
(String variable, int lineNumber) retraceVariable
(String variable, int lineNumber, int startPosition) Resolve a variable from the interpreter context, returning null if not found.void
setLineNumber
(int lineNumber) void
setPosition
(int position) void
startRender
(String name) Wrap an object in it's PyIsh equivalentMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.hubspot.jinjava.objects.serialization.PyishSerializable
writePyishSelf
-
Field Details
-
IGNORED_OUTPUT_FROM_EXTENDS_NOTE
- See Also:
-
OUTPUT_UNDEFINED_VARIABLES_ERROR
- See Also:
-
IGNORE_NESTED_INTERPRETATION_PARSE_ERRORS
- See Also:
-
-
Constructor Details
-
JinjavaInterpreter
-
JinjavaInterpreter
-
-
Method Details
-
checkOutputSize
-
isOutputTooLarge
-
getConfiguration
Deprecated.use {getConfig()
} -
addExtendParentRoot
-
addBlock
-
enterScope
Creates a new variable scope, extending from the current scope. Allows you to create a nested contextual scope which can override variables from higher levels.Should be used in a try/finally context, similar to lock-use patterns:
interpreter.enterScope(); try (interpreter.enterScope()) { // ... }
-
enterScope
public JinjavaInterpreter.InterpreterScopeClosable enterScope(Map<Context.Library, Set<String>> disabled) -
enterNonStackingScope
-
leaveScope
public void leaveScope() -
getRandom
-
isValidationMode
public boolean isValidationMode() -
getRevertibleObjects
-
parse
-
renderFlat
Parse the given string into a root Node, and then render it without processing any extend parents. This method should be used when the template is known to not have any extends or block tags.- Parameters:
template
- string to parse- Returns:
- rendered result
-
renderFlat
Parse the given string into a root Node, and then render it without processing any extend parents. This method should be used when the template is known to not have any extends or block tags.- Parameters:
template
- string to parserenderLimit
- stop rendering once this output length is reached- Returns:
- rendered result
-
render
Parse the given string into a root Node, and then renders it processing extend parents.- Parameters:
template
- string to parse- Returns:
- rendered result
-
render
Parse the given string into a root Node, and then renders it processing extend parents.- Parameters:
template
- string to parserenderLimit
- stop rendering once this output length is reached- Returns:
- rendered result
-
render
Render the given root node, processing extend parents. Equivalent to render(root, true)- Parameters:
root
- node to render- Returns:
- rendered result
-
render
Render the given root node with an option to process extend parents. Equivalent to render(root, processExtendRoots).- Parameters:
root
- node to renderprocessExtendRoots
-- Returns:
-
retraceVariable
Resolve a variable from the interpreter context, returning null if not found. This method updates the template error accumulators when a variable is not found.- Parameters:
variable
- name of variable in contextlineNumber
- current line number, for error reportingstartPosition
- current line position, for error reporting- Returns:
- resolved value for variable
-
retraceVariable
-
resolveObject
Resolve a variable into an object value. If given a string literal (e.g. 'foo' or "foo"), this method returns the literal unquoted. If the variable is undefined in the context, this method returns the given variable string.- Parameters:
variable
- name of variable in contextlineNumber
- current line number, for error reportingstartPosition
- current line position, for error reporting- Returns:
- resolved value for variable
-
resolveObject
-
resolveString
Resolve a variable into a string value. If given a string literal (e.g. 'foo' or "foo"), this method returns the literal unquoted. If the variable is undefined in the context, this method returns the given variable string.- Parameters:
variable
- name of variable in contextlineNumber
- current line number, for error reportingstartPosition
- current line position, for error reporting- Returns:
- resolved value for variable
-
getAsString
-
resolveString
-
getContext
-
resolveResourceLocation
-
getResource
- Throws:
IOException
-
getConfig
-
resolveELExpressionSilently
Resolve expression against current context, but does not add the expression to the set of resolved expressions.- Parameters:
expression
- Jinja expression.- Returns:
- Value of expression.
-
resolveELExpression
Resolve expression against current context.- Parameters:
expression
- Jinja expression.lineNumber
- Line number of expression.- Returns:
- Value of expression.
-
resolveELExpression
Resolve expression against current context. Also set the interpreter's position, useful for nodes that resolve multiple expressions such as a node using an IfTag and ElseTags.- Parameters:
expression
- Jinja expression.lineNumber
- Line number of expression.position
- Start position of expression.- Returns:
- Value of expression.
-
resolveProperty
Resolve property of bean.- Parameters:
object
- Bean.propertyName
- Name of property to resolve.- Returns:
- Value of property.
-
resolveProperty
Resolve property of bean.- Parameters:
object
- Bean.propertyNames
- Names of properties to resolve recursively.- Returns:
- Value of property.
-
wrap
Wrap an object in it's PyIsh equivalent- Parameters:
object
- Bean.- Returns:
- Wrapped bean.
-
getLineNumber
public int getLineNumber() -
setLineNumber
public void setLineNumber(int lineNumber) -
getPosition
public int getPosition() -
setPosition
public void setPosition(int position) -
getCurrentBlock
-
addError
-
removeLastError
public void removeLastError() -
getLastError
-
getScopeDepth
public int getScopeDepth() -
addAllErrors
Deprecated.UseaddAllChildErrors(String, Collection)
instead to fix error line numbers -
addAllChildErrors
-
getErrors
-
getErrorsCopy
-
getCurrent
-
getCurrentMaybe
-
pushCurrent
-
popCurrent
public static void popCurrent() -
startRender
-
endRender
-
endRender
-
appendPyishString
Description copied from interface:PyishSerializable
Allows for a class to append the custom string representation in Jinjava. This method will be used byPyishSerializable.writePyishSelf(JsonGenerator, SerializerProvider)
to specify what will be written to the json generator.- Specified by:
appendPyishString
in interfacePyishSerializable
- Parameters:
appendable
- Appendable to append the pyish string representation to.- Returns:
- The same appendable with an appended result
- Throws:
IOException
-
getConfig()
}