2584 Commits

Author SHA1 Message Date
Guillaume Gomez
1da2840071 Fix book code examples 2025-08-17 14:59:12 +02:00
Guillaume Gomez
edcaa61fb6 Add new test to check syntax of book examples 2025-08-17 14:59:12 +02:00
Guillaume Gomez
06d6ec37f6
Merge pull request #573 from Kijewski/pr-linkfix
readme: fix a link, include readmes in `lib.rs`
2025-08-16 21:03:27 +02:00
René Kijewski
016fe82199 readme: fix a link, include readmes in lib.rs 2025-08-15 13:06:10 +02:00
Markus Ebner
59a982028e Fix #563: filesizeformat with proper accuracy 2025-08-13 12:26:25 +02:00
Guillaume Gomez
e40da12343
Merge pull request #569 from GuillaumeGomez/old-paths
Fix invalid handling of paths starting with `::`
2025-08-13 11:39:04 +02:00
Guillaume Gomez
e8572f4580 Fix invalid handling of paths starting with :: 2025-08-13 11:20:49 +02:00
dependabot[bot]
680121125a build(deps): bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-12 14:55:17 +02:00
Guillaume Gomez
885e0f7de1 Fix wrong span context for askama variables 2025-08-12 14:54:51 +02:00
Guillaume Gomez
756717c2f7
Merge pull request #560 from Kijewski/pr-inputstream
parser: use `LocatingSlice<&str>` instead of `&str`
2025-08-08 11:59:40 +02:00
René Kijewski
1014b975cd Fix new clippy warnings 2025-08-07 20:55:28 +02:00
René Kijewski
98ad5d5b3f parser: better messages for (group) 2025-08-07 20:48:15 +02:00
René Kijewski
c0d6f0f0fc parser: a little better spans 2025-08-07 20:39:38 +02:00
René Kijewski
329771152d parser: use LocatingSlice<&str> instead of &str
This will enable better span getting in subsequent PRs.
2025-08-07 18:41:51 +02:00
Guillaume Gomez
e9021aa1a5
Merge pull request #557 from Kijewski/pr-rustc_hash
parser/derive: use only one hasher throughout the proc_macro
2025-08-06 21:05:53 +02:00
René Kijewski
267a115672 parser/derive: use only one hasher throughout the proc_macro 2025-08-06 20:41:20 +02:00
René Kijewski
3a677870d9 derive: remove unneeded .to_string() call
The invocation is not only bad for performance, but also not necessarily
correct:
* The output of `TokenStream::to_string()` is free to add spaces between
  `self` and `.`, or before `self`.
* The `.` might belong to `..` or `..=`.
2025-08-06 19:11:26 +02:00
René Kijewski
58bb4d921f derive: remove trait BufferFmt 2025-08-06 19:11:26 +02:00
René Kijewski
f62cdfb49a derive: better spans for Target 2025-08-06 19:11:26 +02:00
René Kijewski
e1eeb815ea derive: minor macro clean-ups
* prefix temporaries in `{{ expr }}` with `__askama`
* replace custom `spanned!(..)` with `quote_spanned!(..)`
* replace `buf.write_tokens(quote_spanned!(..))` with `quote_into!(..)`
2025-08-06 19:11:26 +02:00
René Kijewski
693f86d1c4 derive: don't use format_args! for code formatting
* No need to manually escape raw identifiers
* Allow a few warnings
2025-08-06 19:11:26 +02:00
Guillaume Gomez
7dbbe397f9 Fix clippy lints 2025-08-06 19:11:26 +02:00
Guillaume Gomez
da850d736f Implement print = "code" on enums 2025-08-06 19:11:26 +02:00
Guillaume Gomez
80a4af7f2d Generate a TokenStream rather than a String 2025-08-06 19:11:26 +02:00
Guillaume Gomez
89024013dd Put Raw::lit field into a span 2025-08-06 19:11:26 +02:00
Guillaume Gomez
54be12a6e0 Add missing span information for parsing error 2025-08-06 19:11:26 +02:00
Guillaume Gomez
dd5e21f1de
Merge pull request #555 from seijikun/mr-docs
Minor documentation fixes
2025-08-01 17:20:17 +02:00
Markus Ebner
e2da496855
Minor documentation fixes 2025-08-01 17:14:42 +02:00
Guillaume Gomez
ea947736a5
Merge pull request #554 from seijikun/mr-docs
Improve documentation
2025-08-01 10:57:35 +02:00
Markus Ebner
4959191aca
Improve documentation
- Reference the HtmlSafe trait for nested templates
- Document new call expression syntax for macro invocations
- Show nested macro caller aliasing
- Document parallel frontend for faster debug recompile times
2025-08-01 02:27:29 +02:00
René Kijewski
1f3c926c58 parser: r#self is not a valid raw identifier in macro calls
It's not a valid raw identifier anywhere, actually, but the other cases
(in a path, as a field name, as a macro name) were already handled.

Resolves <https://issues.oss-fuzz.com/issues/435218013>.
2025-07-31 18:46:35 +02:00
Guillaume Gomez
d12afffc26
Merge pull request #546 from Kijewski/pr-relative-path
derive: track included files with relative path
2025-07-31 14:37:11 +02:00
René Kijewski
6035ffb013 derive: track included files with relative path
To make the compiler understand which files contributed to the generated
code, in order to make it aware when a recompilation is needed, we track
the file paths using `include_bytes!()` calls in the generated code.
This can be a problem for reproducible builds, because the working
directory contributes to the file hash.

This PR makes Askama generate relative paths if possible. This is always
possible on Unix systems, but on Windows hosts absolute paths have to be
used if the code is kept on different drives.
2025-07-30 19:21:09 +02:00
René Kijewski
e1fb7ee98b derive: copy path_clean::clean() and pathdiff::diff_paths()
The function `clean()` was copied from the project [`path_clean`] in version 1.0.1 (rev. [`d8948ae`]).
License: MIT OR Apache-2.0.
Authors: Dan Reeves <hey@danreev.es>, Alex Guerra <alex@heyimalex.com>, Adam Reichold

The function `diff_paths()` was copied in from the project [`pathdiff`] in version 0.2.3 (rev. [`5180ff5`]).
License: MIT OR Apache-2.0.
Copyright 2012-2015 The Rust Project Developers.

Please see their commit history for more information.

[`path_clean`]: <https://github.com/danreeves/path-clean>
[`pathdiff`]: <https://github.com/Manishearth/pathdiff>
[`d8948ae`]: <d8948ae69d/src/lib.rs (L50-L86)>
[`5180ff5`]: <5180ff5b23/src/lib.rs (L18-L86)>
2025-07-30 19:05:45 +02:00
René Kijewski
d670d9b91c parser: fail on unterminated byte literal
Resolves <https://issues.oss-fuzz.com/issues/433650278>.

Also, I noticed that an Unicode escape in a byte literal, e.g.
`b'\u{42}'`, was accepted when it should not have been.
2025-07-28 21:56:40 +02:00
Guillaume Gomez
ec17ed4813
Merge pull request #548 from Kijewski/pr-fix-rtd
book: first install mdbook, then use it
2025-07-28 20:56:27 +02:00
René Kijewski
c00a774ed2 book: first install mdbook, then use it
This is follow up to [#544], which makes `update-theme.py` use `mdbook`
itself to build `index.hbs`. `mdbook` needs to be installed to be used,
though.

[#544]: <https://redirect.github.com/askama-rs/askama/pull/544>
2025-07-28 19:58:22 +02:00
Guillaume Gomez
7d2d7a2b59
Merge pull request #544 from Kijewski/pr-update-mdbook
book: update `mdbook` version and highlight `jinja` blocks
2025-07-28 17:31:34 +02:00
Guillaume Gomez
11da13eeb8
Merge pull request #543 from Kijewski/143907
parser: remove one indirection in `punction()` finding
2025-07-28 17:30:57 +02:00
René Kijewski
ab1c3d499c book: update mdbook version and highlight jinja blocks 2025-07-27 02:44:34 +02:00
René Kijewski
6d849880d9 parser: remove one indirection in punction() finding 2025-07-26 00:51:39 +02:00
René Kijewski
b8e11e86b6 parser/derive: replaces usages of Expr/Node with Box<Expr>/Box<Node>
This means that there is much less copying of data done at runtime.

Two new `unsafe` transmutations had to be added, both in the same
function, because even though `&T` and `Box<T>` have the same layout,
rust currently rejects any `Box`es in a `const` value. Miri is happy
with `askama_derive`'s tests.

<details>
<summary>askama_derive benchmark</summary>

```text
synthetic/hello_world   time:   [35.108 µs 35.271 µs 35.412 µs]
                        thrpt:  [1.3735 MiB/s 1.3790 MiB/s 1.3854 MiB/s]
                 change:
                        time:   [−6.2826% −5.1769% −4.1151%] (p = 0.00 < 0.05)
                        thrpt:  [+4.2917% +5.4595% +6.7038%]
                        Performance has improved.

librustdoc/item_info.html
                        time:   [39.687 µs 39.957 µs 40.186 µs]
                        thrpt:  [3.9157 MiB/s 3.9381 MiB/s 3.9649 MiB/s]
                 change:
                        time:   [−3.5603% −2.5102% −1.3793%] (p = 0.00 < 0.05)
                        thrpt:  [+1.3986% +2.5749% +3.6917%]
                        Performance has improved.

librustdoc/item_union.html
                        time:   [101.64 µs 101.95 µs 102.27 µs]
                        thrpt:  [9.6516 MiB/s 9.6818 MiB/s 9.7111 MiB/s]
                 change:
                        time:   [−4.0638% −3.5966% −3.1652%] (p = 0.00 < 0.05)
                        thrpt:  [+3.2686% +3.7307% +4.2359%]
                        Performance has improved.

librustdoc/page.html    time:   [379.80 µs 381.74 µs 383.65 µs]
                        thrpt:  [16.140 MiB/s 16.221 MiB/s 16.304 MiB/s]
                 change:
                        time:   [−6.6429% −5.2611% −4.3384%] (p = 0.00 < 0.05)
                        thrpt:  [+4.5351% +5.5533% +7.1156%]
                        Performance has improved.

librustdoc/print_item.html
                        time:   [88.483 µs 88.849 µs 89.313 µs]
                        thrpt:  [10.571 MiB/s 10.626 MiB/s 10.670 MiB/s]
                 change:
                        time:   [−2.5658% −2.0639% −1.5517%] (p = 0.00 < 0.05)
                        thrpt:  [+1.5761% +2.1074% +2.6333%]
                        Performance has improved.

librustdoc/short_item_info.html
                        time:   [90.028 µs 90.157 µs 90.281 µs]
                        thrpt:  [10.035 MiB/s 10.049 MiB/s 10.063 MiB/s]
                 change:
                        time:   [−2.4814% −1.9435% −1.3640%] (p = 0.00 < 0.05)
                        thrpt:  [+1.3829% +1.9821% +2.5445%]
                        Performance has improved.

librustdoc/sidebar.html time:   [106.91 µs 108.17 µs 109.57 µs]
                        thrpt:  [11.263 MiB/s 11.408 MiB/s 11.543 MiB/s]
                 change:
                        time:   [−4.2433% −3.3985% −2.6066%] (p = 0.00 < 0.05)
                        thrpt:  [+2.6763% +3.5181% +4.4314%]
                        Performance has improved.

librustdoc/source.html  time:   [71.149 µs 71.416 µs 71.652 µs]
                        thrpt:  [10.289 MiB/s 10.322 MiB/s 10.361 MiB/s]
                 change:
                        time:   [−2.7381% −2.1144% −1.5588%] (p = 0.00 < 0.05)
                        thrpt:  [+1.5835% +2.1601% +2.8152%]
                        Performance has improved.

librustdoc/type_layout.html
                        time:   [88.405 µs 88.920 µs 89.595 µs]
                        thrpt:  [30.049 MiB/s 30.277 MiB/s 30.453 MiB/s]
                 change:
                        time:   [+0.6665% +1.8855% +3.0267%] (p = 0.00 < 0.05)
                        thrpt:  [−2.9378% −1.8506% −0.6621%]
                        Change within noise threshold.

librustdoc/type_layout_size.html
                        time:   [44.048 µs 44.246 µs 44.398 µs]
                        thrpt:  [6.1004 MiB/s 6.1213 MiB/s 6.1488 MiB/s]
                 change:
                        time:   [−5.8376% −4.9477% −4.0335%] (p = 0.00 < 0.05)
                        thrpt:  [+4.2030% +5.2052% +6.1996%]
                        Performance has improved.
```
</details>
2025-07-25 23:44:34 +02:00
dependabot[bot]
f0a1fa467d build(deps): update criterion requirement from 0.6 to 0.7
Updates the requirements on [criterion](https://github.com/bheisler/criterion.rs) to permit the latest version.
- [Changelog](https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bheisler/criterion.rs/compare/0.6.0...0.7.0)

---
updated-dependencies:
- dependency-name: criterion
  dependency-version: 0.7.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-25 23:36:35 +02:00
Guillaume Gomez
37ded317f1
Merge pull request #540 from Kijewski/pr-uninline-expr-call
derive: un-inline `Expr::Call` handling for `{{ expressions }}` and remove parentheses
2025-07-24 18:13:16 +02:00
René Kijewski
bbf9d1c234 derive: remove parentheses before handling {{ (expr) }} 2025-07-24 16:53:51 +02:00
René Kijewski
bbb2932da2 derive: un-inline Expr::Call handling for {{ expressions }}
This is by far the biggest part of the function.
2025-07-24 16:27:55 +02:00
René Kijewski
22092ecb15 parser: un-inline more error messages
Tiny follow up to [#501].

[#501]: <https://redirect.github.com/askama-rs/askama/pull/501>
2025-07-23 18:23:59 +02:00
Guillaume Gomez
8dcc794a9e
Merge pull request #538 from Kijewski/pr-always-false
derive: make `EvaluatedResult` know its unknown result
2025-07-23 15:10:53 +02:00
René Kijewski
78c0ab97bf derive: make EvaluatedResult know its unknown result
This PR adds a `WithSpan<Expr>` member to `EvaluatedResult::Unknown`,
so `Generator::evaluate_condition()` does not have to return a tuple.
2025-07-23 14:45:43 +02:00
Guillaume Gomez
6ac150e096
Merge pull request #533 from seijikun/mr-callexpr-named
Implement #531: Allow named arguments in call expr macro invocations
2025-07-22 13:17:04 +02:00