use thiserror::Error;
use crate::{Blueprint, error::HauchiwaError, graph::Handle, loader::GlobAssetsTask};
#[derive(Debug, Error)]
pub enum StyleError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Sass compilation error: {0}")]
Sass(#[from] Box<grass::Error>),
#[error("Build error: {0}")]
Build(#[from] crate::error::BuildError),
}
#[derive(Debug, Clone)]
pub struct Stylesheet {
pub path: camino::Utf8PathBuf,
}
impl<G> Blueprint<G>
where
G: Send + Sync + 'static,
{
pub fn load_css(
&mut self,
glob_entry: &'static str,
glob_watch: &'static str,
) -> Result<Handle<super::Assets<Stylesheet>>, HauchiwaError> {
Ok(self.add_task_opaque(GlobAssetsTask::new(
vec![glob_entry],
vec![glob_watch],
move |_, store, input| {
let data = grass::from_path(&input.path, &grass::Options::default())
.map_err(StyleError::Sass)?;
let path = store
.save(data.as_bytes(), "css")
.map_err(StyleError::Build)?;
Ok((input.path, Stylesheet { path }))
},
)?))
}
}