From 6532136e02fbd854532bcf3aa070c6d142b6d5b8 Mon Sep 17 00:00:00 2001 From: imbolc Date: Thu, 31 Oct 2024 11:21:45 +0600 Subject: [PATCH] Inline script and style tags macros, closes #3 --- src/lib.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index fd48d52..3047ec0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,51 @@ macro_rules! render { }; } +/// Inline script tag +/// +/// # Usage +/// ``` +/// let page = vy::render! { +/// {vy::script!( +/// console.log("Hello,"); +/// console.log("world!"); +/// )} +/// }; +/// assert_eq!( +/// page, +/// r#""# +/// ); +/// ``` +#[macro_export] +macro_rules! script { + ($($t:tt)*) => { + vy::PreEscaped(concat!("")) + }; +} + +/// Inline style tag +/// +/// # Usage +/// +/// ``` +/// let page = vy::render! { +/// {vy::style!( +/// .red { color: red } +/// .green { color: green } +/// )} +/// }; +/// assert_eq!( +/// page, +/// "" +/// ); +/// ``` +#[macro_export] +macro_rules! style { + ($($t:tt)*) => { + vy::PreEscaped(concat!("")) + }; +} + #[cfg(test)] mod tests { #[test]