Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3c5c86a

Browse files
authored
Update basic.md
1 parentd3e638a commit3c5c86a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎docs/usage/basic.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ inline const char* AnimalsToString(Animals e)
3939
}
4040
```
4141
42-
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.
4343
4444
Firstly, you should define the simple jinja2 template (in the C++ manner):
4545
{% raw %}
@@ -59,9 +59,9 @@ inline const char* {{enumName}}ToString({{enumName}} e)
5959
```
6060
{% endraw %}
6161

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 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.
6363

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.
6565

6666
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!
6767

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp