Inherits from NSObject
Declared in GRMustacheContext.h

Overview

The GRMustacheContext represents a Mustache rendering context: it internally maintains two stacks:

  • a context stack, that makes it able to provide the current context object, and to perform key lookup.
  • a tag delegate stack, so that tag delegates are notified when a Mustache tag is rendered.

Tasks

Creating Contexts

Deriving New Contexts

Class Methods

context

An empty rendering context.

+ (instancetype)context

Return Value

An empty rendering context.

Availability

Declared In

GRMustacheContext.h

contextWithObject:

Returns a context with object at the top of the context stack.

+ (instancetype)contextWithObject:(id)object

Parameters

object

An object

Return Value

A rendering context.

Availability

Discussion

If object conforms to the GRMustacheTemplateDelegate protocol, it is also made the top of the tag delegate stack.

Declared In

GRMustacheContext.h

contextWithProtectedObject:

Returns a context with object at the top of the protected context stack.

+ (instancetype)contextWithProtectedObject:(id)object

Parameters

object

An object

Return Value

A rendering context.

Availability

Discussion

Unlike contextWithObject:, this method does not put the object to the tag delegate stack if it conforms to the GRMustacheTemplateDelegate protocol.

Companion guide: https://github.com/groue/GRMustache/blob/master/Guides/protected_context.md

Declared In

GRMustacheContext.h

contextWithTagDelegate:

Returns a context with tagDelegate at the top of the tag delegate stack.

+ (instancetype)contextWithTagDelegate:(id<GRMustacheTagDelegate>)tagDelegate

Parameters

tagDelegate

A tag delegate

Return Value

A rendering context.

Declared In

GRMustacheContext.h

Instance Methods

contextByAddingObject:

Returns a new rendering context that is the copy of the receiver, and the given object added at the top of the context stack.

- (instancetype)contextByAddingObject:(id)object

Parameters

object

An object

Return Value

A new rendering context.

Availability

Discussion

If object conforms to the GRMustacheTemplateDelegate protocol, it is also added at the top of the tag delegate stack.

Declared In

GRMustacheContext.h

contextByAddingProtectedObject:

Returns a new rendering context that is the copy of the receiver, and the given object added at the top of the protected context stack.

- (instancetype)contextByAddingProtectedObject:(id)object

Parameters

object

An object

Return Value

A new rendering context.

Availability

Discussion

Unlike contextByAddingObject:, this method does not add the object to the tag delegate stack if it conforms to the GRMustacheTemplateDelegate protocol.

Companion guide: https://github.com/groue/GRMustache/blob/master/Guides/protected_context.md

Declared In

GRMustacheContext.h

contextByAddingTagDelegate:

Returns a new rendering context that is the copy of the receiver, and the given object added at the top of the tag delegate stack.

- (instancetype)contextByAddingTagDelegate:(id<GRMustacheTagDelegate>)tagDelegate

Parameters

tagDelegate

A tag delegate

Return Value

A new rendering context.

Availability

Declared In

GRMustacheContext.h

valueForMustacheExpression:error:

Evaluate the expression in the receiver context.

- (id)valueForMustacheExpression:(NSString *)expression error:(NSError **)error

Availability

Discussion

This method can evaluate complex expressions such as user.name or uppercase(user.name).

Declared In

GRMustacheContext.h

valueForMustacheKey:

Returns the value stored in the context stack for the given key.

- (id)valueForMustacheKey:(NSString *)key

Availability

Discussion

If you want the value for an full expression such as user.name or uppercase(user.name), use the valueForMustacheExpression:error: method.

Declared In

GRMustacheContext.h