|
|
|
@ -14,7 +14,7 @@ use crate::renderer::errors::WalkError;
|
|
|
|
|
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_combined;
|
|
|
|
|
use crate::renderer::walking::walk_path;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
@ -146,7 +146,7 @@ impl<'a> DustRenderer<'a> {
|
|
|
|
|
}
|
|
|
|
|
DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()),
|
|
|
|
|
DustTag::DTReference(reference) => {
|
|
|
|
|
let val = walk_path_combined(breadcrumbs, &reference.path.keys);
|
|
|
|
|
let val = walk_path(breadcrumbs, &reference.path.keys);
|
|
|
|
|
match val {
|
|
|
|
|
Err(WalkError::CantWalk) => return Ok("".to_owned()),
|
|
|
|
|
Ok(final_val) => {
|
|
|
|
@ -160,7 +160,7 @@ impl<'a> DustRenderer<'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DustTag::DTSection(container) => {
|
|
|
|
|
let val = walk_path_combined(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
|
|
|
|
@ -187,7 +187,7 @@ impl<'a> DustRenderer<'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DustTag::DTExists(container) => {
|
|
|
|
|
let val = walk_path_combined(breadcrumbs, &container.path.keys);
|
|
|
|
|
let val = walk_path(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 +196,7 @@ impl<'a> DustRenderer<'a> {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
DustTag::DTNotExists(container) => {
|
|
|
|
|
let val = walk_path_combined(breadcrumbs, &container.path.keys);
|
|
|
|
|
let val = walk_path(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)
|
|
|
|
@ -497,7 +497,7 @@ impl<'a> DustRenderer<'a> {
|
|
|
|
|
None => None,
|
|
|
|
|
Some(rval) => match rval {
|
|
|
|
|
RValue::RVLiteral(literal) => Some(Ok(literal)),
|
|
|
|
|
RValue::RVPath(path) => Some(walk_path_combined(breadcrumbs, &path.keys)),
|
|
|
|
|
RValue::RVPath(path) => Some(walk_path(breadcrumbs, &path.keys)),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -682,14 +682,14 @@ mod tests {
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
walk_path_combined(&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!(
|
|
|
|
|
walk_path_combined(
|
|
|
|
|
walk_path(
|
|
|
|
|
&vec![&number_context as &dyn ContextElement],
|
|
|
|
|
&vec!["tiger"]
|
|
|
|
|
)
|
|
|
|
@ -699,7 +699,7 @@ mod tests {
|
|
|
|
|
"3".to_owned()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
walk_path_combined(
|
|
|
|
|
walk_path(
|
|
|
|
|
&vec![&deep_context as &dyn ContextElement],
|
|
|
|
|
&vec!["tiger", "food"]
|
|
|
|
|
)
|
|
|
|
|