Add a special case to new_breadcrumbs for when theres an injected context but no explicit context or new context element and finish the partial integration.

This commit is contained in:
Tom Alexander 2020-05-25 16:30:15 -04:00
parent 4ce0899279
commit d02c98cb94
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -298,14 +298,17 @@ impl<'a> DustRenderer<'a> {
return Ok(rendered_content); return Ok(rendered_content);
} else { } else {
let injected_context = ParametersContext::new(breadcrumbs, &partial.params); let injected_context = ParametersContext::new(breadcrumbs, &partial.params);
// TODO: need to add a special case where the let new_breadcrumbs = Self::new_breadcrumbs(
// injected context is added 1 behind the existing breadcrumbs,
// breadcrumbs when new_context_element does not Some(&injected_context),
// exist. &partial.explicit_context,
let mut new_breadcrumbs = breadcrumbs.clone(); None,
new_breadcrumbs.insert(new_breadcrumbs.len() - 1, &injected_context); );
let rendered_content = let rendered_content = self.render_template(
self.render_template(&partial_name, &new_breadcrumbs, Some(blocks))?; &partial_name,
new_breadcrumbs.as_ref().unwrap_or(breadcrumbs),
Some(blocks),
)?;
return Ok(rendered_content); return Ok(rendered_content);
} }
} }
@ -657,7 +660,18 @@ impl<'a> DustRenderer<'a> {
Some(_) => Vec::with_capacity(3), Some(_) => Vec::with_capacity(3),
None => breadcrumbs.clone(), None => breadcrumbs.clone(),
}; };
injected_context.map(|ctx| new_stack.push(ctx)); injected_context.map(|ctx| {
// Special case: when there is no explicit context or new
// context element, the injected context gets inserted 1
// spot behind the current context. Otherwise, the
// injected context gets added after the current context
// but before the explicit context and new context
// element.
match (explicit_context, new_context_element) {
(None, None) => new_stack.insert(std::cmp::max(new_stack.len() - 1, 0), ctx),
_ => new_stack.push(ctx),
}
});
explicit_context.as_ref().map(|path| { explicit_context.as_ref().map(|path| {
walk_path(breadcrumbs, &path.keys).map(|val| { walk_path(breadcrumbs, &path.keys).map(|val| {
if val.is_truthy() { if val.is_truthy() {