Beginning of the render_tag function.

Beginning of the render_tag function. At this point I need to figure out how to access elements in the context.
This commit is contained in:
Tom Alexander
2020-04-11 18:40:36 -04:00
parent 2459d7b418
commit f65a144b3c
4 changed files with 22 additions and 6 deletions

View File

@@ -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<C>(&self, name: &str, context: C) -> Result<String, RenderError>
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<C>(&self, template: &Template, context: C) -> Result<String, RenderError>
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<C>(&self, tag: &DustTag, context: C) -> Result<String, RenderError>
where
C: Copy,
{
match tag {
DustTag::DTComment(comment) => (),
DustTag::DTReference(reference) => (),
_ => (), // TODO: Implement the rest
}
Ok("".to_owned())
}
}