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
I think previous input for filter-recursion ui test was not right as it
was not triggering error for recursion itself, for example:
```rust
fn fuzzed_filter_recursion() {
const TEMPLATE: &str = include_str!("../tests/filter-recursion.txt");
if let Err(e) = Ast::from_str(TEMPLATE, None, &Syntax::default()) {
panic!("{e}");
}
}
```
```sh
---- tests::fuzzed_filter_recursion stdout ----
thread 'tests::fuzzed_filter_recursion' panicked at rinja_parser/src/tests.rs:1121:9:
failed to parse template source at row 1, column 255 near:
"|A|AA|A|A|A|A|AA|A|A|A|A|AA|A|A|A|A|AA|A"...
```
Cloning a TokenStream is not for free. This change lets criterion do the
cloning outside of the measured time, and blackboxing is done by
criterion, too.
The benchmark runs ~10% faster, now.
This PR adds the crate "rinja_derive_standalone", which is just like
"rinja_derive", though not a "proc_macro". This way we can easily expose
it's internals for testing and benchmarking.
Right now, the PR is more or less a prove of concept, and it probably
needs a handful more useful benchmark use cases to be worth the hassle.