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
C++ implementation of Jinja2 Python template engine. This library was originally inspired by [Jinja2CppLight](https://github.com/hughperkins/Jinja2CppLight) project and brings support of mostly all Jinja2 templates features into C++ world.
17
+
C++ implementation of Jinja2 Python template engine. This library brings support of powerful Jinja2 templates features into the C++ world. Reports and dynamic html pages, source code generation and
18
18
19
19
## Introduction
20
20
@@ -28,6 +28,7 @@ Main features of Jinja2C++:
28
28
- Templates extention, including and importing
29
29
- Macros
30
30
- Rich error reporting.
31
+
- Shared template enironment with templates cache support
31
32
32
33
For instance, this simple code:
33
34
@@ -60,7 +61,7 @@ hello; world!!!
60
61
61
62
In order to use Jinja2C++ in your project you have to:
62
63
* Clone the Jinja2C++ repository
63
-
* Build it according with the instructions
64
+
* Build it according with the [instructions](https://jinja2cpp.dev/docs/build_and_install.html)
64
65
* Link to your project.
65
66
66
67
Usage of Jinja2C++ in the code is pretty simple:
@@ -73,7 +74,7 @@ jinja2::Template tpl;
73
74
2. Populate it with template:
74
75
75
76
```c++
76
-
tpl.Load("{{'Hello World' }}!!!");
77
+
tpl.Load("{{'Hello World' }}!!!");
77
78
```
78
79
79
80
3. Render the template:
@@ -95,7 +96,7 @@ More detailed examples and features describtion can be found in the documentatio
95
96
## Current Jinja2 support
96
97
Currently, Jinja2Cpp supports the limited number of Jinja2 features. By the way, Jinja2Cpp is planned to be full [jinja2 specification](http://jinja.pocoo.org/docs/2.10/templates/)-conformant. The current support is limited to:
97
98
- expressions. You can use almost every style of expressions: simple, filtered, conditional, and so on.
98
-
- big number of filters (**sort, default, first, last, length, max, min, reverse, unique, sum, attr, map, reject, rejectattr, select, selectattr, pprint, dictsort, abs, float, int, list, round, random, trim, title, upper, wordcount, replace, truncate, groupby, urlencode, capitalize**)
99
+
- big number of filters (**sort, default, first, last, length, max, min, reverse, unique, sum, attr, map, reject, rejectattr, select, selectattr, pprint, dictsort, abs, float, int, list, round, random, trim, title, upper, wordcount, replace, truncate, groupby, urlencode, capitalize, escape**)
99
100
- big number of testers (**eq, defined, ge, gt, iterable, le, lt, mapping, ne, number, sequence, string, undefined, in, even, odd, lower, upper**)
100
101
- limited number of functions (**range**, **loop.cycle**)
101
102
- 'if' statement (with 'elif' and 'else' branches)
@@ -115,27 +116,20 @@ Full information about Jinja2 specification support and compatibility table can
115
116
116
117
## Supported compilers
117
118
Compilation of Jinja2Cpp tested on the following compilers (with C++14 and C++17 enabled features):
118
-
- Linux gcc 5.0
119
-
- Linux gcc 6.0
120
-
- Linux gcc 7.0
121
-
- Linux clang 5.0
122
-
- Linux clang 6.0
123
-
- Linux clang 7
124
-
- Linux clang 8
119
+
- Linux gcc 5.5 - 9.0
120
+
- Linux clang 5.0 - 9
125
121
- MacOS X-Code 9
126
122
- MacOS X-Code 10
127
123
- MacOS X-Code 11 (C++14 in default build, C++17 with externally-provided boost)
128
-
- Microsoft Visual Studio 2015 x86, x64
129
-
- Microsoft Visual Studio 2017 x86, x64
130
-
- Microsoft Visual Studio 2019 x86, x64
124
+
- Microsoft Visual Studio 2015 - 2019 x86, x64
131
125
- MinGW gcc compiler 7.3
132
126
- MinGW gcc compiler 8.1
133
127
134
128
**Note:** Support of gcc version >= 9.x or clang version >= 8.0 depends on version of Boost library provided.
@@ -176,12 +170,6 @@ In simpliest case to compile Jinja2Cpp you need:
176
170
> cmake --build . --target install
177
171
```
178
172
179
-
6. Also you can run the tests:
180
-
181
-
```
182
-
> ctest -C Release
183
-
```
184
-
185
173
In this case Jinja2Cpp will be built with internally-shipped dependencies and install them respectively. But Jinja2Cpp supports build with externally-provided deps. Different Jinja2Cpp usage scenarios can be found in this repository: https://github.com/jinja2cpp/examples-build
186
174
187
175
### Usage with conan.io dependency manager
@@ -191,11 +179,11 @@ Jinja2Cpp can be used as conan.io package. In this case you should do the follow
191
179
2. Register the following remote conan.io repositories:
The sample command is: `conan remote add martin https://api.bintray.com/conan/martinmoene/nonstd-lite`
197
185
198
-
3. Add reference to Jinja2Cpp package (`jinja2cpp/0.9.1@Manu343726/testing`) to your conanfile.txt, conanfile.py or CMakeLists.txt. For instance, with usage of `conan-cmake` integration it could be written this way:
186
+
3. Add reference to Jinja2Cpp package (`jinja2cpp/1.0.0@flexferrum/testing`) to your conanfile.txt, conanfile.py or CMakeLists.txt. For instance, with usage of `conan-cmake` integration it could be written this way:
199
187
200
188
```cmake
201
189
include (../../cmake/conan.cmake)
@@ -204,7 +192,7 @@ if (NOT MSVC)
204
192
endif ()
205
193
206
194
conan_cmake_run(REQUIRES
207
-
jinja2cpp/0.9.1@Manu343726/testing
195
+
jinja2cpp/1.0.0@flexferrum/testing
208
196
gtest/1.7.0@bincrafters/stable
209
197
BASIC_SETUP
210
198
${CONAN_SETTINGS}
@@ -231,7 +219,7 @@ You can define (via -D command line CMake option) the following build flags:
231
219
-**JINJA2CPP_BUILD_TESTS** (default TRUE) - to build or not to Jinja2Cpp tests.
-**JINJA2CPP_BUILD_SHARED** (default OFF) - Specify Jinja2Cpp library library link type.
234
-
-**MSVC_RUNTIME_TYPE** (default /MD) - MSVC runtime type to link with (if you use Microsoft Visual Studio compiler).
222
+
-**JINJA2CPP_MSVC_RUNTIME_TYPE** (default /MD) - MSVC runtime type to link with (if you use Microsoft Visual Studio compiler).
235
223
-**JINJA2CPP_DEPS_MODE** (default "internal") - modes for dependencies handling. Following values possible:
236
224
-`internal` In this mode Jinja2Cpp build script uses dependencies (include `boost`) shipped as subprojects. Nothing needs to be provided externally.
237
225
-`external-boost` In this mode Jinja2Cpp build script uses only `boost` as externally-provided dependency. All other dependencies taken from subprojects.
@@ -240,7 +228,7 @@ You can define (via -D command line CMake option) the following build flags:
240
228
241
229
242
230
### Build with C++17 standard enabled
243
-
In case of C++17 standard enabled for your project you should define `variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD` macro in the build settings.
231
+
In case of C++17 standard enabled for your project you should define `variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD nssv_CONFIG_SELECT_STRING_VIEW=nssv_STRING_VIEW_NONSTD optional_CONFIG_SELECT_OPTIONAL=optional_OPTIONAL_NONSTD` macros in the build settings.
244
232
245
233
## Acknowledgments
246
234
Thanks to **@manu343726** for CMake scripts improvement, bugs hunting and fixing and conan.io packaging.
@@ -258,6 +246,35 @@ Thanks to **@rmorozov** for stanitized builds setup
258
246
259
247
## Changelog
260
248
249
+
### Version 1.0.0
250
+
#### Changes and improvements
251
+
-`default` attribute added to the `map` filter (#48)
252
+
- escape sequences support added to the string literals (#49)
253
+
- arbitrary ranges, generated sequences, input iterators etc. now can be used with `GenericList` type (#66)
254
+
- nonstd::string_view is now one of the possible types for the `Value`
255
+
-`filter` tag support added to the template parser (#44)
256
+
-`escape` filter support added to the template parser (#140)
257
+
-`capitalize` filter support added to the template parser (#137)
258
+
- multiline version of `set` tag added to the parser (#45)
259
+
- added built-in reflection for nlohmann json and rapid json libraries (#78)
260
+
-`loop.depth` and `loop.depth0` variables support added
261
+
- {fmt} is now used as a formatting library instead of iostreams
262
+
- robin hood hash maps is now used for internal value storage
263
+
- rendering performance improvements
264
+
- template cache implemented in `TemplateEnv`
265
+
- user-defined callables now can accept global context via `*context` special param
266
+
- MinGW, clang >= 7.0, XCode >= 9, gcc >= 7.0 are now officially supported as a target compilers (#79)
267
+
268
+
#### Fixed bugs
269
+
- Fixed pipe (`|`) operator precedence (#47)
270
+
- Fixed bug in internal char <-> wchar_t converter on Windows
271
+
- Fixed crash in parsing `endblock` tag
272
+
- Fixed scope control for `include` and `for` tags
273
+
- Fixed bug with macros call within expression context
274
+
275
+
#### Breaking changes
276
+
- MSVC runtime type is now defines by `JINJA2CPP_MSVC_RUNTIME_TYPE` CMake variable
277
+
261
278
### Version 0.9.2
262
279
#### Major changes
263
280
- User-defined callables implemented. Now you can define your own callable objects, pass them as input parameters and use them inside templates as regular (global) functions, filters or testers. See details here: https://jinja2cpp.dev/docs/usage/ud_callables.html
0 commit comments