mirror of
https://github.com/pantor/inja.git
synced 2026-08-18 05:13:18 +00:00
test and doc whitespace control for expressions
This commit is contained in:
@@ -260,13 +260,14 @@ env.set_trim_blocks(true);
|
|||||||
env.set_lstrip_blocks(true);
|
env.set_lstrip_blocks(true);
|
||||||
```
|
```
|
||||||
|
|
||||||
With both `trim_blocks` and `lstrip_blocks` enabled, you can put statements on their own lines. Furthermore, you can also strip whitespaces by hand. If you add a minus sign (`-`) to the start or end of a statement, the whitespaces before or after that block will be removed:
|
With both `trim_blocks` and `lstrip_blocks` enabled, you can put statements on their own lines. Furthermore, you can also strip whitespaces for both statements and expressions by hand. If you add a minus sign (`-`) to the start or end, the whitespaces before or after that block will be removed:
|
||||||
|
|
||||||
```.cpp
|
```.cpp
|
||||||
|
render("Hello {{- name -}} !", data); // "Hello Inja!"
|
||||||
render("{% if neighbour in guests -%} I was there{% endif -%} !", data); // Renders without any whitespaces
|
render("{% if neighbour in guests -%} I was there{% endif -%} !", data); // Renders without any whitespaces
|
||||||
```
|
```
|
||||||
|
|
||||||
Stripping behind a statement also remove any newlines.
|
Stripping behind a statement or expression also removes any newlines.
|
||||||
|
|
||||||
### Callbacks
|
### Callbacks
|
||||||
|
|
||||||
|
|||||||
@@ -204,6 +204,10 @@ TEST_CASE("templates") {
|
|||||||
CHECK(env.render("Test\n {%- if is_happy %}{{ name }}{% endif %} ", data) == "Test\nPeter ");
|
CHECK(env.render("Test\n {%- if is_happy %}{{ name }}{% endif %} ", data) == "Test\nPeter ");
|
||||||
CHECK(env.render(" {%+ if is_happy %}{{ name }}{% endif %}", data) == " Peter");
|
CHECK(env.render(" {%+ if is_happy %}{{ name }}{% endif %}", data) == " Peter");
|
||||||
CHECK(env.render(" {%- if is_happy %}{{ name }}{% endif -%} \n ", data) == "Peter");
|
CHECK(env.render(" {%- if is_happy %}{{ name }}{% endif -%} \n ", data) == "Peter");
|
||||||
|
|
||||||
|
CHECK(env.render(" {{- name -}} \n ", data) == "Peter");
|
||||||
|
CHECK(env.render("Test\n {{- name }} ", data) == "Test\nPeter ");
|
||||||
|
CHECK(env.render(" {{ name }}\n ", data) == " Peter\n ");
|
||||||
|
|
||||||
// Nothing will be stripped if there are other characters before the start of the block.
|
// Nothing will be stripped if there are other characters before the start of the block.
|
||||||
CHECK(env.render(". {%- if is_happy %}{{ name }}{% endif -%}\n", data) == ". Peter");
|
CHECK(env.render(". {%- if is_happy %}{{ name }}{% endif -%}\n", data) == ". Peter");
|
||||||
|
|||||||
Reference in New Issue
Block a user