use super::{
super::{render::*, util::*},
coordinate::*,
error::*,
};
use {compris::resolve::*, kutil::cli::depict::*, std::path::*};
#[derive(Clone, Debug, Depict, Resolve)]
pub struct FilesConfiguration {
#[resolve]
#[depict(as(debug), style(string))]
pub assets: PathBuf,
#[resolve]
#[depict(as(debug), style(string))]
pub status: PathBuf,
#[resolve]
#[depict(as(debug), style(string))]
pub templates: PathBuf,
#[resolve]
#[depict(as(depict))]
pub coordinate: CoordinateConfiguration,
}
impl FilesConfiguration {
pub fn set_assets_path<PathT>(&mut self, assets_path: PathT)
where
PathT: AsRef<Path>,
{
if self.assets.as_os_str().is_empty() {
self.assets = assets_path.as_ref().into();
}
}
pub fn validate<PathT>(&mut self, base_path: PathT) -> Result<(), ConfigurationError>
where
PathT: AsRef<Path>,
{
let base_path = base_path.as_ref();
if !self.status.is_absolute() {
self.status = base_path.join(&self.status);
}
if !self.templates.is_absolute() {
self.templates = base_path.join(&self.templates);
}
self.coordinate.validate(base_path, vec![self.templates.clone()])?;
Ok(())
}
pub fn asset(&self, uri_path: &str) -> PathBuf {
self.assets.join(uri_path.trim_start_matches(PATH_SEPARATOR))
}
pub fn templates(&self) -> Templates {
Templates::new(self)
}
}
impl Default for FilesConfiguration {
fn default() -> Self {
Self {
assets: Default::default(),
status: PathBuf::from("status"),
templates: PathBuf::from("templates"),
coordinate: Default::default(),
}
}
}