MustacheEngine

Core implementation of Mustache

String parameter means a string type to render.

Constructors

this
this(Option option)
Undocumented in source.

Members

Aliases

FindPath
alias FindPath = string delegate(string)
Undocumented in source.
Handler
alias Handler = String delegate(String)
Undocumented in source.

Classes

Context
class Context

Mustache context for setting values

Enums

CacheLevel
enum CacheLevel

Cache level for compile result

Functions

clearCache
void clearCache()

Clears the intenal cache. Useful for forcing reloads when using CacheLevel.once.

render
String render(string name, Context context)

Renders name template with context.

render
void render(string name, Context context, Sink sink)

OutputRange version of render.

renderString
String renderString(String src, Context context)

string version of render.

renderString
void renderString(String src, Context context, Sink sink)

string/OutputRange version of render.

Properties

ext
const(string) ext [@property getter]
string ext [@property setter]

Property for template extenstion

findPath
FindPath findPath [@property getter]
FindPath findPath [@property setter]

Property for callback to dynamically search path. The result of the delegate should return the full path for the given name.

handler
const(Handler) handler [@property getter]
Handler handler [@property setter]

Property for callback handler

level
const(CacheLevel) level [@property getter]
CacheLevel level [@property setter]

Property for cache level

path
const(string) path [@property getter]
string path [@property setter]

Property for template searche path

Structs

Option
struct Option

Options for rendering

Examples

alias MustacheEngine!(string) Mustache;

Mustache mustache;
auto context = new Mustache.Context;

context["name"]  = "Chris";
context["value"] = 10000;
context["taxed_value"] = 10000 - (10000 * 0.4);
context.useSection("in_ca");

write(mustache.render("sample", context));

sample.mustache:

Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{taxed_value}}, after taxes.
{{/in_ca}}

Output:

Hello Chris
You have just won $10000!
Well, $6000, after taxes.

Meta