Loading the compiled templates into a context
This commit is contained in:
@@ -4,3 +4,4 @@ mod renderer;
|
||||
|
||||
pub use renderer::compile_template;
|
||||
pub use renderer::CompiledTemplate;
|
||||
pub use renderer::DustContext;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::parser::template;
|
||||
use crate::parser::Template;
|
||||
use nom::IResult;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CompiledTemplate<'a> {
|
||||
@@ -8,6 +9,11 @@ pub struct CompiledTemplate<'a> {
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DustContext<'a> {
|
||||
templates: BTreeMap<&'a String, &'a Template<'a>>,
|
||||
}
|
||||
|
||||
pub fn compile_template<'a>(source: &'a str, name: String) -> CompiledTemplate<'a> {
|
||||
// TODO: Make this function return a result with a custom error type. Break the nom IResult chain
|
||||
// TODO: Make this all consuming
|
||||
@@ -17,3 +23,15 @@ pub fn compile_template<'a>(source: &'a str, name: String) -> CompiledTemplate<'
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DustContext<'a> {
|
||||
pub fn new() -> DustContext<'a> {
|
||||
DustContext {
|
||||
templates: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_source(&mut self, template: &'a CompiledTemplate) {
|
||||
self.templates.insert(&template.name, &template.template);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user