Skip to content

Commit

Permalink
Inline script and style tags macros, closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
imbolc committed Oct 31, 2024
1 parent b9df531 commit 6532136
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"<script>console.log("Hello,"); console.log("world!");</script>"#
/// );
/// ```
#[macro_export]
macro_rules! script {
($($t:tt)*) => {
vy::PreEscaped(concat!("<script>", stringify!($($t)*), "</script>"))
};
}

/// Inline style tag
///
/// # Usage
///
/// ```
/// let page = vy::render! {
/// {vy::style!(
/// .red { color: red }
/// .green { color: green }
/// )}
/// };
/// assert_eq!(
/// page,
/// "<style>.red { color: red }.green { color: green }</style>"
/// );
/// ```
#[macro_export]
macro_rules! style {
($($t:tt)*) => {
vy::PreEscaped(concat!("<style>", stringify!($($t)*), "</style>"))
};
}

#[cfg(test)]
mod tests {
#[test]
Expand Down

0 comments on commit 6532136

Please sign in to comment.