Modifier and Type | Field and Description |
---|---|
protected int |
column
The column of this template.
|
protected String |
filename
The file's name.
|
protected Handlebars |
handlebars
The handlebars object.
|
protected Map<String,Param> |
hash
The hash object.
|
protected int |
hashSize
Hash's size.
|
protected int |
line
The line of this template.
|
protected String |
name
The variable's name.
|
protected List<Param> |
params
The parameter list.
|
protected int |
paramSize
Param's size.
|
protected TagType |
type
The variable type.
|
Constructor and Description |
---|
VarDecorator(Handlebars handlebars,
String name,
TagType type,
List<Param> params,
Map<String,Param> hash,
boolean root)
Creates a new
VarDecorator . |
Modifier and Type | Method and Description |
---|---|
void |
after(Context context,
Writer writer)
Notify that template has been processed.
|
String |
apply(Context context)
Merge the template tree using the given context.
|
void |
apply(Context context,
Writer writer)
Merge the template tree using the given context.
|
String |
apply(Object context)
Merge the template tree using the given context.
|
void |
apply(Object context,
Writer writer)
Merge the template tree using the given context.
|
<T> TypeSafeTemplate<T> |
as()
Creates a new
TypeSafeTemplate . |
<T,S extends TypeSafeTemplate<T>> |
as(Class<S> rootType)
Creates a new
TypeSafeTemplate . |
void |
before(Context context,
Writer writer)
Notify that template is going to be processed.
|
protected void |
collect(Collection<String> result,
TagType tagType)
Child classes might want to check if they apply to the tagtype and append them self to the
result list.
|
List<String> |
collect(TagType... tagType)
Collect all the tag names under the given tagType.
|
List<String> |
collectReferenceParameters()
Collects all the parameters which are also variables.
|
protected void |
collectReferenceParameters(Collection<String> result) |
protected Object[] |
decoParams(Context ctx)
Build a parameter list by looking for values in the current context.
|
boolean |
decorate() |
protected Object |
determineContext(Context context)
Determine the current context.
|
String |
endDelimiter()
The end delimiter.
|
com.github.jknack.handlebars.internal.Variable |
endDelimiter(String endDelimiter)
Set the end delimiter.
|
String |
filename() |
com.github.jknack.handlebars.internal.BaseTemplate |
filename(String filename)
Set the file's name.
|
protected CharSequence |
formatAndEscape(Object value,
Formatter.Chain formatter)
Format and escape a var (if need it).
|
protected Map<String,Object> |
hash(Context context)
Build a hash object by looking for values in the current context.
|
com.github.jknack.handlebars.internal.HelperResolver |
hash(Map<String,Param> hash)
Set the hash.
|
protected String |
hashToString()
Make a string of
hash . |
protected Helper<Object> |
helper(String name)
Find the helper by it's name.
|
protected void |
merge(Context scope,
Writer writer)
Merge a child template into the writer.
|
String |
name()
The variable's name.
|
protected Object[] |
params(Context ctx)
Build a parameter list by looking for values in the current context.
|
com.github.jknack.handlebars.internal.HelperResolver |
params(List<Param> params)
Set the parameters.
|
protected String |
paramsToString(List<?> params)
Make a string of
params . |
int[] |
position() |
com.github.jknack.handlebars.internal.BaseTemplate |
position(int line,
int column)
Set the template position.
|
protected void |
postInit()
Apply any pending initialization.
|
String |
startDelimiter()
The start delimiter.
|
com.github.jknack.handlebars.internal.Variable |
startDelimiter(String startDelimiter)
Set the start delimiter.
|
protected String |
suffix() |
String |
text()
Provide the raw text.
|
String |
toJavaScript()
Convert this template to JavaScript template (a.k.a precompiled template).
|
String |
toString() |
static Object |
transform(Object candidate)
Transform the given value into something different or leave it as it is.
|
Object |
value(Context scope,
Writer writer)
Apply the template and return the raw value (not a CharSequence).
|
protected final String name
protected final TagType type
protected int paramSize
protected int hashSize
protected final Handlebars handlebars
protected int line
protected int column
protected String filename
public VarDecorator(Handlebars handlebars, String name, TagType type, List<Param> params, Map<String,Param> hash, boolean root)
VarDecorator
.handlebars
- The handlebars instance.name
- The variable's name. Required.type
- The variable's type. Required.params
- The variable's parameters. Required.hash
- The variable's hash. Required.root
- True, if this is top level decorator.protected void postInit()
public void before(Context context, Writer writer) throws IOException
context
- The context object. Required.writer
- The writer object. Required.IOException
- If a resource cannot be loaded.public void apply(Context context, Writer writer) throws IOException
Template
apply
in interface Template
context
- The context object. Required.writer
- The writer object. Required.IOException
- If a resource cannot be loaded.public boolean decorate()
protected String suffix()
public String name()
protected void merge(Context scope, Writer writer) throws IOException
scope
- The scope object.writer
- The writer.IOException
- If a resource cannot be loaded.public Object value(Context scope, Writer writer) throws IOException
scope
- Template scope.writer
- Writer.IOException
- If something goes wrong.protected void collect(Collection<String> result, TagType tagType)
result
- The result list.tagType
- The matching tagtype.protected CharSequence formatAndEscape(Object value, Formatter.Chain formatter)
value
- The variable's value.formatter
- Formatter to use.public String text()
Template
public com.github.jknack.handlebars.internal.Variable endDelimiter(String endDelimiter)
endDelimiter
- The end delimiter.public com.github.jknack.handlebars.internal.Variable startDelimiter(String startDelimiter)
startDelimiter
- The start delimiter.public String startDelimiter()
public String endDelimiter()
protected Map<String,Object> hash(Context context) throws IOException
context
- The current context.IOException
- If param can't be applied.protected Object[] params(Context ctx) throws IOException
ctx
- The current context.IOException
- If param can't be applied.protected Object[] decoParams(Context ctx) throws IOException
ctx
- The current context.IOException
- If param can't be applied.protected Object determineContext(Context context) throws IOException
context
- The current context.IOException
- If param can't be applied.public static final Object transform(Object candidate)
candidate
- The candidate value. May be null.protected Helper<Object> helper(String name)
name
- The helper's name.public com.github.jknack.handlebars.internal.HelperResolver hash(Map<String,Param> hash)
hash
- The new hash.public com.github.jknack.handlebars.internal.HelperResolver params(List<Param> params)
params
- The new params.protected String paramsToString(List<?> params)
params
.params
- list of params.params
.protected void collectReferenceParameters(Collection<String> result)
result
- The result list to add new parameters to.public final String apply(Object context) throws IOException
apply
in interface Template
context
- The context object. May be null.IOException
- If a resource cannot be loaded.public final void apply(Object context, Writer writer) throws IOException
apply
in interface Template
context
- The context object. May be null.writer
- The writer object. Required.IOException
- If a resource cannot be loaded.public String apply(Context context) throws IOException
Template
apply
in interface Template
context
- The context object. Required.IOException
- If a resource cannot be loaded.public void after(Context context, Writer writer) throws IOException
context
- The context object. Required.writer
- The writer object. Required.IOException
- If a resource cannot be loaded.public com.github.jknack.handlebars.internal.BaseTemplate filename(String filename)
filename
- The file's name.public String filename()
public int[] position()
public com.github.jknack.handlebars.internal.BaseTemplate position(int line, int column)
line
- The line.column
- The column.public <T,S extends TypeSafeTemplate<T>> S as(Class<S> rootType)
Template
TypeSafeTemplate
.as
in interface Template
T
- The root type.S
- The template type.rootType
- The template type. Required.TypeSafeTemplate
.public <T> TypeSafeTemplate<T> as()
Template
TypeSafeTemplate
.as
in interface Template
T
- The root type.TypeSafeTemplate
.public List<String> collect(TagType... tagType)
Template
Usage:
{{hello}} {{var 1}} {{{tripleVar}}}
collect(TagType.VAR)
returns [hello, var]
collect(TagType.TRIPLE_VAR)
returns [tripleVar]
collect(TagType.VAR, TagType.TRIPLE_VAR)
returns
[hello, var, tripleVar]
public List<String> collectReferenceParameters()
Template
Usage:
{{#if v1}}{{/if}} {{#each v2 "test"}}{{/each}}
collectReferenceParameters()
returns [v1, v2]
collectReferenceParameters
in interface Template
public String toJavaScript()
Template
toJavaScript
in interface Template
Copyright © 2021. All rights reserved.