Package com.github.jknack.handlebars
Class Context
java.lang.Object
com.github.jknack.handlebars.Context
Mustache/Handlebars are contextual template engines. This class represent the
'context stack' of a template.
- Objects and hashes should be pushed onto the context stack.
- All elements on the context stack should be accessible.
- Multiple sections per template should be permitted.
- Failed context lookups should be considered falsy.
- Dotted names should be valid for Section tags.
- Dotted names that cannot be resolved should be considered falsy.
- Dotted Names - Context Precedence: Dotted names should be resolved against former resolutions.
- Since:
- 0.1.0
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionInsert a new attribute in the context-stack.Insert all the attributes in the context-stack.static ContextCreates a new context but keep thedataattribute.<T> TRead the attribute from the data storage.Set an attribute in the data storage.Store the map in the data storage.voiddestroy()Destroy this context by cleaning up instance attributes.Lookup the given key inside the context stack.Lookup the given key inside the context stack.get(List<PathExpression> path) Lookup the given key inside the context stack.booleanfinal Objectmodel()Resolved as '.' or 'this' inside templates.static ContextCreates a new block param context.static Context.BuildernewBuilder(Context parent, Object model) Start a new context builder.static Context.BuildernewBuilder(Object model) Start a new context builder.static ContextnewContext(Context parent, Object model) Creates a new child context.static ContextnewContext(Object model) Creates a new root context.static ContextCreates a new partial context.final Contextparent()The parent context or null.List all the properties and values ofmodel().propertySet(Object context) List all the properties and values for the given object.toString()
-
Field Details
-
PARTIALS
The qualified name for partials. Internal use. -
INLINE_PARTIALS
Inline partials.- See Also:
-
INVOCATION_STACK
The qualified name for partials. Internal use. -
PARAM_SIZE
Number of parameters of a helper. Internal use. -
CALLEE
Last callee of a partial block. Internal use.
-
-
Method Details
-
combine
Insert a new attribute in the context-stack.- Parameters:
name- The attribute's name. Required.model- The model data.- Returns:
- This context.
-
combine
Insert all the attributes in the context-stack.- Parameters:
model- The model attributes.- Returns:
- This context.
-
data
Read the attribute from the data storage.- Type Parameters:
T- Data type.- Parameters:
name- The attribute's name.- Returns:
- The attribute value or null.
-
data
Set an attribute in the data storage.- Parameters:
name- The attribute's name. Required.value- The attribute's value. Required.- Returns:
- This context.
-
data
Store the map in the data storage.- Parameters:
attributes- The attributes to add. Required.- Returns:
- This context.
-
model
Resolved as '.' or 'this' inside templates.- Returns:
- The model or data.
-
parent
The parent context or null.- Returns:
- The parent context or null.
-
propertySet
List all the properties and values for the given object.- Parameters:
context- The context object.- Returns:
- All the properties and values for the given object.
-
propertySet
List all the properties and values ofmodel().- Returns:
- All the properties and values of
model().
-
isBlockParams
public boolean isBlockParams()- Returns:
- True, if this context is a block param context.
-
get
Lookup the given key inside the context stack.- Objects and hashes should be pushed onto the context stack.
- All elements on the context stack should be accessible.
- Multiple sections per template should be permitted.
- Failed context lookups should be considered falsey.
- Dotted names should be valid for Section tags.
- Dotted names that cannot be resolved should be considered falsey.
- Dotted Names - Context Precedence: Dotted names should be resolved against former resolutions.
- Parameters:
path- The object path.- Returns:
- The value associated to the given key or
nullif no value is found.
-
get
Lookup the given key inside the context stack.- Objects and hashes should be pushed onto the context stack.
- All elements on the context stack should be accessible.
- Multiple sections per template should be permitted.
- Failed context lookups should be considered falsey.
- Dotted names should be valid for Section tags.
- Dotted names that cannot be resolved should be considered falsey.
- Dotted Names - Context Precedence: Dotted names should be resolved against former resolutions.
- Parameters:
key- The object key.- Returns:
- The value associated to the given key or
nullif no value is found.
-
get
Lookup the given key inside the context stack.- Objects and hashes should be pushed onto the context stack.
- All elements on the context stack should be accessible.
- Multiple sections per template should be permitted.
- Failed context lookups should be considered falsey.
- Dotted names should be valid for Section tags.
- Dotted names that cannot be resolved should be considered falsey.
- Dotted Names - Context Precedence: Dotted names should be resolved against former resolutions.
- Parameters:
key- The object key.parentScopeResolution- False, if we want to restrict lookup to current scope.- Returns:
- The value associated to the given key or
nullif no value is found.
-
destroy
public void destroy()Destroy this context by cleaning up instance attributes. -
toString
-
newBuilder
Start a new context builder.- Parameters:
parent- The parent context. Required.model- The model data.- Returns:
- A new context builder.
-
newBuilder
Start a new context builder.- Parameters:
model- The model data.- Returns:
- A new context builder.
-
newContext
Creates a new child context.- Parameters:
parent- The parent context. Required.model- The model data.- Returns:
- A new child context.
-
newBlockParamContext
Creates a new block param context.- Parameters:
parent- The parent context. Required.names- A list of names to set in the block param context.values- A list of values to set in the block param context.- Returns:
- A new block param context.
-
newPartialContext
Creates a new partial context.- Parameters:
ctx- Current scope.scope- Scope switch.hash- Partial hash.- Returns:
- A new context.
-
newContext
Creates a new root context.- Parameters:
model- The model data.- Returns:
- A new root context.
-
copy
Creates a new context but keep thedataattribute.- Parameters:
context- Context to extract thedataattribute.model- A model/data.- Returns:
- A new context.
-