544 Commits

Author SHA1 Message Date
René Kijewski
377253945e crate! etc are invalid macro names 2025-05-23 21:01:00 +02:00
Guillaume Gomez
657dcea10f
Merge pull request #422 from pollend/feature/add-support-for-caller
feat: add caller pattern from jinja
2025-05-23 13:57:18 +02:00
René Kijewski
eaccbb02ae Comparison operators cannot be chained 2025-05-23 01:26:19 +02:00
Guillaume Gomez
1acbc33383 Improve error output 2025-05-22 23:11:46 +02:00
Guillaume Gomez
aefd0848af Fix test_short_circuit test 2025-05-22 23:07:27 +02:00
Guillaume Gomez
3ab930ded0 Fix handling of endcall whitespace characters 2025-05-22 22:50:40 +02:00
Michael Pollind
f08ca469c9 add more test add reserved word caller
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
c4fcd4781a address comments
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
0547c2ee88 fix caller logic
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
ef489b60f6 add test cases and rework spaces
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
8862325e9b tweak test
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
ce73e73720 feat: add caller pattern and adjust syntax to closer match jinja
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
b8c85a07bd feat: add caller pattern for macro
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:39 +02:00
René Kijewski
f92ed0a074 Deny self etc. as path element 2025-05-20 21:20:55 +02:00
René Kijewski
1b2c54620e name is its own span 2025-05-20 21:19:57 +02:00
Guillaume Gomez
5099820722 Add test to ensure that self can be used as match argument 2025-05-20 18:37:39 +02:00
Guillaume Gomez
8b05a5c118 Add ui tests for crate, Self and super as identifiers 2025-05-20 18:37:39 +02:00
René Kijewski
75dd2c92f3 Update dependencies
* Update version-incompatible dependencies in examples.
* Update version-incompatible dev-dependencies.
* Replaced deprecated `criterion::black_box`.
* Add `features = "simd"` to `winnow`. This adds a transitive
  dependency to `memchr`, on which we already depend on directly.
2025-05-18 23:06:41 +02:00
René Kijewski
3775f4e3a3 Use unicode-ident to determine what is an identifier
Resolves <https://github.com/askama-rs/askama/issues/442>.

The performance is actually slightly better than before. `unicode-ident`
is highly optimized and jump free.

One test from a fuzzer outcome had to be deleted, because it contained
identifiers that weren't actually identifiers. There is still a test
that tests the same problem, but every identifier is simply `x`. In
another fuzzed test a character [`U+E0049`] was removed.

[`U+E0049`]: https://en.wikipedia.org/w/index.php?oldid=1278382889

<details>
<summary>Benchmark results</summary>

```text
$ cd askama_parser && cargo bench

librustdoc/all          time:   [184.47 µs 185.30 µs 186.08 µs]
                        thrpt:  [75.887 MiB/s 76.207 MiB/s 76.548 MiB/s]
                 change:
                        time:   [−1.4364% −0.9672% −0.4738%] (p = 0.00 < 0.05)
                        thrpt:  [+0.4761% +0.9767% +1.4573%]
                        Change within noise threshold.

librustdoc/item_info    time:   [3.3880 µs 3.3892 µs 3.3906 µs]
                        thrpt:  [46.409 MiB/s 46.428 MiB/s 46.445 MiB/s]
                 change:
                        time:   [−3.8735% −3.5927% −3.2949%] (p = 0.00 < 0.05)
                        thrpt:  [+3.4071% +3.7266% +4.0296%]
                        Performance has improved.

librustdoc/item_union   time:   [20.052 µs 20.087 µs 20.126 µs]
                        thrpt:  [49.044 MiB/s 49.140 MiB/s 49.224 MiB/s]
                 change:
                        time:   [−2.2419% −1.8647% −1.5113%] (p = 0.00 < 0.05)
                        thrpt:  [+1.5345% +1.9002% +2.2933%]
                        Performance has improved.

librustdoc/page         time:   [85.828 µs 86.157 µs 86.518 µs]
                        thrpt:  [71.571 MiB/s 71.871 MiB/s 72.147 MiB/s]
                 change:
                        time:   [−1.2728% −0.7668% −0.2512%] (p = 0.00 < 0.05)
                        thrpt:  [+0.2518% +0.7727% +1.2892%]
                        Change within noise threshold.

librustdoc/print_item   time:   [10.065 µs 10.101 µs 10.138 µs]
                        thrpt:  [93.132 MiB/s 93.469 MiB/s 93.806 MiB/s]
                 change:
                        time:   [−3.3793% −2.8352% −2.3267%] (p = 0.00 < 0.05)
                        thrpt:  [+2.3821% +2.9180% +3.4975%]
                        Performance has improved.

librustdoc/short_item_info
                        time:   [9.0741 µs 9.1018 µs 9.1377 µs]
                        thrpt:  [99.148 MiB/s 99.540 MiB/s 99.843 MiB/s]
                 change:
                        time:   [−4.7480% −4.2335% −3.7763%] (p = 0.00 < 0.05)
                        thrpt:  [+3.9245% +4.4207% +4.9847%]
                        Performance has improved.

librustdoc/sidebar      time:   [21.468 µs 21.555 µs 21.648 µs]
                        thrpt:  [57.004 MiB/s 57.252 MiB/s 57.482 MiB/s]
                 change:
                        time:   [−3.7641% −3.0465% −2.4191%] (p = 0.00 < 0.05)
                        thrpt:  [+2.4791% +3.1423% +3.9114%]
                        Performance has improved.

librustdoc/source       time:   [7.9602 µs 7.9780 µs 7.9929 µs]
                        thrpt:  [92.230 MiB/s 92.403 MiB/s 92.609 MiB/s]
                 change:
                        time:   [−1.6386% −1.0684% −0.5875%] (p = 0.00 < 0.05)
                        thrpt:  [+0.5910% +1.0799% +1.6659%]
                        Change within noise threshold.

librustdoc/type_layout_size
                        time:   [4.7821 µs 4.7915 µs 4.8017 µs]
                        thrpt:  [56.406 MiB/s 56.526 MiB/s 56.637 MiB/s]
                 change:
                        time:   [−1.9743% −1.4867% −1.0153%] (p = 0.00 < 0.05)
                        thrpt:  [+1.0257% +1.5091% +2.0141%]
                        Performance has improved.

librustdoc/type_layout  time:   [15.022 µs 15.051 µs 15.076 µs]
                        thrpt:  [178.57 MiB/s 178.88 MiB/s 179.22 MiB/s]
                 change:
                        time:   [−1.5028% −1.0358% −0.5705%] (p = 0.00 < 0.05)
                        thrpt:  [+0.5738% +1.0466% +1.5257%]
                        Change within noise threshold.
```
</details>
2025-05-18 23:04:47 +02:00
René Kijewski
ab798e2482 Allow filters with explicit path
IMHO that makes custom filters much easier to use.
2025-05-17 13:20:54 +02:00
René Kijewski
6ce85f318c Make code generator re-usable for other projects
This PR
* removes the crate `askama_derive_standalone`,
* makes `askama_derive` a normal library, and
* adds the proc-macro crate `askama_macros`,

Before, it was not possible for another crate to re-export
`askama::Template` in a useful way, because the generated code assumes
that it has access to an `extern crate askama`.

`askama_derive` will export the function `derive_template()` like
`askama_derive_standalone` did, but it has an additional argument to
accept a `TokenStream` that should contain (an) statement(s) to define
the identifier `askama`, e.g. `quote! { extern crate askama; }`.

The new proc-macro crate `askama_macros` now defines the derive-macro
`Template` by calling `askama_derive::derive_template()`.

Prior art: [`encase`] → [`encase_derive`] → [`encase_derive_impl`];
[2298a3e].

[`encase`]: <https://crates.io/crates/encase/0.11.0>
[`encase_derive`]: <https://crates.io/crates/encase_derive/0.11.0>
[`encase_derive_impl`]: <https://crates.io/crates/encase_derive_impl/0.11.0>
[2298a3e]: <2298a3efd5>
2025-05-17 13:20:21 +02:00
C0D3 M4513R
c31fce773e
Relax Sized constraint on impl FastWritable for Cow (#432)
* Add test to ensure `Cow<'_, str>` implements `FastWritable`

* Relax Sized constraint on `impl FastWritable for Cow`

* Run rustfmt

Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>

* Put "test" in a const block.

* Update cow_str_implements_fast_writable.rs

Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>

---------

Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>
Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>
2025-05-07 17:11:45 +02:00
René Kijewski
a7c55f77fe generator: fix ensure_no_named_arguments() test
The wrong `Expr` variant was tested.
2025-05-02 00:54:18 +02:00
René Kijewski
72bbe3ede1 Bump version number to v0.14.0 2025-04-22 23:37:23 +02:00
Guillaume Gomez
6a16256f24 Fix new clippy lints 2025-04-22 11:34:55 +02:00
Guillaume Gomez
04a4d5b020 Update MSRV to 1.83 2025-04-22 11:34:55 +02:00
Guillaume Gomez
6f912abee6 Move FastWritable into askama root 2025-04-22 11:33:57 +02:00
Guillaume Gomez
7c5deda4c1 Rename pluralize arguments into singular and plural 2025-04-21 23:11:24 +02:00
René Kijewski
b402936db3 generator: add named arguments for filters 2025-04-21 23:11:24 +02:00
René Kijewski
4be302338a generator: do argument coercion for |truncate / |center
Don't simply pass any arguments to the filter. The error message won't
be useful otherwise. Also ensure that the argument is a `usize`.
2025-04-21 23:11:24 +02:00
René Kijewski
94fddd4df5 book: add page about FastWritable 2025-04-19 22:09:28 +02:00
René Kijewski
ba33974996 Let |indent use AsIndent 2025-04-17 15:07:21 +02:00
René Kijewski
c6d45e1cdc Always supply values to custom filters 2025-04-15 17:15:47 +02:00
René Kijewski
f7fc39d138 Implement |wordcount filter with access to runtime values 2025-04-15 13:24:19 +02:00
René Kijewski
22648acf08 book: how to access runtime values in custom filters 2025-04-15 13:24:19 +02:00
René Kijewski
20af543610 Pass values through alloc filters, too 2025-04-15 13:24:18 +02:00
René Kijewski
d6bf966048 Pass variables to sub-templates more reliably even if indirectly 2025-04-15 13:13:35 +02:00
Guillaume Gomez
ddfdd20855 Do not put question mark initialization expressions behind a reference 2025-04-12 21:52:14 +02:00
Guillaume Gomez
8081d717d3 If using local variable as value when creating a new variable, do not put it behind a reference 2025-04-11 07:19:59 +02:00
Guillaume Gomez
d3f0947d11 Track config files 2025-03-31 22:41:49 +02:00
René Kijewski
697862a76c Bump version number to 0.13.0 2025-03-27 17:22:37 +01:00
René Kijewski
19f6582308 Bump version number to v0.13.0-pre.0 2025-03-17 21:32:27 +01:00
Guillaume Gomez
3b52c907c3 Rename rinja into askama 2025-03-11 19:31:06 +01:00
René Kijewski
13eea3bd74 derive: fail if requested template block is missing
Previously it was only tested if the block exists if there were any
blocks. If there weren't any, then an empty result would be rendered.
2025-02-08 23:00:54 +01:00
René Kijewski
137aaa0604 derive: implement template attribute blocks 2025-02-08 02:07:01 +01:00
René Kijewski
f0ded0ba32 derive: add span to missing block message 2025-02-07 23:29:04 +01:00
René Kijewski
f759c364f9 derive: no rinja on enum variants 2025-02-07 23:20:12 +01:00
René Kijewski
c13059096e Fix error messages 2025-02-04 22:45:40 +01:00
Guillaume Gomez
f361293da7 Improve macro call arguments mismatch errors 2025-02-04 22:45:40 +01:00
René Kijewski
30e664182d derive: for enums, let Self refer to the original type 2025-02-04 01:24:59 +01:00