2425 Commits

Author SHA1 Message Date
strickczq
c40e828f03 fix fmt and clippy 2025-05-29 19:00:50 +02:00
strickczq
77b0763679 Track first line across calls and add tests
Fix logic issue where `self.first` was not tracked across calls, causing incorrect indentation.

Replaced `idx` with `is_first_line` flag.

Added `test_indent_chunked` to verify correct behavior.
2025-05-29 19:00:50 +02:00
strickczq
6653662d9e book: remove alloc feature mention for indent filter
Updated the "filters" chapter in the book to remove the mention of the alloc feature requirement for the indent filter, as it no longer relies on memory allocation.
2025-05-29 19:00:50 +02:00
strickczq
6d5473f801 fix alloc imports by indent.rs 2025-05-29 19:00:50 +02:00
strickczq
b54c5666c3 Move indent filter to separate indent.rs file
Relocated the `indent` filter implementation from alloc.rs to a new indent.rs file,
as it no longer requires memory allocation.

Updated module imports and exports in filters/mod.rs to reflect this change.

Removed unused dependencies
    (Cow, Deref, Pin) from alloc.rs.
2025-05-29 19:00:50 +02:00
strickczq
8c6d227ddb Rewrite indent filter to use IndentWriter
Refactored the `indent` filter implementation to introduce the `IndentWriter` struct,
eliminating the need for memory allocation.

Removed the `MAX_LEN` restriction and the `fuzzed_indent_filter` test,
as they are no longer necessary with the new approach.

Fixes #465.
2025-05-29 19:00:50 +02:00
Alexander Zaitsev
08682a3133
docs: Update performance.md (#188)
* docs: Update performance.md

- add documentation about PGO usage for optimizing Rinja's performance
2025-05-28 11:39:03 +02:00
Guillaume Gomez
39b957a1b3 Add issue templates 2025-05-28 03:17:01 +02:00
Guillaume Gomez
f3201cfb21
Merge pull request #456 from sinder38/update-ref-doc
Update `ref` documentation
2025-05-26 22:04:05 +02:00
René Kijewski
429aaf0821 Escape macro names like loop! 2025-05-23 21:01:00 +02:00
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
Guillaume Gomez
a2088e730a Add missing endcall in examples 2025-05-23 12:07:22 +02:00
Guillaume Gomez
7a53f7f942
Merge pull request #457 from Kijewski/pr-comp
Comparison operators cannot be chained
2025-05-23 10:20:04 +02:00
Michael Pollind
5bbaca527d add missing endcall for examples
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 19:35:53 -07: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
06c32d6d18 Allow super in calls 2025-05-22 23:04:52 +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
83057d8f30 Update askama_derive/src/generator/node.rs
Co-authored-by: Guillaume Gomez <guillaume1.gomez@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
b328a96ca4 simplify handler
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
5c07ea6842 address comments
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
7370f951a1 Update book/src/template_syntax.md
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
c88c4015d9 Update book/src/template_syntax.md
Co-authored-by: Guillaume Gomez <guillaume1.gomez@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
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