use std::future::Future;
use serde_json::{Map, Value};
pub trait GenerationHooks: Send + Sync {
type Error: From<std::io::Error> + Send;
fn rename(
&self,
_paths: &[String],
) -> impl Future<Output = Result<Option<Vec<String>>, Self::Error>> + Send {
async { Ok(None) }
}
fn has_css_context(&self) -> bool {
false
}
fn has_html_context(&self) -> bool {
false
}
fn css_context(
&self,
context: Map<String, Value>,
) -> impl Future<Output = Result<Map<String, Value>, Self::Error>> + Send {
async { Ok(context) }
}
fn html_context(
&self,
context: Map<String, Value>,
) -> impl Future<Output = Result<Map<String, Value>, Self::Error>> + Send {
async { Ok(context) }
}
}
impl GenerationHooks for () {
type Error = std::io::Error;
}
pub(crate) struct RenameHooks<'a>(pub Option<&'a (dyn Fn(&str) -> String + Send + Sync)>);
impl GenerationHooks for RenameHooks<'_> {
type Error = std::io::Error;
async fn rename(&self, paths: &[String]) -> std::io::Result<Option<Vec<String>>> {
Ok(self
.0
.map(|rename| paths.iter().map(|path| rename(path)).collect()))
}
}