Rename the new functions to replace the old functions.

master
Tom Alexander 4 years ago
parent 46fe1f5204
commit 39c579171b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -2,7 +2,7 @@ use crate::parser::KVPair;
use crate::parser::{Filter, OwnedLiteral, RValue};
use crate::renderer::context_element::CompareContextElement;
use crate::renderer::context_element::ContextElement;
use crate::renderer::walking::walk_path_combined;
use crate::renderer::walking::walk_path;
use crate::renderer::Loopable;
use crate::renderer::RenderError;
use crate::renderer::Renderable;
@ -89,7 +89,7 @@ impl Walkable for ParametersContext {
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?;
match rval {
OwnedRValue::RVPath(path) => walk_path_combined(&self.breadcrumbs, &path.keys),
OwnedRValue::RVPath(path) => walk_path(&self.breadcrumbs, &path.keys),
OwnedRValue::RVLiteral(literal) => Ok(literal),
}
}

@ -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"]
)

@ -8,7 +8,7 @@ enum WalkResult<'a> {
FullyWalked(&'a dyn ContextElement),
}
fn walk_path_from_single_level_borrow<'a, P, C>(context: &'a C, path: &[P]) -> WalkResult<'a>
fn walk_path_from_single_level<'a, P, C>(context: &'a C, path: &[P]) -> WalkResult<'a>
where
P: Borrow<str>,
C: Borrow<dyn ContextElement + 'a>,
@ -34,7 +34,7 @@ where
WalkResult::FullyWalked(output)
}
pub fn walk_path_combined<'a, B, P>(
pub fn walk_path<'a, B, P>(
breadcrumbs: &'a Vec<B>,
path: &Vec<P>,
) -> Result<&'a dyn ContextElement, WalkError>
@ -54,7 +54,7 @@ where
.borrow()
== "."
{
return match walk_path_from_single_level_borrow(
return match walk_path_from_single_level(
breadcrumbs
.last()
.expect("Breadcrumbs should never be empty"),
@ -68,7 +68,7 @@ where
};
}
for context in breadcrumbs.iter().rev() {
match walk_path_from_single_level_borrow(context, path) {
match walk_path_from_single_level(context, path) {
// If no walking was done at all, keep looping
WalkResult::NoWalk => {}
// If we partially walked then stop trying to find

Loading…
Cancel
Save