#[macro_export]
macro_rules! include_tailwind_raw {
(always) => {
::core::include_str!(env!("INCLUDE_TAILWIND_PATH"))
};
() => {
{
#[cfg(not(debug_assertions))] {
$crate::include_tailwind_raw!(always)
}
#[cfg(debug_assertions)] { "/* this is empty in debug */\n" }
}
};
}
#[macro_export]
macro_rules! include_tailwind {
($($v:tt)*) => { $crate::Stylesheet($crate::include_tailwind_raw!($($v)*)) };
}
#[derive(Debug, Clone, Copy, Hash)]
pub struct Stylesheet(pub &'static str);
impl AsRef<str> for Stylesheet { fn as_ref(&self) -> &str { &self.0 } }
impl Stylesheet {
pub fn as_str(&self) -> &'static str { &self.0 }
}
#[cfg(feature = "axum")]
mod axum_support {
use crate::Stylesheet;
use axum_core::response::{IntoResponse, Response};
use http::{header, HeaderMap, HeaderValue};
impl IntoResponse for Stylesheet {
fn into_response(self) -> Response {
(
HeaderMap::from_iter([
(header::CONTENT_TYPE, HeaderValue::from_static("text/css; charset=utf-8"))
]),
self.0,
).into_response()
}
}
}
#[derive(Debug)]
pub enum LoadTailwind {
Inline {
css: &'static str
},
Loaded {
path: String,
},
Jit {
config: &'static str,
jit_url: &'static str,
},
}
#[cfg(feature = "maud")]
mod maud_support {
use crate::LoadTailwind;
use maud::Render;
impl Render for LoadTailwind {
#[inline]
fn render(&self) -> maud::Markup {
maud::PreEscaped(self.to_string())
}
}
}
impl std::fmt::Display for LoadTailwind {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LoadTailwind::Inline { css } => {
write!(f, "
<!-- included inline by include-tailwind -->
<style>
{css}
</style>")?;
},
LoadTailwind::Loaded { path } => {
write!(f, "<link rel=\"stylesheet\" type=\"text/css\" href=\"{path}\">")?;
},
LoadTailwind::Jit { config, jit_url } => {
write!(f, "
<script src=\"{jit_url}\"></script>
<script>
{config}
</script>")?;
},
}
Ok(())
}
}
#[macro_export]
macro_rules! load_tailwind {
(always) => {
$crate::LoadTailwind::Inline { css: $crate::include_tailwind_raw!(always) }
};
(always, $path:literal) => {
$crate::LoadTailwind::Loaded { path: String::from($path) }
};
(jit) => {
$crate::LoadTailwind::Jit {
config: include_str!(env!("INCLUDE_TAILWIND_JIT_CONFIG_PATH")),
jit_url: env!("INCLUDE_TAILWIND_JIT_URL"),
}
};
() => {
{
#[cfg(debug_assertions)] { $crate::load_tailwind!(jit) }
#[cfg(not(debug_assertions))] { $crate::load_tailwind!(always) }
}
};
($path:expr) => {
{
#[cfg(debug_assertions)] { $crate::load_tailwind!(jit) }
#[cfg(not(debug_assertions))] { $crate::load_tailwind!(always) }
}
};
}