Initial implementation combining owned_walk_path and walk_path. Works everywhere except one spot.

This commit is contained in:
Tom Alexander
2020-05-24 14:56:09 -04:00
parent a58b605e59
commit 4790ac77d6
3 changed files with 85 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ use crate::renderer::inline_partial_tree::extract_inline_partials;
use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
use crate::renderer::parameters_context::ParametersContext;
use crate::renderer::walking::walk_path;
use crate::renderer::walking::walk_path_combined;
use std::collections::HashMap;
#[derive(Clone, Debug)]
@@ -146,7 +147,7 @@ impl<'a> DustRenderer<'a> {
}
DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()),
DustTag::DTReference(reference) => {
let val = walk_path(breadcrumbs, &reference.path.keys);
let val = walk_path_combined(breadcrumbs, &reference.path.keys);
match val {
Err(WalkError::CantWalk) => return Ok("".to_owned()),
Ok(final_val) => {
@@ -160,7 +161,7 @@ impl<'a> DustRenderer<'a> {
}
}
DustTag::DTSection(container) => {
let val = walk_path(breadcrumbs, &container.path.keys);
let val = walk_path_combined(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
@@ -187,7 +188,7 @@ impl<'a> DustRenderer<'a> {
}
}
DustTag::DTExists(container) => {
let val = walk_path(breadcrumbs, &container.path.keys);
let val = walk_path_combined(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val);
return if loop_elements.is_empty() {
self.render_maybe_body(&container.else_contents, breadcrumbs, blocks)
@@ -196,7 +197,7 @@ impl<'a> DustRenderer<'a> {
};
}
DustTag::DTNotExists(container) => {
let val = walk_path(breadcrumbs, &container.path.keys);
let val = walk_path_combined(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val);
return if !loop_elements.is_empty() {
self.render_maybe_body(&container.else_contents, breadcrumbs, blocks)
@@ -682,14 +683,14 @@ mod tests {
.collect();
assert_eq!(
walk_path(&vec![&context as &dyn ContextElement], &vec!["cat"])
walk_path_combined(&vec![&context as &dyn ContextElement], &vec!["cat"])
.unwrap()
.render(&Vec::new())
.unwrap(),
"kitty".to_owned()
);
assert_eq!(
walk_path(
walk_path_combined(
&vec![&number_context as &dyn ContextElement],
&vec!["tiger"]
)
@@ -699,7 +700,7 @@ mod tests {
"3".to_owned()
);
assert_eq!(
walk_path(
walk_path_combined(
&vec![&deep_context as &dyn ContextElement],
&vec!["tiger", "food"]
)