From 28d76964080f5c6c36d5f6ed72828b679fe352b4 Mon Sep 17 00:00:00 2001 From: bott Date: Sun, 7 Oct 2018 17:13:52 +0200 Subject: Add Rust macro support at templates --- testing/templates/rust-macros.html | 1 + testing/tests/rust_macro.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 testing/templates/rust-macros.html create mode 100644 testing/tests/rust_macro.rs (limited to 'testing') diff --git a/testing/templates/rust-macros.html b/testing/templates/rust-macros.html new file mode 100644 index 0000000..dc0b3de --- /dev/null +++ b/testing/templates/rust-macros.html @@ -0,0 +1 @@ +Hello, {{ hello!(name) }}! diff --git a/testing/tests/rust_macro.rs b/testing/tests/rust_macro.rs new file mode 100644 index 0000000..c6e97ce --- /dev/null +++ b/testing/tests/rust_macro.rs @@ -0,0 +1,22 @@ +#[macro_use] +extern crate askama; + +use askama::Template; + +macro_rules! hello { + ($name:expr) => { + "world" + } +} + +#[derive(Template)] +#[template(path = "rust-macros.html")] +struct RustMacrosTemplate<'a> { + name: &'a str, +} + +#[test] +fn main() { + let template = RustMacrosTemplate { name: "foo" }; + assert_eq!("Hello, world!", template.render().unwrap()); +} -- cgit