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
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 22 additions and 6 deletions

View File

@ -41,7 +41,7 @@ fn main() {
println!(
"{}",
dust_renderer
.render(main_template_name, context)
.render(main_template_name, &context)
.expect("Failed to render")
);
}

View File

@ -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;

View File

@ -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<Filter>,
}

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())
}
}