com.github.jknack.handlebars
Class Context

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

public final class Context
extends Object

Mustache/Handlebars are contextual template engines. This class represent the 'context stack' of a template.

Since:
0.1.0
Author:
edgar.espina

Nested Class Summary
static class Context.Builder
          A context builder.
 
Field Summary
static String PARTIALS
          The qualified name for partials.
 
Method Summary
<T> T
data(String name)
          Read the attribute from the data storage.
 Context data(String name, Object value)
          Set an attribute in the data storage.
 void destroy()
          Destroy this context by cleaning up instance attributes.
 Object get(String key)
          Lookup the given key inside the context stack.
 Object model()
          Resolved as '.' or 'this' inside templates.
static Context.Builder newBuilder(Context parent, Object model)
          Start a new context builder.
static Context.Builder newBuilder(Object model)
          Start a new context builder.
static Context newContext(Context parent, Object model)
          Creates a new child context.
static Context newContext(Object model)
          Creates a new root context.
 Set<Map.Entry<String,Object>> propertySet()
          List all the properties and values of model().
 Set<Map.Entry<String,Object>> propertySet(Object context)
          List all the properties and values for the given object.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PARTIALS

public static final String PARTIALS
The qualified name for partials. Internal use.

Method Detail

data

public <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 Context 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.
Returns:
This context.

model

public Object model()
Resolved as '.' or 'this' inside templates.

Returns:
The model or data.

propertySet

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

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

propertySet

public Set<Map.Entry<String,Object>> propertySet()
List all the properties and values of model().

Returns:
All the properties and values of model().

get

public Object get(String key)
Lookup the given key inside the context stack.

Parameters:
key - The object key.
Returns:
The value associated to the given key or null if no value is found.

destroy

public void destroy()
Destroy this context by cleaning up instance attributes.


toString

public String toString()
Overrides:
toString in class Object

newBuilder

public static Context.Builder newBuilder(Context parent,
                                         Object model)
Start a new context builder.

Parameters:
parent - The parent context. Required.
model - The model data.
Returns:
A new context builder.

newBuilder

public static Context.Builder newBuilder(Object model)
Start a new context builder.

Parameters:
model - The model data.
Returns:
A new context builder.

newContext

public static Context newContext(Context parent,
                                 Object model)
Creates a new child context.

Parameters:
parent - The parent context. Required.
model - The model data.
Returns:
A new child context.

newContext

public static Context newContext(Object model)
Creates a new root context.

Parameters:
model - The model data.
Returns:
A new root context.


Copyright © 2012. All Rights Reserved.