use crate::{
block::Block,
parser::{self, template::Template},
};
#[derive(Debug)]
pub struct File {
pub templates: Vec<Template>,
}
impl File {
pub fn parse(content: &str) -> Result<Self, ()> {
parser::parse(content)
.map(|templates| File { templates })
.map_err(|_| ())
}
pub fn template_opt(&self, template_name: &str) -> Option<Block> {
for t in &self.templates {
if t.name == template_name {
return Some(t.into());
}
}
None
}
pub fn template(&self, template_name: &str) -> Block {
self.template_opt(template_name).unwrap()
}
}