public class Template extends Object
Modifier and Type | Field and Description |
---|---|
protected List<TemplateArgument> |
arguments |
protected Emitter |
emitter |
protected String |
name |
protected Map<String,String> |
pragmas |
protected Resource |
resource |
Constructor and Description |
---|
Template(String name,
Resource resource)
Creates a new template with the given name (full path) and resource.
|
Modifier and Type | Method and Description |
---|---|
void |
addArgument(TemplateArgument arg)
Adds an argument to the template.
|
void |
addPragma(String name,
String value)
Adds a pragma which was detected while compiling.
|
List<TemplateArgument> |
getArguments()
Returns the list of arguments expected by the template.
|
double |
getAverageRenderTime()
Returns the average time it took to render the template.
|
LocalDateTime |
getCompilationTime()
Returns the compilation timestamp as
LocalDateTime . |
long |
getCompilationTimestamp()
Returns the timestamp when the template was last recompiled.
|
String |
getComplexity()
Returns the complexity of the template.
|
String |
getEffectiveFileName()
Contains the effective file name (without the .pasta suffix).
|
Emitter |
getEmitter()
Returns the emitter which represents the body of the template.
|
String |
getName()
Returns the name of the template.
|
int |
getNumInvocations()
Returns how many times the template was rendered since its compilation.
|
sirius.kernel.commons.Value |
getPragma(String name)
Reads the pragma with the given name.
|
Resource |
getResource()
Returns the resource which was used as input for the template.
|
LocalDateTime |
getResourceLastChanged()
Returns the timestamp when the underlying resource was last changed as
LocalDateTime . |
String |
getShortName()
Represents a short an readable name of the template used in error messages.
|
int |
getStackDepth()
Returns the stack depth required by this template.
|
boolean |
isConstant()
Determines if the contents of this template are completely constant.
|
void |
render(GlobalRenderContext ctx,
Object... args)
Returns the template using the given context and arguments.
|
String |
renderToString(Object... args)
Invokes the template and renders it into a string using the given arguments.
|
void |
renderWithContext(LocalRenderContext ctx)
Renders the template with the given local context.
|
String |
renderWithParams(sirius.kernel.commons.Context context)
Invokes the template and renders it into a string using the given arguments.
|
void |
setEmitter(Emitter emitter)
Sets the body of the template.
|
void |
setStackDepth(int stackDepth)
Sets the stack depth / number of local variables.
|
String |
toString() |
void |
transferArguments(Map<String,Object> args,
LocalRenderContext renderContext)
Reads all arguments from the given map into the given render context.
|
protected String name
protected Resource resource
protected Emitter emitter
protected List<TemplateArgument> arguments
public String getEffectiveFileName()
public void addArgument(TemplateArgument arg)
arg
- the argument to addpublic void addPragma(String name, String value)
name
- the name of the pragmavalue
- the value of the pragmapublic sirius.kernel.commons.Value getPragma(String name)
name
- the name of the pragma to readValue
or an empty value if no such pragma existspublic String renderToString(Object... args) throws RenderException
args
- the arguments to supplyRenderException
- in case of an error when creating the outputpublic String renderWithParams(sirius.kernel.commons.Context context) throws RenderException
context
- the arguments to supplyRenderException
- in case of an error when creating the outputpublic void transferArguments(Map<String,Object> args, LocalRenderContext renderContext) throws RenderException
Also, all given values are verified and default values are used, where required.
args
- the arguments to userenderContext
- the context to fillRenderException
- in case of invalid or missing argumentspublic void render(GlobalRenderContext ctx, Object... args) throws RenderException
ctx
- the context used to render the templateargs
- the arguments being supplied to the templateRenderException
- in case of an error when creating the outputpublic void renderWithContext(LocalRenderContext ctx) throws RenderException
ctx
- the local render contextRenderException
- in case of an error when creating the outputpublic boolean isConstant()
public long getCompilationTimestamp()
System.currentTimeMillis()
when the template was last compiledpublic List<TemplateArgument> getArguments()
public String getName()
public Resource getResource()
public LocalDateTime getCompilationTime()
LocalDateTime
.public LocalDateTime getResourceLastChanged()
LocalDateTime
.public int getNumInvocations()
public double getAverageRenderTime()
public String getComplexity()
The complexity is simply the number of emitters and number of expressions in a template.
public Emitter getEmitter()
public void setStackDepth(int stackDepth)
stackDepth
- the number of local variables / arguments required at runtimepublic int getStackDepth()
public void setEmitter(Emitter emitter)
emitter
- the emitter which represents the body of this templatepublic String getShortName()
This will most probably either render the name as tag if it is one or just output the filename instead of the full path, which is nonambiguous in the context or an error message.
Copyright © 2018. All rights reserved.