public class Options
extends java.lang.Object
Helper.apply(Object, Options)
.
Usage:
Options options = new Options.Builder(handlebars, context, fn) .build();Optionally you can set parameters and hash table:
Options options = new Options.Builder(handlebars, context, fn) .setParams(new Object[] {}) .setHash(hash) .build();
Modifier and Type | Class and Description |
---|---|
static interface |
Options.Buffer
Buffer like use it to increase rendering time while using helpers.
|
static class |
Options.Builder
An
Options builder. |
static class |
Options.InMemoryBuffer
A
StringBuilder implementation. |
static class |
Options.NativeBuffer
This buffer will write into the underlying writer.
|
Modifier and Type | Field and Description |
---|---|
java.util.List<java.lang.String> |
blockParams
Block param names.
|
Context |
context
The current context.
|
Template |
fn
The current template.
|
Handlebars |
handlebars
The
Handlebars object. |
java.util.Map<java.lang.String,java.lang.Object> |
hash
The hash options.
|
java.lang.String |
helperName
The name of the helper.
|
Template |
inverse
The current inverse template.
|
java.lang.Object[] |
params
The parameters.
|
TagType |
tagType
The
TagType from where the helper was called. |
Constructor and Description |
---|
Options(Handlebars handlebars,
java.lang.String helperName,
TagType tagType,
Context context,
Template fn,
Template inverse,
java.lang.Object[] params,
java.util.Map<java.lang.String,java.lang.Object> hash,
java.util.List<java.lang.String> blockParams)
Creates a new Handlebars
Options . |
Options(Handlebars handlebars,
java.lang.String helperName,
TagType tagType,
Context context,
Template fn,
Template inverse,
java.lang.Object[] params,
java.util.Map<java.lang.String,java.lang.Object> hash,
java.util.List<java.lang.String> blockParams,
java.io.Writer writer)
Creates a new Handlebars
Options . |
Modifier and Type | Method and Description |
---|---|
java.lang.CharSequence |
apply(Template template)
Apply the given template to the default context.
|
java.lang.CharSequence |
apply(Template template,
Context context)
Apply the given template to the provided context.
|
java.lang.CharSequence |
apply(Template template,
Context context,
java.util.List<java.lang.Object> blockParams)
Apply the given template to the provided context.
|
java.lang.CharSequence |
apply(Template template,
java.lang.Object context)
Apply the given template to the provided context.
|
java.lang.CharSequence |
apply(Template template,
java.lang.Object context,
java.util.List<java.lang.Object> blockParams)
Apply the given template to the provided context.
|
Options.Buffer |
buffer()
Get a Buffer which probably increase rendering time (performance).
|
<T> T |
data(java.lang.String name)
Read the attribute from the data storage.
|
void |
data(java.lang.String name,
java.lang.Object value)
Set an attribute in the data storage.
|
java.lang.CharSequence |
fn()
Apply the
fn template using the default context. |
java.lang.CharSequence |
fn(Context context)
Apply the
fn template using the provided context. |
java.lang.CharSequence |
fn(java.lang.Object context)
Apply the
fn template using the provided context. |
<T> T |
get(java.lang.String name)
Look for a value in the context's stack.
|
<T> T |
get(java.lang.String name,
T defaultValue)
Look for a value in the context's stack.
|
<T> T |
hash(java.lang.String name)
Find a value inside the
hash attributes. |
<T> T |
hash(java.lang.String name,
java.lang.Object defaultValue)
Find a value inside the
hash attributes. |
java.lang.CharSequence |
inverse()
Apply the
inverse template using the default context. |
java.lang.CharSequence |
inverse(Context context)
Apply the
inverse template using the provided context. |
java.lang.CharSequence |
inverse(java.lang.Object context)
Apply the
inverse template using the provided context. |
boolean |
isFalsy(java.lang.Object value)
Returns false if its argument is false, null or empty list/array (a "falsy"
value).
|
<T> T |
param(int index)
Return a parameter at given index.
|
<T> T |
param(int index,
T defaultValue)
Return a parameter at given index.
|
Template |
partial(java.lang.String path)
Return a previously registered partial in the current execution context.
|
void |
partial(java.lang.String path,
Template partial)
Store a partial in the current execution context.
|
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
propertySet(java.lang.Object context)
List all the properties and their values for the given object.
|
Context |
wrap(java.lang.Object model)
Creates a
Context from the given model. |
public final Handlebars handlebars
Handlebars
object. Not null.public final Context context
public final Template fn
public final Template inverse
public final java.lang.Object[] params
public final java.util.Map<java.lang.String,java.lang.Object> hash
public final java.lang.String helperName
public final java.util.List<java.lang.String> blockParams
public Options(Handlebars handlebars, java.lang.String helperName, TagType tagType, Context context, Template fn, Template inverse, java.lang.Object[] params, java.util.Map<java.lang.String,java.lang.Object> hash, java.util.List<java.lang.String> blockParams)
Options
.handlebars
- The handlebars instance. Required.helperName
- The name of the helper. Required.tagType
- The TagType
from where the helper was called.context
- The current context. Required.fn
- The template function. Required.inverse
- The inverse template function. Required.params
- The parameters. Required.hash
- The optional hash. Required.blockParams
- The block param names. Required.public Options(Handlebars handlebars, java.lang.String helperName, TagType tagType, Context context, Template fn, Template inverse, java.lang.Object[] params, java.util.Map<java.lang.String,java.lang.Object> hash, java.util.List<java.lang.String> blockParams, java.io.Writer writer)
Options
.handlebars
- The handlebars instance. Required.helperName
- The name of the helper. Required.tagType
- The TagType
from where the helper was called.context
- The current context. Required.fn
- The template function. Required.inverse
- The inverse template function. Required.params
- The parameters. Required.hash
- The optional hash. Required.blockParams
- The block param names. Required.writer
- A writer. Optional.public java.lang.CharSequence fn() throws java.io.IOException
fn
template using the default context.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence fn(java.lang.Object context) throws java.io.IOException
fn
template using the provided context.context
- The context to use.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence fn(Context context) throws java.io.IOException
fn
template using the provided context.context
- The context to use.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence inverse() throws java.io.IOException
inverse
template using the default context.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence inverse(java.lang.Object context) throws java.io.IOException
inverse
template using the provided context.context
- The context to use.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence inverse(Context context) throws java.io.IOException
inverse
template using the provided context.context
- The context to use.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence apply(Template template, java.lang.Object context) throws java.io.IOException
template
- The template.context
- The context object.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence apply(Template template, Context context) throws java.io.IOException
template
- The template.context
- The context object.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence apply(Template template, Context context, java.util.List<java.lang.Object> blockParams) throws java.io.IOException
template
- The template.context
- The context object.blockParams
- The block param values.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence apply(Template template, java.lang.Object context, java.util.List<java.lang.Object> blockParams) throws java.io.IOException
template
- The template.context
- The context object.blockParams
- The block param values.java.io.IOException
- If a resource cannot be loaded.public java.lang.CharSequence apply(Template template) throws java.io.IOException
template
- The template.java.io.IOException
- If a resource cannot be loaded.public <T> T param(int index)
Return a parameter at given index. This is analogous to:
Object param = options.params[index]
The only difference is the type safe feature:
MyType param = options.param(index)
T
- The runtime type.index
- The parameter position.public <T> T param(int index, T defaultValue)
Return a parameter at given index. This is analogous to:
Object param = options.params[index]
The only difference is the type safe feature:
MyType param = options.param(index)
T
- The runtime type.index
- The parameter position.defaultValue
- The default value to return if the parameter is not
present or if null.public <T> T get(java.lang.String name, T defaultValue)
T
- The runtime type.name
- The property's name.defaultValue
- The default value to return if the attribute is not
present or if null.null
if it's not found.public <T> T get(java.lang.String name)
T
- The runtime type.name
- The property's name.null
if it's not found.public Template partial(java.lang.String path)
path
- The partial's path. Required. null
if not found.public void partial(java.lang.String path, Template partial)
path
- The partial's path. Required.partial
- The partial template. Required.public <T> T hash(java.lang.String name)
Find a value inside the hash
attributes. This is analogous to:
Object myClass = options.hash.get("class");
This mehtod works as a shorthand and type safe call:
String myClass = options.hash("class");
T
- The runtime type.name
- The hash's name.public <T> T hash(java.lang.String name, java.lang.Object defaultValue)
Find a value inside the hash
attributes. This is analogous to:
Object myClass = options.hash.get("class");
This method works as a shorthand and type safe call:
String myClass = options.hash("class");
T
- The runtime type.name
- The hash's name.defaultValue
- The default value to returns.public boolean isFalsy(java.lang.Object value)
value
- A value.public Context wrap(java.lang.Object model)
Context
from the given model. If the object is a context
already the same object will be returned.model
- The model object.public <T> T data(java.lang.String name)
T
- Data type.name
- The attribute's name.public void data(java.lang.String name, java.lang.Object value)
name
- The attribute's name. Required.value
- The attribute's value. Required.public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> propertySet(java.lang.Object context)
context
- The context object. Not null.public Options.Buffer buffer()
public CharSequence helper(Object ctx, Options options) { Buffer buffer = options.buffer(); ... buffer.append(...); ... return buffer; }Something to keep in mind is that when using the native buffer there won't be any visible output. For example
Options.NativeBuffer.toString()
results in an empty string, that's expected
because the content is written directly to the underlying writer.Copyright © 2010 - 2020 Adobe. All Rights Reserved