2445 Commits

Author SHA1 Message Date
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
9215884c1a add docs
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:39 +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
sinder
0ce68a32f8 Change deprecated as_ref to ref
Add a line about `ref` renaming to the upgrade guide
2025-05-22 22:46:24 +08:00
Dominique Martinet
cd13e4f148
book: upgrading: complete note about filter change (#453)
commit c6d45e1cdc0f ("Always supply `values` to custom filters") added a
second mandatory argument, and it was not obvious what broke on upgrade
through the current explanation so write a bit more about it.
2025-05-22 16:17:12 +02:00
Guillaume Gomez
bbd5285381
Merge pull request #450 from GuillaumeGomez/crate-identifier
Prevent `crate` to be used as identifier
2025-05-20 23:27:23 +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
Guillaume Gomez
244980e0e9 Prevent crate, Self and super to be used as identifiers 2025-05-20 18:31:08 +02:00
Guillaume Gomez
6ac39d24d9
Merge pull request #446 from Kijewski/pr-parse-source-crash
Print invalid generated code during panic
2025-05-19 16:36:03 +02:00
Guillaume Gomez
00f9c7068d
Merge pull request #448 from Kijewski/pr-int-base
derive: don't suppress fatal errors in integer parsing
2025-05-19 13:07:37 +02:00
René Kijewski
359da68fa0 derive: don't suppress fatal errors in integer parsing 2025-05-19 11:59:37 +02:00
Guillaume Gomez
df2e35063f
Merge pull request #441 from Kijewski/pr-dependencies
Update dependencies
2025-05-19 11:31:29 +02:00
René Kijewski
f4aa0cef9a Print invalid generate code during panic 2025-05-19 08:17:56 +02:00
René Kijewski
e99f612391 Drive-by fixes 2025-05-18 23:06:42 +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
3e5562dc7c
derive: prefix more generated variables with __askama (#444)
* _did_loop → __askama_did_loop

* _iter → __askama_iter

* bool → askama::helpers::core::primitive::bool

* _loop_item → __askama_item
2025-05-18 23:05:18 +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
Guillaume Gomez
37101cb95d
Merge pull request #440 from Kijewski/pr-fuzz-derive
Fuzz code generator, too
2025-05-18 00:01:43 +02:00
René Kijewski
e2aa22d423 ci: disable Cluster-Fuzz until there is a seed corpus for derive 2025-05-17 23:31:03 +02:00
René Kijewski
b716014612 Fuzz code generator, too 2025-05-17 23:21:45 +02:00
René Kijewski
e80b710f67 derive: add feature to disable all file system access
If you want to fuzz the code generator, it's essential that no local
files are accessed, e.g. through `{% import %}`.

This DOES NOT mean that the generated code is safe; this is not a
sandbox. The generated code can still contain

* evil compile-time code: `{{ include_str!("/etc/passwd") }}`
* evil runtime code: `{{ std::fs::remove_dir_all("/home/user") %}`

But during the code generation nothing potentially bad should happen.
2025-05-17 23:08:27 +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
Guillaume Gomez
428ff19932
Merge pull request #436 from Kijewski/pr-no-loop-first
`loop.first` is known by being at `index == 0`
2025-05-17 11:49:05 +02:00
Guillaume Gomez
38455c46d7
Merge pull request #437 from Kijewski/pr-more-fuzz
Fuzz more filters
2025-05-17 11:48:37 +02:00
René Kijewski
0ad2a3d973 Fuzz more filters
Added: `|escape`, `|filesizeformat`, `|join`, `|json`, `|json(..)`,
`|unique`, and `|wordcount`.
2025-05-16 16:23:20 +02:00
René Kijewski
73e8559ca7 loop.first is known by being at index == 0 2025-05-16 16:08:01 +02:00
Guillaume Gomez
d23c5b2f3e
Merge pull request #438 from Kijewski/pr-clippy
Fix new clippy warnings in rust 1.89
2025-05-16 10:13:37 +02:00
René Kijewski
ed216e5b2c Fix new clippy warnings in rust 1.89 2025-05-16 03:26:19 +02:00
Guillaume Gomez
150becaf0f
Merge pull request #433 from Kijewski/pr-linguist
Ignore fuzzing corpus from source line count
2025-05-13 07:43:27 +02:00
René Kijewski
077b83631a Ignore fuzzing corpus from source line count
Github's language statistics for the project say that 43% of askama is
assembly code. It is not. The heuristic counts our fuzzing corpus as
assembly code, and the corpus is quite big.

This PR excludes the corpus from being counted.
2025-05-12 18:38:43 +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
Guillaume Gomez
73ba176ad5
Merge pull request #426 from Kijewski/pr-ensure_no_named_arguments
generator: fix `ensure_no_named_arguments()` test
2025-05-02 11:13:29 +02:00
Guillaume Gomez
4a7de4fde4
Merge pull request #427 from Kijewski/pr-remove-zizmor
ci: remove zizmor test
2025-05-02 11:13:02 +02:00
René Kijewski
979f9d8ef4 ci: remove zizmor test
It was a small script to test common Github action config errors, but
IMHO it became more opinionated with every release. No, I won't add a
hashsum to every `uses` line, thank you for asking again and again.

Also, it takes 3 minutes to build by now. 3 minutes until the first real
test is executed.
2025-05-02 01:09:35 +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
Guillaume Gomez
90d1a71801
Merge pull request #423 from m4tx/fix-function-docs
chore: fix tiny wording error in "Calling functions" docs
2025-04-30 18:19:14 +02:00
Mateusz Maćkowski
44c67d3ba1
chore: fix tiny wording error in "Calling functions" docs 2025-04-30 18:15:21 +02:00
Guillaume Gomez
9b41bb9ff5
Merge pull request #421 from Kijewski/pr-inline
Add missing `#[inline]` annotations
2025-04-29 11:49:37 +02:00
René Kijewski
01e9d3c640 Add missing #[inline] annotations 2025-04-27 21:30:19 +02:00
René Kijewski
bf5e066b68 generator: remove invisible group from output
The generated `TokenStream` gets parsed correctly by `rustc`, but fails
to be parsed by `syn` in some circumstances. E.g. the template syntax
`test {#` lets the playground crash.

This PR removes the invisible group.
2025-04-26 22:24:26 +02:00
dependabot[bot]
3cdc0ea4c1 build(deps): bump astral-sh/setup-uv from 5 to 6
Bumps [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) from 5 to 6.
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](https://github.com/astral-sh/setup-uv/compare/v5...v6)

---
updated-dependencies:
- dependency-name: astral-sh/setup-uv
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-25 01:17:27 +02:00
Guillaume Gomez
95867ac8ce
Merge pull request #416 from Kijewski/pr-upgrading-0.14
Get ready for v0.14.0
v0.14.0
2025-04-23 15:12:34 +02:00
René Kijewski
61b7422497 Add |titlecase as alias for |title 2025-04-22 23:37:23 +02:00
René Kijewski
79be271593 Run doctests 2025-04-22 23:37:23 +02:00
René Kijewski
72bbe3ede1 Bump version number to v0.14.0 2025-04-22 23:37:23 +02:00
René Kijewski
57750338fa book: update upgrading.md 2025-04-22 23:37:23 +02:00