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
Of course, you can write this producerin the waylike [this](https://github.com/flexferrum/autoprogrammer/blob/87a9dc8ff61c7bdd30fede249757b71984e4b954/src/generators/enum2string_generator.cpp#L140). It's too complicatedfor writing 'from scratch'.Actually, there is a better and simpler way.
42
+
Of course, you can write this producer like [this](https://github.com/flexferrum/autoprogrammer/blob/87a9dc8ff61c7bdd30fede249757b71984e4b954/src/generators/enum2string_generator.cpp#L140). It's too complicatedto write 'from scratch'.But there is a better and simpler way.
43
43
44
44
Firstly, you should define the simple jinja2 template (in the C++ manner):
This template is quite basic. Actually, this is the regular text mixed with blocks, which have special meaning. Template parts wrapped with {% raw %}'{{' and '}}'{% endraw %} are expressions. During the template rendering this expression will be evaluated and the result will be inserted into final text. For instance,`{% raw %}{{ enumName }}{% endraw %}` should be replaced with the value of`enumName` param (if any) or should be substituted with an empty string.
62
+
This template is quite basic. Actually, this is the regular text mixed with blocks, which have special meaning. Template parts wrapped with {% raw %}'{{' and '}}'{% endraw %} are expressions. During the template rendering this expression will be evaluated and the result will be inserted intothefinal text. For instance,`{% raw %}{{ enumName }}{% endraw %}` should be replaced with the value of`enumName` param (if any) or substituted with an empty string.
63
63
64
-
Template parts wrapped in {% raw %}'{%' and '%}'{% endraw %} are "statements" or control blocks.Each of such statement hasspecial meaning and different processing inside Jinja2C++ engine. For instance,`{% raw %}{% for item in items %}...{% endfor %}{% endraw %}` is a loop statement.`items` variable should be a collection and loop body will be inserted into the final text as many times as many items in`items`. The current item can be accessed inside loop body via`item` variable.
64
+
Template parts wrapped in {% raw %}'{%' and '%}'{% endraw %} are "statements" or control blocks.Such statements havespecial meaning and different processing inside Jinja2C++ engine. For instance,`{% raw %}{% for item in items %}...{% endfor %}{% endraw %}` is a loop statement.`items` variable should be a collection and loop body will be inserted into the final text as many times as many items in`items`. The current item can be accessed inside loopthebody via the`item` variable.
65
65
66
66
Template author can define new variables via`set` statement, test expressions via`if`, define macros via`macro`, include other templates via`include` and so on. There are many statements in the Jinja2 specification. But in order to be useful there should be a way to pass parameters to the template engine from the 'outside'. For instance, for the template above`items` should be somehow passed to the Jinja2C++ engine in order to be iterated. And there is a way to do it! Here it is!