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
- Partial support for both narrow- and wide-character strings both for templates and parameters.
46
47
- Built-in reflection for C++ types.
47
48
- Powerful full-featured Jinja2 expressions with filtering (via '|' operator) and 'if'-expressions.
48
-
-Basic control statements (set, for, if).
49
+
-Control statements (set, for, if).
49
50
- Templates extention.
51
+
- Macros
50
52
- Rich error reporting.
51
53
52
54
For instance, this simple code:
@@ -381,6 +383,54 @@ private:
381
383
382
384
'**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
385
386
+
## Macros
387
+
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 '**macros**'. The sample can be rewritten the following way:
388
+
```c++
389
+
{% macro MethodsDecl(class, access) %}
390
+
{% 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.
409
+
410
+
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).
433
+
384
434
## Error reporting
385
435
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
436
- Error code
@@ -463,8 +513,10 @@ Currently, Jinja2Cpp supports the limited number of Jinja2 features. By the way,
463
513
- 'for' statement (with 'else' branch and 'if' part support)
464
514
- 'extends' statement
465
515
- 'set' statement
466
-
- 'extends' statement
516
+
- 'extends'/'block' statements
517
+
- 'macro'/'call' statements
467
518
- recursive loops
519
+
- space control
468
520
469
521
# Supported compilers
470
522
Compilation of Jinja2Cpp tested on the following compilers (with C++14 enabled feature):
@@ -476,7 +528,7 @@ Compilation of Jinja2Cpp tested on the following compilers (with C++14 enabled f
476
528
- Microsoft Visual Studio 2017 x86
477
529
478
530
# 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.
531
+
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