Modifier and Type | Field and Description |
---|---|
protected List<String> |
blockParams
Block param names.
|
protected Template |
body
The body template.
|
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 Helper<Object> |
helper
Helper.
|
protected Template |
inverse
Inverse section for if/else clauses.
|
protected int |
line
The line of this template.
|
protected String |
name
The section's name.
|
protected List<Param> |
params
The parameter list.
|
protected int |
paramSize
Param's size.
|
protected List<PathExpression> |
path
Compiled path for
name() . |
protected TagType |
tagType
Tag type, default: is
TagType.SECTION . |
Constructor and Description |
---|
BlockDecorator(Handlebars handlebars,
String name,
boolean inverted,
List<Param> params,
Map<String,Param> hash,
List<String> blockParams,
boolean root)
Creates a new
BlockDecorator . |
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.
|
Template |
body()
The template's body.
|
com.github.jknack.handlebars.internal.Block |
body(Template body)
Set the template body.
|
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.Block |
endDelimiter(String endDelimiter)
Set the end delimiter.
|
String |
filename() |
com.github.jknack.handlebars.internal.BaseTemplate |
filename(String filename)
Set the file's name.
|
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.
|
Template |
inverse()
The inverse template for else clauses.
|
Template |
inverse(String inverseLabel,
Template inverse)
Set the inverse template.
|
boolean |
inverted()
True if it's an inverted section.
|
protected void |
merge(Context context,
Writer writer)
Merge a child template into the writer.
|
String |
name()
The section'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()
Make/run any pending or required initialization.
|
String |
startDelimiter()
The start delimiter.
|
com.github.jknack.handlebars.internal.Block |
startDelimiter(String startDelimiter)
Set the start delimiter.
|
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.
|
protected Template body
protected final String name
protected Template inverse
protected TagType tagType
TagType.SECTION
.protected final List<PathExpression> path
name()
.protected int paramSize
protected int hashSize
protected final Handlebars handlebars
protected int line
protected int column
protected String filename
public BlockDecorator(Handlebars handlebars, String name, boolean inverted, List<Param> params, Map<String,Param> hash, List<String> blockParams, boolean root)
BlockDecorator
.handlebars
- The handlebars object.name
- The section's name.inverted
- True if it's inverted.params
- The parameter list.hash
- The hash.blockParams
- The block param names.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 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 boolean decorate()
protected void merge(Context context, Writer writer) throws IOException
context
- The scope object.writer
- The writer.IOException
- If a resource cannot be loaded.public String name()
public boolean inverted()
public com.github.jknack.handlebars.internal.Block body(Template body)
body
- The template body. Required.public Template inverse(String inverseLabel, Template inverse)
inverseLabel
- One of 'else' or '^'. Required.inverse
- The inverse template. Required.public Template inverse()
public com.github.jknack.handlebars.internal.Block endDelimiter(String endDelimiter)
endDelimiter
- The end delimiter.public com.github.jknack.handlebars.internal.Block startDelimiter(String startDelimiter)
startDelimiter
- The start delimiter.public Template body()
public String text()
Template
public String startDelimiter()
public String endDelimiter()
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]
protected void collect(Collection<String> result, TagType tagType)
result
- The result list.tagType
- The matching tagtype.public List<String> collectReferenceParameters()
Template
Usage:
{{#if v1}}{{/if}} {{#each v2 "test"}}{{/each}}
collectReferenceParameters()
returns [v1, v2]
collectReferenceParameters
in interface Template
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 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 String toJavaScript()
Template
toJavaScript
in interface Template
Copyright © 2021. All rights reserved.