public class LocalRenderContext extends Object
If one template invokes another, they share a common GlobalRenderContext
but have their own LocalRenderContext
.
Also a local context knows its parent and can therefore output the render stack which is kind of a stacktrace for templates.
Modifier | Constructor and Description |
---|---|
protected |
LocalRenderContext(Template template,
GlobalRenderContext globalContext,
sirius.tagliatelle.rendering.StackAllocator.View locals)
Creates a new context.
|
Modifier and Type | Method and Description |
---|---|
LocalRenderContext |
createChildContext(Template template)
Creates a child context to invoke the given template.
|
LocalRenderContext |
createClosureContext()
Creates a closure context which can be put on the render stack as child, to provide access to the variables
of the enclosed context and to maintain a valid renderstack.
|
LocalRenderContext |
createInlineContext(Template template)
Creates an inline context which uses the same locals as this context but references another template.
|
boolean |
emitBlock(String name)
Emits the block with the given name.
|
Object |
getGlobal(int index)
Reads the global variable at the given index.
|
GlobalRenderContext |
getGlobalContext()
Provides access to the underlying global context.
|
Object |
getLocal(int index)
Reads the local variable at the given index.
|
protected sirius.tagliatelle.rendering.StackAllocator.View |
getLocals()
Contains the locals used by this context.
|
void |
outputEscaped(String content)
Adds escaped output to the result buffer.
|
void |
outputRaw(String content)
Adds unescaped output to the result buffer.
|
void |
release()
Releases this context.
|
Optional<Template> |
resolve(String templateName)
Resolves the given template.
|
void |
setBlocks(LocalRenderContext context,
Map<String,Emitter> blocks)
Specifies the blocks made available by the caller.
|
void |
setLocal(int index,
Object variable)
Assigns the given value to the given local variable.
|
String |
toString() |
void |
updatePosition(parsii.tokenizer.Position newPosition)
Updates the output position.
|
protected LocalRenderContext(Template template, GlobalRenderContext globalContext, sirius.tagliatelle.rendering.StackAllocator.View locals)
Use one of the helper methods to create a purpose built context.
template
- the template for which the context was created.globalContext
- the global and shared context for the render processlocals
- the local / stack variables. These can also be shared, if a closure (block included in
another template) is created.public LocalRenderContext createChildContext(Template template)
template
- the template which will be invokedpublic LocalRenderContext createClosureContext()
public LocalRenderContext createInlineContext(Template template)
This is just created to maintain a proper render stack in case of an error.
template
- the original template from which the inlined content was createdpublic void release()
public void outputRaw(String content) throws IOException
content
- the string to outputIOException
- in case of an IO erroroutputRaw(String)
public void outputEscaped(String content) throws IOException
Utilizes the current GlobalRenderContext.escaper
to escape the given string.
content
- the string to outputIOException
- in case of an IO error(String)
public void setLocal(int index, Object variable)
index
- the index of the local to assignvariable
- the value to assignpublic Object getGlobal(int index)
index
- the index in the environment list to readpublic Object getLocal(int index)
index
- the local index to readprotected sirius.tagliatelle.rendering.StackAllocator.View getLocals()
public Optional<Template> resolve(String templateName) throws CompileException
A local cache is maintained by the GlobalRenderContext
so that a previously resolved template is directly
re-used and not resolved several times.
templateName
- the name of the template to resolveCompileException
- in case the resolved template has compile errorspublic boolean emitBlock(String name) throws RenderException
name
- the name of the block to emitRenderException
- in case of an error when emitting the blockpublic void setBlocks(LocalRenderContext context, Map<String,Emitter> blocks)
context
- the context being enclosed along with the blocks to be restored later to access local variablesblocks
- the blocks passed to the template being renderedpublic void updatePosition(parsii.tokenizer.Position newPosition)
newPosition
- the position within the template being rendered.public GlobalRenderContext getGlobalContext()
Copyright © 2018. All rights reserved.