Switched to returning an Option for into_context_element().
This commit is contained in:
parent
3aaf7f9987
commit
b74dc394a8
@ -105,7 +105,7 @@ pub trait IntoContextElement: Debug + Walkable /* + CloneIntoBoxedContextElement
|
||||
&self,
|
||||
renderer: &DustRenderer,
|
||||
breadcrumbs: Option<&BreadcrumbTree>,
|
||||
) -> &dyn ContextElement;
|
||||
) -> Option<&dyn ContextElement>;
|
||||
}
|
||||
|
||||
impl<C: ContextElement> IntoContextElement for C {
|
||||
@ -113,7 +113,7 @@ impl<C: ContextElement> IntoContextElement for C {
|
||||
&self,
|
||||
renderer: &DustRenderer,
|
||||
breadcrumbs: Option<&BreadcrumbTree>,
|
||||
) -> &dyn ContextElement {
|
||||
self
|
||||
) -> Option<&dyn ContextElement> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ impl<'a> IntoContextElement for RValue<'a> {
|
||||
&self,
|
||||
renderer: &DustRenderer,
|
||||
breadcrumbs: Option<&BreadcrumbTree>,
|
||||
) -> &dyn ContextElement {
|
||||
) -> Option<&dyn ContextElement> {
|
||||
match self {
|
||||
RValue::RVLiteral(owned_literal) => owned_literal,
|
||||
RValue::RVLiteral(owned_literal) => Some(owned_literal),
|
||||
RValue::RVPath(path) => todo!(),
|
||||
RValue::RVTemplate(template) => todo!(),
|
||||
}
|
||||
|
@ -151,8 +151,8 @@ impl<'a> DustRenderer<'a> {
|
||||
let val = walk_path(breadcrumbs, &reference.path.keys)
|
||||
.map(|ice| ice.into_context_element(self, breadcrumbs));
|
||||
match val {
|
||||
Err(WalkError::CantWalk) => return Ok("".to_owned()),
|
||||
Ok(final_val) => {
|
||||
Err(WalkError::CantWalk) | Ok(None) => return Ok("".to_owned()),
|
||||
Ok(Some(final_val)) => {
|
||||
return if final_val.is_truthy() {
|
||||
final_val.render(&Self::preprocess_filters(&reference.filters))
|
||||
} else {
|
||||
@ -218,8 +218,10 @@ impl<'a> DustRenderer<'a> {
|
||||
let mut new_nodes: Vec<BreadcrumbTreeElement> = Vec::new();
|
||||
|
||||
explicit_context.as_ref().map(|path| {
|
||||
let x = walk_path(maybe_breadcrumbs, &path.keys);
|
||||
x.map(|ice| ice.into_context_element(self, maybe_breadcrumbs))
|
||||
walk_path(maybe_breadcrumbs, &path.keys)
|
||||
.map(|ice| ice.into_context_element(self, maybe_breadcrumbs))
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|val| {
|
||||
if val.is_truthy() {
|
||||
new_nodes.push(BreadcrumbTreeElement::Borrowed(val.from_context_element()))
|
||||
@ -283,11 +285,13 @@ impl<'a> DustRenderer<'a> {
|
||||
}
|
||||
});
|
||||
explicit_context.as_ref().map(|path| {
|
||||
let x = walk_path(maybe_breadcrumbs, &path.keys);
|
||||
// TODO: should resolving the value here use
|
||||
// explicit_context_maybe_breadcrumbs or
|
||||
// maybe_breadcrumbs?
|
||||
x.map(|ice| ice.into_context_element(self, maybe_breadcrumbs))
|
||||
walk_path(maybe_breadcrumbs, &path.keys)
|
||||
.map(|ice| ice.into_context_element(self, maybe_breadcrumbs))
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|val| {
|
||||
if val.is_truthy() {
|
||||
new_nodes.push(BreadcrumbTreeElement::Borrowed(val.from_context_element()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user