use std::path::{Path, PathBuf};
use crate::Frontmatter;
#[derive(Debug, Clone)]
pub struct Context {
file_tree: Vec<PathBuf>,
pub destination: PathBuf,
pub frontmatter: Frontmatter,
}
impl Context {
#[inline]
#[must_use]
pub fn new(src: PathBuf, dest: PathBuf) -> Self {
Self {
file_tree: vec![src],
destination: dest,
frontmatter: Frontmatter::new(),
}
}
#[inline]
#[must_use]
pub fn from_parent(context: &Self, child: &Path) -> Self {
let mut context = context.clone();
context.file_tree.push(child.to_path_buf());
context
}
#[inline]
#[must_use]
pub fn current_file(&self) -> &PathBuf {
self.file_tree
.last()
.expect("Context not initialized properly, file_tree is empty")
}
#[inline]
#[must_use]
pub fn root_file(&self) -> &PathBuf {
self.file_tree
.first()
.expect("Context not initialized properly, file_tree is empty")
}
#[inline]
#[must_use]
pub fn note_depth(&self) -> usize {
self.file_tree.len()
}
#[inline]
#[must_use]
pub fn file_tree(&self) -> Vec<PathBuf> {
self.file_tree.clone()
}
}