Rename the new functions to replace the old functions.

This commit is contained in:
Tom Alexander 2020-05-05 20:46:31 -04:00
parent 18f9fb7f57
commit 3cf47fa1a8
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 14 additions and 14 deletions

View File

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

View File

@ -45,7 +45,7 @@ impl<'a> DustRenderer<'a> {
.insert(template.name.clone(), &template.template); .insert(template.name.clone(), &template.template);
} }
pub fn new_render( pub fn render(
&'a self, &'a self,
name: &str, name: &str,
breadcrumbs: &Vec<&'a dyn ContextElement>, breadcrumbs: &Vec<&'a dyn ContextElement>,
@ -59,10 +59,10 @@ impl<'a> DustRenderer<'a> {
))); )));
} }
}; };
self.new_render_body(&main_template.contents, breadcrumbs) self.render_body(&main_template.contents, breadcrumbs)
} }
fn new_render_body( fn render_body(
&'a self, &'a self,
body: &'a Body, body: &'a Body,
breadcrumbs: &Vec<&'a dyn ContextElement>, breadcrumbs: &Vec<&'a dyn ContextElement>,
@ -73,14 +73,14 @@ impl<'a> DustRenderer<'a> {
TemplateElement::TEIgnoredWhitespace(_) => {} TemplateElement::TEIgnoredWhitespace(_) => {}
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.new_render_tag(dt, breadcrumbs)?); output.push_str(&self.render_tag(dt, breadcrumbs)?);
} }
} }
} }
Ok(output) Ok(output)
} }
fn new_render_tag( fn render_tag(
&'a self, &'a self,
tag: &'a DustTag, tag: &'a DustTag,
breadcrumbs: &Vec<&'a dyn ContextElement>, breadcrumbs: &Vec<&'a dyn ContextElement>,
@ -98,7 +98,7 @@ impl<'a> DustRenderer<'a> {
.to_owned()) .to_owned())
} }
DustTag::DTReference(reference) => { DustTag::DTReference(reference) => {
let val = new_walk_path(breadcrumbs, &reference.path.keys); let val = walk_path(breadcrumbs, &reference.path.keys);
if let Err(RenderError::NotFound { .. }) = val { if let Err(RenderError::NotFound { .. }) = val {
// If reference does not exist in the context, it becomes an empty string // If reference does not exist in the context, it becomes an empty string
return Ok("".to_owned()); return Ok("".to_owned());
@ -107,7 +107,7 @@ impl<'a> DustRenderer<'a> {
} }
} }
DustTag::DTSection(container) => { DustTag::DTSection(container) => {
let val = new_walk_path(breadcrumbs, &container.path.keys); let val = walk_path(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = self.get_loop_elements(val)?; let loop_elements: Vec<&dyn ContextElement> = self.get_loop_elements(val)?;
if loop_elements.is_empty() { if loop_elements.is_empty() {
// Oddly enough if the value is falsey (like // Oddly enough if the value is falsey (like
@ -118,7 +118,7 @@ impl<'a> DustRenderer<'a> {
// TODO: do filters apply? I don't think so // TODO: do filters apply? I don't think so
// but I should test // but I should test
return match &container.else_contents { return match &container.else_contents {
Some(body) => self.new_render_body(&body, breadcrumbs), Some(body) => self.render_body(&body, breadcrumbs),
None => Ok("".to_owned()), None => Ok("".to_owned()),
}; };
} else { } else {
@ -130,7 +130,7 @@ impl<'a> DustRenderer<'a> {
.map(|array_elem| { .map(|array_elem| {
let mut new_breadcumbs = breadcrumbs.clone(); let mut new_breadcumbs = breadcrumbs.clone();
new_breadcumbs.push(array_elem); new_breadcumbs.push(array_elem);
self.new_render_body(&body, &new_breadcumbs) self.render_body(&body, &new_breadcumbs)
}) })
.collect(); .collect();
let rendered_slice: &[String] = &rendered_results?; let rendered_slice: &[String] = &rendered_results?;
@ -191,7 +191,7 @@ fn walk_path_from_single_level<'a>(
Ok(WalkResult::FullyWalked(output)) Ok(WalkResult::FullyWalked(output))
} }
fn new_walk_path<'a>( fn walk_path<'a>(
breadcrumbs: &Vec<&'a dyn ContextElement>, breadcrumbs: &Vec<&'a dyn ContextElement>,
path: &'a Vec<&str>, path: &'a Vec<&str>,
) -> Result<&'a dyn ContextElement, RenderError<'a>> { ) -> Result<&'a dyn ContextElement, RenderError<'a>> {
@ -320,14 +320,14 @@ mod tests {
.collect(); .collect();
assert_eq!( assert_eq!(
new_walk_path(&vec![&context as &dyn ContextElement], &vec!["cat"]) walk_path(&vec![&context as &dyn ContextElement], &vec!["cat"])
.unwrap() .unwrap()
.render(&Vec::new()) .render(&Vec::new())
.unwrap(), .unwrap(),
"kitty".to_owned() "kitty".to_owned()
); );
assert_eq!( assert_eq!(
new_walk_path( walk_path(
&vec![&number_context as &dyn ContextElement], &vec![&number_context as &dyn ContextElement],
&vec!["tiger"] &vec!["tiger"]
) )
@ -337,7 +337,7 @@ mod tests {
"3".to_owned() "3".to_owned()
); );
assert_eq!( assert_eq!(
new_walk_path( walk_path(
&vec![&deep_context as &dyn ContextElement], &vec![&deep_context as &dyn ContextElement],
&vec!["tiger", "food"] &vec!["tiger", "food"]
) )