mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-01 06:51:15 +00:00
Allow using "with" keyword in "let" statements
Askama uses the syntax `{% when Variant with (parameters) %}` in `{% match %}` blocks. This change allows the optional use of the keyword "with" in "let" and "if let" statements, too.
This commit is contained in:
parent
136e55c8cf
commit
9e7fe8f2f9
@ -442,6 +442,7 @@ fn target(i: &[u8]) -> IResult<&[u8], Target<'_>> {
|
|||||||
// match structs
|
// match structs
|
||||||
let (i, path) = opt(path)(i)?;
|
let (i, path) = opt(path)(i)?;
|
||||||
if let Some(path) = path {
|
if let Some(path) = path {
|
||||||
|
let (i, _) = opt(ws(tag("with")))(i)?;
|
||||||
let (i, is_unnamed_struct) = opt_opening_paren(i)?;
|
let (i, is_unnamed_struct) = opt_opening_paren(i)?;
|
||||||
if is_unnamed_struct {
|
if is_unnamed_struct {
|
||||||
let (i, targets) = alt((
|
let (i, targets) = alt((
|
||||||
|
@ -105,3 +105,17 @@ fn test_let_destruct_with_path() {
|
|||||||
};
|
};
|
||||||
assert_eq!(t.render().unwrap(), "hello");
|
assert_eq!(t.render().unwrap(), "hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(source = "{% let some::path::Struct with (v) = v %}{{v}}", ext = "txt")]
|
||||||
|
struct LetDestructoringWithPathAndWithKeyword<'a> {
|
||||||
|
v: some::path::Struct<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_let_destruct_with_path_and_with_keyword() {
|
||||||
|
let t = LetDestructoringWithPathAndWithKeyword {
|
||||||
|
v: some::path::Struct("hello"),
|
||||||
|
};
|
||||||
|
assert_eq!(t.render().unwrap(), "hello");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user