Conforms to NSObject
Declared in GRMustacheTemplateRepository.h

Overview

The protocol for a GRMustacheTemplateRepository’s dataSource.

The dataSource’s responsability is to provide Mustache template strings for template and partial names.

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

Instance Methods

templateRepository:templateIDForName:relativeToTemplateID:

Returns a template ID, that is to say an object that uniquely identifies a template or a template partial.

- (id<NSCopying>)templateRepository:(GRMustacheTemplateRepository *)templateRepository templateIDForName:(NSString *)name relativeToTemplateID:(id)baseTemplateID

Parameters

templateRepository

The GRMustacheTemplateRepository asking for a template ID.

name

The name of the template or template partial.

baseTemplateID

The template ID of the enclosing template, or nil.

Return Value

a template ID

Availability

v1.13

Discussion

The class of this ID is opaque: your implementation of a GRMustacheTemplateRepositoryDataSource would define, for itself, what kind of object would identity a template or a partial.

For example, a file-based data source may use NSString objects containing paths to the templates.

You should try to choose “human-readable” template IDs, because template IDs are embedded in the description of errors that may happen during a template processing, in order to help the library user locate, and fix, the faulting template.

Whenever relevant, template and partial hierarchies are supported via the baseTemplateID parameter: it contains the template ID of the enclosing template, or nil when the data source is asked for a template ID for a partial that is referred from a raw template string (see [GRMustacheTemplateRepository templateFromString:error:]).

Not all data sources have to implement hierarchies: they can simply ignore this parameter.

Data sources that implement hierarchies have to implement their own support for absolute partial paths.

The return value of this method can be nil: the library user would then eventually get an NSError of domain GRMustacheErrorDomain and code GRMustacheErrorCodeTemplateNotFound.

Declared In

GRMustacheTemplateRepository.h

templateRepository:templateStringForTemplateID:error:

Provided with a template ID that comes from templateRepository:templateIDForName:relativeToTemplateID:, returns a Mustache template string.

- (NSString *)templateRepository:(GRMustacheTemplateRepository *)templateRepository templateStringForTemplateID:(id)templateID error:(NSError **)error

Parameters

templateRepository

The GRMustacheTemplateRepository asking for a Mustache template string.

templateID

The template ID of the template

error

If there is an error returning a template string, upon return contains nil, or an NSError object that describes the problem.

Return Value

a Mustache template string

Availability

v1.13

Discussion

For example, a file-based data source may interpret the template ID as a NSString object containing paths to the template, and return the file content.

As usual, whenever this method returns nil, the error parameter should point to a valid NSError. This NSError would eventually reach the library user.

Declared In

GRMustacheTemplateRepository.h