From 4e7425d2ffa2e56b4c0b3c975f2c89fb364bd0a1 Mon Sep 17 00:00:00 2001 From: imbolc Date: Thu, 31 Oct 2024 11:58:28 +0600 Subject: [PATCH 1/2] Macros --- maud/src/lib.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 7647379c..4fd47941 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -462,3 +462,48 @@ pub mod macro_private { } } } + +/// Inline script tag +/// +/// # Usage +/// ``` +/// let page = maud::html! { +/// (maud::script!{ +/// console.log("Hello,"); +/// console.log("world!"); +/// }) +/// }; +/// assert_eq!( +/// page.into_string(), +/// r#""# +/// ); +/// ``` +#[macro_export] +macro_rules! script { + ($($t:tt)*) => { + $crate::PreEscaped(concat!("")) + }; +} + +/// Inline style tag +/// +/// # Usage +/// +/// ``` +/// let page = maud::html! { +/// (maud::style!{ +/// .red { color: red } +/// .green { color: green } +/// }) +/// }; +/// assert_eq!( +/// page.into_string(), +/// "" +/// ); +/// ``` +#[macro_export] +macro_rules! style { + ($($t:tt)*) => { + $crate::PreEscaped(concat!("")) + }; +} From 0145d2e4754df7f3d87b0cc1a77bf324fc9fe35f Mon Sep 17 00:00:00 2001 From: imbolc Date: Thu, 31 Oct 2024 12:07:31 +0600 Subject: [PATCH 2/2] Changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6458fe8..2de3d7a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change Log ## [Unreleased] +- Add `script!` and `style!` inline tag helpers + [#448](https://github.com/lambda-fairy/maud/pull/448) ## [0.26.0] - 2024-01-15