Lumiera  0.pre.03
»edit your freedom«
TextTemplate Class Reference

#include "lib/text-template.hpp"

Description

Text template substitution engine.

Can substitute ${placeholders} by name and can handle conditional and iterated sections. Structural data for the substitution is accessed and navigated through a generic Data Source binding. By default, a binding for Map-of-strings is provided.

See also
TextTemplate_test

Definition at line 339 of file text-template.hpp.

Public Member Functions

 TextTemplate (string spec)
 
auto keys () const
 diagnostics: query a list of all active keys expected by the template. More...
 
template<class DAT >
string render (DAT const &data) const
 submit data and materialise rendered results into a single string
 
template<class DAT >
auto submit (DAT const &data) const
 Instantiate this (pre-compiled) TextTemplate using the given data binding. More...
 

Static Public Member Functions

template<class DAT >
static string apply (string spec, DAT const &data)
 one-shot shorthand: compile a template and apply it to the given data
 
static ActionSeq compile (string const &)
 

Classes

struct  Action
 
class  ActionCompiler
 
class  InstanceCore
 Iterator »State Core« to process the template instantiation. More...
 
struct  ParseCtx
 

Friends

class test::TextTemplate_test
 

Private Types

using ActionSeq = std::vector< Action >
 the text template is compiled into a sequence of Actions
 
enum  Clause {
  IF,
  FOR
}
 
enum  Code {
  TEXT,
  KEY,
  COND,
  JUMP,
  ITER,
  LOOP
}
 
using Idx = size_t
 cross-references by index number
 
using ScopeStack = std::stack< ParseCtx, std::vector< ParseCtx > >
 

Private Attributes

ActionSeq actions_
 

Additional Inherited Members

- Private Member Functions inherited from MoveOnly
 MoveOnly (MoveOnly &&)=default
 
 MoveOnly (MoveOnly const &)=delete
 
MoveOnlyoperator= (MoveOnly &&)=delete
 
MoveOnlyoperator= (MoveOnly const &)=delete
 

Class Documentation

◆ TextTemplate::ParseCtx

struct TextTemplate::ParseCtx
Class Members
Clause clause
Idx begin
Idx after
+ Collaboration diagram for TextTemplate::ParseCtx:

Member Function Documentation

◆ submit()

auto submit ( DAT const &  data) const
inline

Instantiate this (pre-compiled) TextTemplate using the given data binding.

Returns
iterator to perform the evaluation and substitution step-by step, thereby producing a sequence of std::string_view&

Definition at line 963 of file text-template.hpp.

References lib::explore().

+ Here is the call graph for this function:

◆ keys()

auto keys ( ) const
inline

diagnostics: query a list of all active keys expected by the template.

Definition at line 986 of file text-template.hpp.

References lib::explore().

+ Here is the call graph for this function:

◆ compile()

TextTemplate::ActionSeq compile ( string const &  spec)
inlinestatic

exposed for testing

Definition at line 615 of file text-template.hpp.

+ Inheritance diagram for TextTemplate:
+ Collaboration diagram for TextTemplate:

The documentation for this class was generated from the following file: