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!(
"{}",
dust_renderer
.new_render(main_template_name, &breadcrumbs)
.render(main_template_name, &breadcrumbs)
.expect("Failed to render")
);
}

View File

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