Class for rendering templates from string, files or directories.
Example of use
{"key1","value #1"},
{"key2","value #2"}
};
TplProc.renderFile(
"/path/to/template/file.tpl",
"/path/to/rendered/file.txt",
Data,
Errors);
TplProc.renderDirectory(
"/path/to/template/directory",
"/path/to/rendered/directory",
Data,
Errors);
#include <tools/TemplateProcessor.hpp>
|
using | Data = std::map< std::string, std::string > |
|
using | Errors = std::set< std::string > |
|
|
| TemplateProcessor ()=delete |
|
| TemplateProcessor (const std::string &Begin, const std::string &End) |
|
virtual | ~TemplateProcessor ()=default |
|
void | enableAutoComment (const std::string &CommentStr) |
|
void | ignoreUnknown (bool Enabled) |
|
std::string | renderString (const std::string &Str, const Data &D, Errors &E) |
|
std::string | renderFile (const std::string &InFile, const Data &D, Errors &E) |
|
void | renderFile (const std::string &InFile, const std::string &OutFile, const Data &D, Errors &E) |
|
void | renderDirectory (const std::string &InDir, const std::string &OutDir, const Data &D, Errors &E) |
|
◆ Data
Type for the input data used to resolve the template, as a key-value structure
◆ Errors
Type for the resolution errors returned at render time, containing unresolved patterns found in the template
◆ TemplateProcessor() [1/2]
openfluid::tools::TemplateProcessor::TemplateProcessor |
( |
| ) |
|
|
delete |
◆ TemplateProcessor() [2/2]
openfluid::tools::TemplateProcessor::TemplateProcessor |
( |
const std::string & |
Begin, |
|
|
const std::string & |
End |
|
) |
| |
Constructs a template processor, giving the beginning end ending delimiters used ath rendering time
- Parameters
-
[in] | Begin | The beginning delimiter |
[in] | End | The ending delimiter |
- Exceptions
-
◆ ~TemplateProcessor()
virtual openfluid::tools::TemplateProcessor::~TemplateProcessor |
( |
| ) |
|
|
virtualdefault |
◆ enableAutoComment()
void openfluid::tools::TemplateProcessor::enableAutoComment |
( |
const std::string & |
CommentStr | ) |
|
Enables automatic comment mode. When enabled, the '#KEYNAME' pattern is replaced by a comment string during the rendering process if 'KEYNAME' is empty or does not exist.
- Parameters
-
[in] | CommentStr | The comment string to use |
◆ ignoreUnknown()
void openfluid::tools::TemplateProcessor::ignoreUnknown |
( |
bool |
Enabled | ) |
|
Enables or disables the ignore unknown mode. When enabled, unknown keys are ignored and removed during the rendering process.
◆ renderDirectory()
void openfluid::tools::TemplateProcessor::renderDirectory |
( |
const std::string & |
InDir, |
|
|
const std::string & |
OutDir, |
|
|
const Data & |
D, |
|
|
Errors & |
E |
|
) |
| |
Renders a template directory into another directory recursively.
- Parameters
-
[in] | InDir | The template directory path |
[in] | OutDir | The rendered directory path |
[in] | D | The data to resolve the template |
[in,out] | E | The unresolved patterns if any |
- Exceptions
-
◆ renderFile() [1/2]
std::string openfluid::tools::TemplateProcessor::renderFile |
( |
const std::string & |
InFile, |
|
|
const Data & |
D, |
|
|
Errors & |
E |
|
) |
| |
Renders a template file into a string
- Parameters
-
[in] | InFile | The template file path |
[in] | D | The data to resolve the template |
[in,out] | E | The unresolved patterns if any |
- Returns
- The resolved template as a string
- Exceptions
-
◆ renderFile() [2/2]
void openfluid::tools::TemplateProcessor::renderFile |
( |
const std::string & |
InFile, |
|
|
const std::string & |
OutFile, |
|
|
const Data & |
D, |
|
|
Errors & |
E |
|
) |
| |
Renders a template file into another file
- Parameters
-
[in] | InFile | The template file path |
[in] | OutFile | The rendered file path |
[in] | D | The data to resolve the template |
[in,out] | E | The unresolved patterns if any |
- Exceptions
-
◆ renderString()
std::string openfluid::tools::TemplateProcessor::renderString |
( |
const std::string & |
Str, |
|
|
const Data & |
D, |
|
|
Errors & |
E |
|
) |
| |
Renders a template string into a string
- Parameters
-
[in] | Str | The template content |
[in] | D | The data to resolve the template |
[in,out] | E | The unresolved patterns if any |
- Returns
- The resolved template as a string
The documentation for this class was generated from the following file: