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!( println!(
"{}", "{}",
dust_renderer dust_renderer
.render(main_template_name, context) .render(main_template_name, &context)
.expect("Failed to render") .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::NodeError;
pub use node_invoker::Result; pub use node_invoker::Result;
pub use parser::template; pub use parser::template;
pub use parser::DustTag;
pub use parser::Template; pub use parser::Template;
pub use parser::TemplateElement; pub use parser::TemplateElement;

View File

@ -52,7 +52,7 @@ enum Special {
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
struct Comment<'a> { pub struct Comment<'a> {
value: &'a str, value: &'a str,
} }
@ -62,7 +62,7 @@ struct Path<'a> {
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
struct Reference<'a> { pub struct Reference<'a> {
path: Path<'a>, path: Path<'a>,
filters: Vec<Filter>, filters: Vec<Filter>,
} }

View File

@ -1,4 +1,5 @@
use crate::parser::template; use crate::parser::template;
use crate::parser::DustTag;
use crate::parser::Template; use crate::parser::Template;
use crate::parser::TemplateElement; use crate::parser::TemplateElement;
use crate::renderer::errors::CompileError; 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> pub fn render<C>(&self, name: &str, context: C) -> Result<String, RenderError>
where where
C: Index<&'a str>, C: Copy,
{ {
let main_template = match self.templates.get(name) { let main_template = match self.templates.get(name) {
Some(tmpl) => tmpl, Some(tmpl) => tmpl,
@ -59,15 +60,29 @@ impl<'a> DustRenderer<'a> {
fn render_template<C>(&self, template: &Template, context: C) -> Result<String, RenderError> fn render_template<C>(&self, template: &Template, context: C) -> Result<String, RenderError>
where where
C: Index<&'a str>, C: Copy,
{ {
let mut output = String::new(); let mut output = String::new();
for elem in &template.contents.elements { for elem in &template.contents.elements {
match elem { match elem {
TemplateElement::TESpan(span) => output.push_str(span.contents), TemplateElement::TESpan(span) => output.push_str(span.contents),
TemplateElement::TETag(dt) => (), TemplateElement::TETag(dt) => {
output.push_str(&self.render_tag(dt, context)?);
}
} }
} }
Ok(output) 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())
}
} }