Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
45 changes: 45 additions & 0 deletions maud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"<script>console.log("Hello,"); console.log("world!");</script>"#
/// );
/// ```
#[macro_export]
macro_rules! script {
($($t:tt)*) => {
$crate::PreEscaped(concat!("<script>", stringify!($($t)*), "</script>"))
};
}

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