askama/testing/templates/allow-whitespaces.html
René Kijewski 462c04c0a0 Make JSON prettifying optional
This PR adds an optional argument to the `|tojson` filter, which
controls if the serialized JSON data gets prettified or not. The
arguments works the same as flask's [`|tojson`][flask] filter, which
passes the argument to python's [`json.dumps()`][python]:

* Omitting the argument, providing a negative integer, or `None`, then
  compact JSON data is generated.
* Providing a non-negative integer, then this amount of ASCII spaces is
  used to indent the data. (Capped to 16 characters.)
* Providing a string, then this string is used as prefix. I attempts are
  made to ensure that the prefix actually consists of whitespaces,
  because chances are, that if you provide e.g. `&nsbp;`, then you are
  doing it intentionally.

This is a breaking change, because it changes the default behavior to
not prettify the data. This is done intentionally, because this is how
it works in flask.

[flask]: https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.tojson
[python]: https://docs.python.org/3/library/json.html#json.dump
2024-06-25 00:12:25 +02:00

63 lines
1.7 KiB
HTML

{{ tuple.0 }}
{{ tuple .1 }}
{{ tuple. 2 }}
{{ tuple . 3 }}
{% let ( t0 , t1 , t2 , t3 , ) = tuple %}
{{ string }}
{{ string.len( ) }}
{{ string . len () }}
{{ string . len () }}
{{ string. len () }}
{{ string . len ( ) }}
{{ nested_1 . nested_2 . array [0] }}
{{ nested_1 .nested_2. array [ 1 ] }}
{{ nested_1 .nested_2. hash [ "key" ] }}
{% let array = nested_1.nested_2.array %}
{#
{% let array = nested_1.nested_2.array %}
{% let array = nested_1 . nested_2 . array %}
#}
{#
{% let hash = &nested_1.nested_2.hash %}
#}
{{ array| json(2) }}
{{ array[..]| json(2) }}{{ array [ .. ]| json(2) }}
{{ array[1..2]| json(2) }}{{ array [ 1 .. 2 ]| json(2) }}
{{ array[1..=2]| json(2) }}{{ array [ 1 ..= 2 ]| json(2) }}
{{ array[(0+1)..(3-1)]| json(2) }}{{ array [ ( 0 + 1 ) .. ( 3 - 1 ) ]| json(2) }}
{{-1}}{{ -1 }}{{ - 1 }}
{{1+2}}{{ 1+2 }}{{ 1 +2 }}{{ 1+ 2 }} {{ 1 + 2 }}
{{1*2}}{{ 1*2 }}{{ 1 *2 }}{{ 1* 2 }} {{ 1 * 2 }}
{{1 bitand 2}}{{ 1 bitand 2 }}{{ 1 bitand 2 }}{{ 1 bitand 2 }} {{ 1 bitand 2 }}
{{1 bitor 2}}{{ 1 bitor 2 }}{{ 1 bitor 2}}{{1 bitor 2 }} {{1 bitor 2}}
{{true}}{{false}}
{{!true}}{{ !true }}{{ ! true }}
{#
{{true&&false}}{{ true&&false }}{{ true &&false }}{{ true&& false }} {{ true && false }}
{{true||false}}{{ true||false }}{{ true ||false }}{{ true|| false }} {{ true || false }}
#}
{{ self.f0() }}{{ self.f0 () }}{{ self.f0 ( ) }}
{{ self.f1("1") }}{{ self.f1 ( "1" ) }}{{ self.f1 ( "1" ) }}
{{ self.f2("1","2") }}{{ self.f2 ( "1" ,"2" ) }}{{ self.f2 ( "1" , "2" ) }}
{% for s in 0..5 %}{% endfor %}
{% for s in 0 .. 5 %}{% endfor %}
{% match option %}
{% when Option :: Some with ( option ) %}
{% when std :: option :: Option :: None %}
{% endmatch %}
{{ std::string::String::new () }}
{#
{{ ::std::string::String::new () }}
#}