All but explicit context for new_breadcrumbs_section.

master
Tom Alexander 4 years ago
parent b381789422
commit de5914417e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -44,6 +44,15 @@ impl<'a> DustRenderer<'a> {
.insert(template.name.clone(), &template.template);
}
/// Returns a option of a tuple of (parent, new_node_elements)
/// which can then be formed into new BreadcrumbTreeNodes
///
/// If None is returned, then it is a signal to simply re-use the
/// existing breadcrumbs.
///
/// Otherwise, the parent (which may be None, especially for
/// explicit contexts) and the additional node elements (which may
/// be empty) should be combined into a final BreadcrumbTreeNode
fn new_breadcrumbs_section<'b>(
&self,
maybe_breadcrumbs: Option<&'a BreadcrumbTreeNode>,
@ -51,15 +60,20 @@ impl<'a> DustRenderer<'a> {
injected_context: Option<&'b dyn IntoContextElement>,
explicit_context: &Option<Path<'b>>,
new_context_element: Option<&'b dyn ContextElement>,
) -> Option<&'a BreadcrumbTreeNode> {
// If there is no new content, return the original breadcrumbs
) -> Option<(
Option<&'b BreadcrumbTreeNode>,
Vec<BreadcrumbTreeNodeElement<'b>>,
)> {
// If none of the additional contexts are present, return None
// to signal that the original breadcrumbs should be used
// rather than incurring a copy here.
match (
index_context,
injected_context,
explicit_context,
new_context_element,
) {
(None, None, None, None) => return maybe_breadcrumbs,
(None, None, None, None) => return None,
_ => (),
}
@ -69,17 +83,18 @@ impl<'a> DustRenderer<'a> {
Some(_) => None,
None => maybe_breadcrumbs,
};
let mut new_stack = None;
let mut new_nodes = Vec::new();
// TODO: Explicit context
injected_context.map(|ctx| {
new_stack = Some(BreadcrumbTreeNode::new(
parent.map(|b| b as _),
BreadcrumbTreeNodeElement::Borrowed(ctx),
injected_context.map(|ctx| new_nodes.push(BreadcrumbTreeNodeElement::Borrowed(ctx)));
new_context_element.map(|ctx| {
new_nodes.push(BreadcrumbTreeNodeElement::Borrowed(
ctx.from_context_element(),
))
});
index_context.map(|ctx| new_nodes.push(BreadcrumbTreeNodeElement::Borrowed(ctx)));
None
Some((parent, new_nodes))
}
}

Loading…
Cancel
Save