Lumiera  0.pre.03
»edit your freedom«
text-template-gen-node-binding.hpp File Reference

Go to the source code of this file.

Description

A complement to allow instantiation of a TextTemplate with ETD data.

Instead of requiring a specific data source type, the text template engine relies on an extension point through a data-binding template, which can be (partially) specialised to implement data access for any suitable kind of structured data. The Lumiera ETD is a recursive data type comprised of lib::diff::GenNode elements, which in turn can hold a small selection of binary data elements. This scheme for structured data is widely used for internal communication between the components of the Lumiera application; it offers all the structural elements to provide a full featured backing data structure for the text template engine.

Intricacies

Since the ETD is based on binary data, we need to invoke a string rendering during data access, in the end relying on util::toString(). This limits the precision of floating-pont and time data (assuming this is adequate for the purpose of instantiating placeholders in a text template). A further challenge arises from the openness of the ETD format, which is intended for loose coupling between subsystems, and deliberately imposes not much structural constraints, while also offering only very limited introspection capabilities (to prevent a »programming by inspection« style). Some further conventions are thus necessary

  • a Scope is assumed to be a Record-Node. (»object structure«)
  • Keys are translated into Attribute access.
  • Iteration is assumed to pick a loop-control Node and descend into this node's child scope.
  • if such iterated children happen to be simple values, then a pseudo-scope is synthesised, containing a single virtual attribute with the KeyID "value" (which implies that TextTemplate can expand a ${value} placeholder in that scope.
  • Attributes of enclosing scopes are also visible — unless shadowed.
See also
TextTemplate_test::verify_ETD_binding

Definition in file text-template-gen-node-binding.hpp.

#include "lib/diff/gen-node.hpp"
#include "lib/text-template.hpp"
#include <string>

Classes

struct  DataSource< diff::GenNode >
 Data-binding for a tree of GenNode data (ETD). More...
 

Namespaces

 lib
 Implementation namespace for support and library code.