You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Link with you projects](#link-with-you-projects)
35
36
-[Changelog](#changelog)
37
+
-[Version 0.9](#version-09)
36
38
-[Version 0.6](#version-06)
37
39
38
40
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -45,8 +47,9 @@ Main features of Jinja2Cpp:
45
47
- Partial support for both narrow- and wide-character strings both for templates and parameters.
46
48
- Built-in reflection for C++ types.
47
49
- Powerful full-featured Jinja2 expressions with filtering (via '|' operator) and 'if'-expressions.
48
-
-Basic control statements (set, for, if).
50
+
-Control statements (set, for, if).
49
51
- Templates extention.
52
+
- Macros
50
53
- Rich error reporting.
51
54
52
55
For instance, this simple code:
@@ -60,6 +63,7 @@ std::string source = R"(
60
63
)";
61
64
62
65
Template tpl;
66
+
tpl.Load(source);
63
67
64
68
std::string result = tpl.RenderAsString(ValuesMap());
65
69
```
@@ -381,6 +385,54 @@ private:
381
385
382
386
'**extends**' statement here defines the template to extend. Set of '**block**' statements after defines actual filling of the corresponding blocks from the extended template. If block from the extended template contains something (like ```namespaced_decls``` from the example above), this content can be rendered with help of '**super()**' function. In other case the whole content of the block will be replaced. More detailed description of template inheritance feature can be found in [Jinja2 documentation](http://jinja.pocoo.org/docs/2.10/templates/#template-inheritance).
383
387
388
+
## Macros
389
+
Ths sample above violates 'DRY' rule. It contains the code which could be generalized. And Jinja2 supports features for such kind generalization. This feature called '**macro**'. The sample can be rewritten the following way:
390
+
```c++
391
+
{% macro MethodsDecl(class, access) %}
392
+
{% for method in class.methods | rejectattr('isImplicit') | selectattr('accessType', 'in', access) %}
`MethodsDecl` statement here is a **macro** which takes two arguments. First one is a class with method definitions. The second is a tuple of access specifiers. Macro takes non-implicit methods from the methods collection (`rejectattr('isImplicit')` filter) then select such methods which have right access specifier (`selectattr('accessType', 'in', access)`), then just prints the method full prototype. Finally, the macro is invoked as a regular function call: `MethodsDecl(class, ['Public'])` and replaced with rendered macro body.
411
+
412
+
There is another way to invoke macro: the **call** statement. Simply put, this is a way to call macro with *callback*. Let's take another sample:
Here is an `InlineMacro` which just describe the inline method definition skeleton. This macro doesn't contain the actual method body. Instead of this it calls `caller` special function. This function invokes the special **callback** macro which is a body of `call` statement. And this macro can have parameters as well. More detailed this mechanics described in the [Jinja2 documentation](http://jinja.pocoo.org/docs/2.10/templates/#macros).
435
+
384
436
## Error reporting
385
437
It's difficult to write complex template completely without errors. Missed braces, wrong characters, incorrect names... Everything is possible. So, it's crucial to be able to get informative error report from the template engine. Jinja2Cpp provides such kind of report. ```Template::Load``` method (and TemplateEnv::LoadTemplate respectively) return instance of ```ErrorInfo``` class which contains details about the error. These details include:
386
438
- Error code
@@ -463,8 +515,10 @@ Currently, Jinja2Cpp supports the limited number of Jinja2 features. By the way,
463
515
- 'for' statement (with 'else' branch and 'if' part support)
464
516
- 'extends' statement
465
517
- 'set' statement
466
-
- 'extends' statement
518
+
- 'extends'/'block' statements
519
+
- 'macro'/'call' statements
467
520
- recursive loops
521
+
- space control
468
522
469
523
# Supported compilers
470
524
Compilation of Jinja2Cpp tested on the following compilers (with C++14 enabled feature):
@@ -476,7 +530,7 @@ Compilation of Jinja2Cpp tested on the following compilers (with C++14 enabled f
476
530
- Microsoft Visual Studio 2017 x86
477
531
478
532
# Build and install
479
-
Jinja2Cpp has got only one external dependency: boost library (at least version 1.55). Because of types from boost are used inside library, you should compile both your projects and Jinja2Cpp library with similar compiler settings. Otherwise ABI could be broken.
533
+
Jinja2Cpp has got only two external dependency: boost library (at least version 1.55) and expected-lite. Because of types from boost are used inside library, you should compile both your projects and Jinja2Cpp library with similar compiler settings. Otherwise ABI could be broken.
0 commit comments