From cba1fb8e508eae87d213e7bc4c7b2eb8b4b92732 Mon Sep 17 00:00:00 2001 From: mataha Date: Sat, 10 Jun 2023 04:57:56 +0200 Subject: Allow macros to be defined and called without arguments This commit introduces a shorthand for defining and calling macros when using them as a reusable substitute for variables assigned complex values (e.g. string literals with or without newline escapes). The use-case is formatting - from my experience it's easier to visually parse a `macro` `endmacro` block than a multiline variable assignment. Signed-off-by: mataha --- testing/tests/macro.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'testing/tests/macro.rs') diff --git a/testing/tests/macro.rs b/testing/tests/macro.rs index 6b0eca5..7e910a9 100644 --- a/testing/tests/macro.rs +++ b/testing/tests/macro.rs @@ -12,6 +12,16 @@ fn test_macro() { assert_eq!(t.render().unwrap(), "12foo foo foo34foo foo5"); } +#[derive(Template)] +#[template(path = "macro-no-args.html")] +struct MacroNoArgsTemplate; + +#[test] +fn test_macro_no_args() { + let t = MacroNoArgsTemplate; + assert_eq!(t.render().unwrap(), "11the best thing111we've ever done11"); +} + #[derive(Template)] #[template(path = "import.html")] struct ImportTemplate<'a> { -- cgit