com.github.jknack.handlebars
Class Options

java.lang.Object
  extended by com.github.jknack.handlebars.Options

public abstract class Options
extends Object

Options available for Helper.apply(Object, Options).

Since:
0.1.0
Author:
edgar.espina

Field Summary
 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.
 
Constructor Summary
Options(Handlebars handlebars, Context context, Template fn, Template inverse, Object[] params, Map<String,Object> hash)
          Creates a new Handlebars Options.
 
Method Summary
abstract  CharSequence apply(Template template)
          Apply the given template to the default context.
abstract  CharSequence apply(Template template, Object context)
          Apply the given template to the provided context.
abstract
<T> T
data(String name)
          Read the attribute from the data storage.
abstract  void data(String name, Object value)
          Set an attribute in the data storage.
abstract  CharSequence fn()
          Apply the fn template using the default context.
abstract  CharSequence fn(Object context)
          Apply the fn template using the provided context.
abstract
<T> T
get(String name)
          Look for a value in the context's stack.
abstract
<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.
abstract  CharSequence inverse()
          Apply the inverse template using the default context.
abstract  CharSequence inverse(Object context)
          Apply the inverse template using the provided context.
 boolean isEmpty(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.
abstract  Template partial(String path)
          Return a previously registered partial in the current execution context.
abstract  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.
abstract  Context wrap(Object model)
          Creates a Context from the given model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handlebars

public final Handlebars handlebars
The Handlebars object. Not null.


context

public final Context context
The current context. Not null.


fn

public final Template fn
The current template. Not null.


inverse

public final Template inverse
The current inverse template. Not null.


params

public final Object[] params
The parameters. Not null.


hash

public final Map<String,Object> hash
The hash options. Not null.

Constructor Detail

Options

public Options(Handlebars handlebars,
               Context context,
               Template fn,
               Template inverse,
               Object[] params,
               Map<String,Object> hash)
Creates a new Handlebars Options.

Parameters:
handlebars - The handlebars instance. Required.
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.
Method Detail

fn

public abstract CharSequence fn()
                         throws IOException
Apply the fn template using the default context.

Returns:
The resulting text.
Throws:
IOException - If a resource cannot be loaded.

fn

public abstract CharSequence fn(Object context)
                         throws IOException
Apply the fn template using the provided context.

Parameters:
context - The context to use.
Returns:
The resulting text.
Throws:
IOException - If a resource cannot be loaded.

inverse

public abstract CharSequence inverse()
                              throws IOException
Apply the inverse template using the default context.

Returns:
The resulting text.
Throws:
IOException - If a resource cannot be loaded.

inverse

public abstract CharSequence inverse(Object context)
                              throws IOException
Apply the inverse template using the provided context.

Parameters:
context - The context to use.
Returns:
The resulting text.
Throws:
IOException - If a resource cannot be loaded.

apply

public abstract CharSequence apply(Template template,
                                   Object context)
                            throws IOException
Apply the given template to the provided context. The context stack is propagated allowing the access to the whole stack.

Parameters:
template - The template.
context - The context object.
Returns:
The resulting text.
Throws:
IOException - If a resource cannot be loaded.

apply

public abstract CharSequence apply(Template template)
                            throws IOException
Apply the given template to the default context. The context stack is propagated allowing the access to the whole stack.

Parameters:
template - The template.
Returns:
The resulting text.
Throws:
IOException - If a resource cannot be loaded.

param

public final <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)

Type Parameters:
T - The runtime type.
Parameters:
index - The parameter position.
Returns:
The paramater's value.

param

public final <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)

Type Parameters:
T - The runtime type.
Parameters:
index - The parameter position.
defaultValue - The default value to return if the parameter is not present or if null.
Returns:
The paramater's value.

get

public abstract <T> T get(String name,
                          T defaultValue)
Look for a value in the context's stack.

Type Parameters:
T - The runtime type.
Parameters:
name - The property's name.
defaultValue - The default value to return if the attribute is not present or if null.
Returns:
The associated value or null if it's not found.

get

public abstract <T> T get(String name)
Look for a value in the context's stack.

Type Parameters:
T - The runtime type.
Parameters:
name - The property's name.
Returns:
The associated value or null if it's not found.

partial

public abstract Template partial(String path)
Return a previously registered partial in the current execution context.

Parameters:
path - The partial's path. Required.
Returns:
A previously registered partial in the current execution context. Or null if not found.

partial

public abstract void partial(String path,
                             Template partial)
Store a partial in the current execution context.

Parameters:
path - The partial's path. Required.
partial - The partial template. Required.

hash

public final <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");

Type Parameters:
T - The runtime type.
Parameters:
name - The hash's name.
Returns:
The hash value or null.

hash

public final <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");

Type Parameters:
T - The runtime type.
Parameters:
name - The hash's name.
defaultValue - The default value to returns.
Returns:
The hash value or null.

isEmpty

public final boolean isEmpty(Object value)
Returns false if its argument is false, null or empty list/array (a "falsy" value).

Parameters:
value - A value.
Returns:
False if its argument is false, null or empty list/array (a "falsy" value).

wrap

public abstract Context wrap(Object model)
Creates a Context from the given model. If the object is a context already the same object will be returned.

Parameters:
model - The model object.
Returns:
A context representing the model or the same model if it's a context already.

data

public abstract <T> T data(String name)
Read the attribute from the data storage.

Type Parameters:
T - Data type.
Parameters:
name - The attribute's name.
Returns:
The attribute value or null.

data

public abstract void data(String name,
                          Object value)
Set an attribute in the data storage.

Parameters:
name - The attribute's name. Required.
value - The attribute's value. Required.

propertySet

public Set<Map.Entry<String,Object>> propertySet(Object context)
List all the properties and their values for the given object.

Parameters:
context - The context object. Not null.
Returns:
All the properties and their values for the given object.


Copyright © 2012. All Rights Reserved.