From 63d03f3afb2534d417d063108f00dff110ccf3fb Mon Sep 17 00:00:00 2001 From: Olivier Date: Sat, 4 Mar 2023 10:42:52 +0000 Subject: [PATCH] Allow shorthand when passing params to templates --- demo_hornbeam_project/src/main.rs | 2 +- hornbeam/src/interpreted.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/demo_hornbeam_project/src/main.rs b/demo_hornbeam_project/src/main.rs index 144cc4e..c5160e4 100644 --- a/demo_hornbeam_project/src/main.rs +++ b/demo_hornbeam_project/src/main.rs @@ -40,7 +40,7 @@ async fn main() -> eyre::Result<()> { async fn say_hello(Path((lang, name)): Path<(String, String)>) -> impl IntoResponse { Rendered(render_template_string!(TEMPLATING, say_hello, lang, { - name: name + name })) } diff --git a/hornbeam/src/interpreted.rs b/hornbeam/src/interpreted.rs index 97f2ee7..6aaaa4d 100644 --- a/hornbeam/src/interpreted.rs +++ b/hornbeam/src/interpreted.rs @@ -216,8 +216,15 @@ macro_rules! interpreter_setters { { $params:ident; $k:ident : $v:expr } => { $params = $params.set(stringify!($k), $v); }; + { $params:ident; $k:ident } => { + $params = $params.set(stringify!($k), $k); + }; { $params:ident; $k:ident : $v:expr, $($tail:tt)* } => { $params = $params.set(stringify!($k), $v); interpreter_setters!{ $params; $($tail)* } }; + { $params:ident; $k:ident, $($tail:tt)* } => { + $params = $params.set(stringify!($k), $k); + interpreter_setters!{ $params; $($tail)* } + }; }