use std::sync::Arc;
macro_rules! define_source {
($name:ident) => {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct $name {
content: &'static str,
path: Option<&'static str>,
}
impl $name {
pub const fn new(content: &'static str, path: Option<&'static str>) -> Self {
Self { content, path }
}
pub const fn inline(content: &'static str) -> Self {
Self::new(content, None)
}
pub const fn as_str(&self) -> &'static str {
self.content
}
pub const fn path(&self) -> Option<&str> {
self.path
}
}
};
}
pub type SharedSourceText = Arc<str>;
define_source!(HtmlSource);
define_source!(CssSource);
define_source!(JsSource);
#[doc(hidden)]
#[macro_export]
macro_rules! include_source {
($source:ident, $path:literal $(,)?) => {{
const __HTUI_SOURCE: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $path));
#[cfg(debug_assertions)]
const __HTUI_SOURCE_PATH: Option<&str> =
Some(concat!(env!("CARGO_MANIFEST_DIR"), "/", $path));
#[cfg(not(debug_assertions))]
const __HTUI_SOURCE_PATH: Option<&str> = None;
$crate::$source::new(__HTUI_SOURCE, __HTUI_SOURCE_PATH)
}};
}
#[macro_export]
macro_rules! include_html {
($path:literal $(,)?) => {
$crate::include_source!(HtmlSource, $path)
};
}
#[macro_export]
macro_rules! include_css {
($path:literal $(,)?) => {
$crate::include_source!(CssSource, $path)
};
}
#[macro_export]
macro_rules! include_js {
($path:literal $(,)?) => {
$crate::include_source!(JsSource, $path)
};
}