use crate::properties::Properties;
use std::path::{Path, PathBuf};
mod collection;
mod iter;
mod name;
pub use self::{collection::Collection, iter::Iter, name::Name};
const APP_BIN_DIR: &str = "src/bin/app";
pub struct Template<'a> {
name: Name,
inner: &'a handlebars::Template,
}
impl<'a> Template<'a> {
fn new(name: &'a str, template: &'a handlebars::Template) -> Self {
Self {
name: Name::from(name),
inner: template,
}
}
pub fn name(&self) -> &Name {
&self.name
}
}
impl<'a> Template<'a> {
pub fn output_path(&self, properties: &Properties) -> PathBuf {
let path = Path::new(self.name().as_ref());
let stemmed_path = path
.parent()
.expect("no output parent path")
.join(path.file_stem().expect("no file stem"));
if stemmed_path.starts_with(APP_BIN_DIR) {
Path::new(APP_BIN_DIR)
.parent()
.unwrap()
.join(properties.name.as_ref())
.join(stemmed_path.strip_prefix(APP_BIN_DIR).unwrap())
} else {
stemmed_path
}
}
}