464 Commits

Author SHA1 Message Date
René Kijewski
532e343c40 parser: reject illegal string literals 2025-06-09 19:24:08 +02:00
René Kijewski
66ce299a4a parser: in macro calls reject cstrings with NULs 2025-06-09 19:24:07 +02:00
Michael Pollind
df54534ae6 bugfix: resolve with macro with call after caller
https://github.com/askama-rs/askama/issues/467

Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-06-01 21:05:06 +02:00
Guillaume Gomez
741ff53a88 Add regression tests for mutable variables 2025-06-01 16:26:57 +02:00
Guillaume Gomez
9ee2afecfa Add support for mutable variables 2025-06-01 16:26:57 +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
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
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
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
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
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
René Kijewski
1066c884f3 book: add enum documentation 2025-01-26 02:23:51 +01:00
René Kijewski
5944ab9bef Implement enum variants 2025-01-26 02:23:51 +01:00
René Kijewski
94288391b3 derive: add ".askama" to list of HTML extensions 2025-01-25 20:00:30 +01:00