MustacheEngine.Context

Mustache context for setting values

Variable:

//{{name}} to "Chris"
context["name"] = "Chirs"

Lists section("addSubContext" name is drived from ctemplate's API):

//{{#repo}}
//<b>{{name}}</b>
//{{/repo}}
//  to
//<b>resque</b>
//<b>hub</b>
//<b>rip</b>
foreach (name; ["resque", "hub", "rip"]) {
    auto sub = context.addSubContext("repo");
    sub["name"] = name;
}

Variable section:

//{{#person?}}Hi {{name}}{{/person?}} to "Hi Jon"
context["person?"] = ["name" : "Jon"];

Lambdas section:

//{{#wrapped}}awesome{{/wrapped}} to "<b>awesome</b>"
context["Wrapped"] = (string str) { return "<b>" ~ str ~ "</b>"; };

Inverted section:

//{{#repo}}<b>{{name}}</b>{{/repo}}
//{{^repo}}No repos :({{/repo}}
//  to
//No repos :(
context["foo"] = "bar";  // not set to "repo"

Constructors

this
this(Context context)
Undocumented in source.

Members

Functions

addSubContext
Context addSubContext(String key, size_t size)

Adds new context to key's section. This method overwrites with list type if you already assigned other type to key's section.

opIndex
String opIndex(String key)

Gets key's value. This method does not search Section.

opIndexAssign
void opIndexAssign(T value, String key)

Assigns value(automatically convert to String) to key field.

useSection
void useSection(String key)

Enable key's section.

Meta