diff --git a/src/bin.rs b/src/bin.rs index fdf9f8b..2be43c0 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -41,7 +41,7 @@ fn main() { println!( "{}", dust_renderer - .render(main_template_name, context) + .render(main_template_name, &context) .expect("Failed to render") ); } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 1bd255e..c9c748b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -7,5 +7,6 @@ pub use node_invoker::run_node_dust; pub use node_invoker::NodeError; pub use node_invoker::Result; pub use parser::template; +pub use parser::DustTag; pub use parser::Template; pub use parser::TemplateElement; diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 50bcec8..3fc7545 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -52,7 +52,7 @@ enum Special { } #[derive(Clone, Debug, PartialEq)] -struct Comment<'a> { +pub struct Comment<'a> { value: &'a str, } @@ -62,7 +62,7 @@ struct Path<'a> { } #[derive(Clone, Debug, PartialEq)] -struct Reference<'a> { +pub struct Reference<'a> { path: Path<'a>, filters: Vec, } diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index a33f2ce..9679727 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -1,4 +1,5 @@ use crate::parser::template; +use crate::parser::DustTag; use crate::parser::Template; use crate::parser::TemplateElement; use crate::renderer::errors::CompileError; @@ -44,7 +45,7 @@ impl<'a> DustRenderer<'a> { pub fn render(&self, name: &str, context: C) -> Result where - C: Index<&'a str>, + C: Copy, { let main_template = match self.templates.get(name) { Some(tmpl) => tmpl, @@ -59,15 +60,29 @@ impl<'a> DustRenderer<'a> { fn render_template(&self, template: &Template, context: C) -> Result where - C: Index<&'a str>, + C: Copy, { let mut output = String::new(); for elem in &template.contents.elements { match elem { TemplateElement::TESpan(span) => output.push_str(span.contents), - TemplateElement::TETag(dt) => (), + TemplateElement::TETag(dt) => { + output.push_str(&self.render_tag(dt, context)?); + } } } Ok(output) } + + fn render_tag(&self, tag: &DustTag, context: C) -> Result + where + C: Copy, + { + match tag { + DustTag::DTComment(comment) => (), + DustTag::DTReference(reference) => (), + _ => (), // TODO: Implement the rest + } + Ok("".to_owned()) + } }