[ Home | Main Table Of Contents | Table Of Contents | Keyword Index ]

mustache::context(n) 1 doc "Mustache. Packages for logic-less templating"

Name

mustache::context - Mustache - Field resolution context

Table Of Contents

Synopsis

Description

Welcome to the Mustache project for Tcl, written by Andreas Kupries.

It provides a set of five related Tcl packages for the parsing and rendering of mustache-style logic-less templates, plus an application for easy command-line access to the functionality.

For availability please read Mustache - How To Get The Sources.

Overview

The mustache render command provided by package mustache::render requires a context as the source of the values to interpolate into the template it is invoked with.

This package provides a suitable TclOO class.

Note however that any command prefix supporting the Instance API below will be suitable.

Class API

::mustache context create obj frame

This constructor command creates a new instance obj of the class, initializes it using the data frame and returns the fully qualified name of that instance.

The frame command prefix has to support the API of mustache::frame objects.

Attention: The frame object becomes owned by the context, and will be destroyed when the context is destroyed.

Additional initialization, i.e. definition of partials (aka parts, aka includes) can be done via the template: instance method.

::mustache context new frame

This constructor command creates a new instance of the class, initializes it using the data frame and returns the fully qualified name of that instance.

The frame command prefix has to support the API of mustache::frame objects.

Attention: The frame object becomes owned by the context, and will be destroyed when the context is destroyed.

Additional initialization, i.e. definition of partials (aka parts, aka includes) can be done via the template: instance method.

Instance API

Contexts are what the mustache renderer delegates field resolution to, and retrieves the values to interpolate from.

From its point of view a context is a stack of data frames from which it can pull values. The data frame at the top of the stack is called dot. Any search for named fields starts at dot, moving deeper into the stack only on misses.

During rendering data frames are pushed on and popped of the stack at the behest of the renderer, as it walks the template structure.

<contextcmd> has? field

Searches the context for the named field. Returns a boolean value indicating either success (true) or failure (false) of the search.

<contextcmd> focus field

Searches the context for the named field. Throws an error when the field is not found. When found the data frame associated with the field is pushed on the search stack, i.e. made dot.

Returns the empty string.

<contextcmd> pop

Removes the data frame at the top of the search stack. Throws an error when trying to pop the root data frame. That is the frame supplied during construction of the context.

Returns the empty string.

<contextcmd> push frame

Pushed the frame on top of the search stack.

The frame command prefix has to support the API of mustache::frame objects.

Returns the empty string.

<contextcmd> iterable?

Asks dot if it can be iterated over. In other words, if it is a non-empty sequence of values.

Returns a boolean value. true signals that dot can be iterated over.

<contextcmd> nil?

Asks dot if it is nil, false, empty, etc.

Returns a boolean value. true signals that dot is indeed nil, empty, false, etc.

<contextcmd> value

Asks dot for its value, and returns it.

<contextcmd> iter script

Iterates over the elements of dot and invokes the script for each element. During the execution of the script the active element will be dot.

Returns the empty string.

<contextcmd> template? name

Checks if the context knows abut the named template. Returns a boolean value indicating either success (true) or failure (false) of the search.

<contextcmd> template: name specification

Defines a new template with name and specification.

Returns the empty string.

<contextcmd> template name

Returns the specification of the named template. Throws an error when a template of the name is not known.

Bugs, Ideas, Feedback

Both the package(s) and this documentation will undoubtedly contain bugs and other problems. Please report such at Mustache Tracker.

Please also report any ideas you may have for enhancements of either package(s) and/or documentation.

Keywords

context, contexts, dot, logic-less templates, mustache, templating