public class Options extends 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 class |
Options.Builder
An
Options builder. |
Modifier and Type | Field and Description |
---|---|
Context |
context
The current context.
|
Template |
fn
The current template.
|
Handlebars |
handlebars
The
Handlebars object. |
Map<String,Object> |
hash
The hash options.
|
Template |
inverse
The current inverse template.
|
Object[] |
params
The parameters.
|
TagType |
tagType
The
TagType from where the helper was called. |
Constructor and Description |
---|
Options(Handlebars handlebars,
TagType tagType,
Context context,
Template fn,
Template inverse,
Object[] params,
Map<String,Object> hash)
Creates a new Handlebars
Options . |
Modifier and Type | Method and Description |
---|---|
CharSequence |
apply(Template template)
Apply the given template to the default context.
|
CharSequence |
apply(Template template,
Object context)
Apply the given template to the provided context.
|
<T> T |
data(String name)
Read the attribute from the data storage.
|
void |
data(String name,
Object value)
Set an attribute in the data storage.
|
CharSequence |
fn()
Apply the
fn template using the default context. |
CharSequence |
fn(Object context)
Apply the
fn template using the provided context. |
<T> T |
get(String name)
Look for a value in the context's stack.
|
<T> T |
get(String name,
T defaultValue)
Look for a value in the context's stack.
|
<T> T |
hash(String name)
Find a value inside the
hash attributes. |
<T> T |
hash(String name,
Object defaultValue)
Find a value inside the
hash attributes. |
CharSequence |
inverse()
Apply the
inverse template using the default context. |
CharSequence |
inverse(Object context)
Apply the
inverse template using the provided context. |
boolean |
isFalsy(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(String path)
Return a previously registered partial in the current execution context.
|
void |
partial(String path,
Template partial)
Store a partial in the current execution context.
|
Set<Map.Entry<String,Object>> |
propertySet(Object context)
List all the properties and their values for the given object.
|
Context |
wrap(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 Object[] params
public Options(Handlebars handlebars, TagType tagType, Context context, Template fn, Template inverse, Object[] params, Map<String,Object> hash)
Options
.handlebars
- The handlebars instance. 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.public CharSequence fn() throws IOException
fn
template using the default context.IOException
- If a resource cannot be loaded.public CharSequence fn(Object context) throws IOException
fn
template using the provided context.context
- The context to use.IOException
- If a resource cannot be loaded.public CharSequence inverse() throws IOException
inverse
template using the default context.IOException
- If a resource cannot be loaded.public CharSequence inverse(Object context) throws IOException
inverse
template using the provided context.context
- The context to use.IOException
- If a resource cannot be loaded.public CharSequence apply(Template template, Object context) throws IOException
template
- The template.context
- The context object.IOException
- If a resource cannot be loaded.public CharSequence apply(Template template) throws IOException
template
- The template.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(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(String name)
T
- The runtime type.name
- The property's name.null
if it's not found.public Template partial(String path)
path
- The partial's path. Required. null
if not found.public void partial(String path, Template partial)
path
- The partial's path. Required.partial
- The partial template. Required.public <T> T hash(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(String name, 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(Object value)
value
- A value.public Context wrap(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(String name)
T
- Data type.name
- The attribute's name.public void data(String name, Object value)
name
- The attribute's name. Required.value
- The attribute's value. Required.Copyright © 2013. All Rights Reserved.