Math helper nearly done, test almost passes.
This commit is contained in:
parent
28a4fea96f
commit
d9f10290f5
@ -68,6 +68,16 @@ impl<'a> ParametersContext<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_values(
|
||||||
|
parent: Option<&'a ParametersContext<'a>>,
|
||||||
|
params: HashMap<&'a str, Option<BreadcrumbTreeElement<'a>>>,
|
||||||
|
) -> Self {
|
||||||
|
ParametersContext {
|
||||||
|
parent: parent,
|
||||||
|
params: params,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn contains_key(&self, segment: &str) -> bool {
|
pub fn contains_key(&self, segment: &str) -> bool {
|
||||||
self.params.contains_key(segment)
|
self.params.contains_key(segment)
|
||||||
|| self
|
|| self
|
||||||
|
@ -665,15 +665,54 @@ impl<'a> DustRenderer<'a> {
|
|||||||
})
|
})
|
||||||
.unwrap_or(Ok("".to_owned()));
|
.unwrap_or(Ok("".to_owned()));
|
||||||
}
|
}
|
||||||
Some(_) => {
|
Some(body) => {
|
||||||
// TODO: math with body, calculate the value and use it like a select block
|
|
||||||
// Calculate the value
|
// Calculate the value
|
||||||
let calculated_value = self.perform_math_operation(breadcrumbs, ¶m_map);
|
let calculated_value =
|
||||||
// Generate a ParametersContext with the result of the math operation as key
|
match self.perform_math_operation(breadcrumbs, ¶m_map) {
|
||||||
|
None => return Ok("".to_owned()),
|
||||||
|
Some(val) => val,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generate a ParametersContext with the result of the math operation as key
|
||||||
|
let converted_value: BreadcrumbTreeElement<'_> = calculated_value.into();
|
||||||
|
let calculated_param_map: HashMap<&str, Option<BreadcrumbTreeElement<'_>>> =
|
||||||
|
vec![("key", Some(converted_value))].into_iter().collect();
|
||||||
|
let calculated_context =
|
||||||
|
ParametersContext::from_values(None, calculated_param_map);
|
||||||
// calculate are_any_checks_true
|
// calculate are_any_checks_true
|
||||||
|
let are_any_checks_true = body
|
||||||
|
.elements
|
||||||
|
.iter()
|
||||||
|
.filter_map(|te| match te {
|
||||||
|
TemplateElement::TETag(dt) => match dt {
|
||||||
|
DustTag::DTHelperEquals(_)
|
||||||
|
| DustTag::DTHelperNotEquals(_)
|
||||||
|
| DustTag::DTHelperGreaterThan(_)
|
||||||
|
| DustTag::DTHelperLessThan(_)
|
||||||
|
| DustTag::DTHelperGreaterThanOrEquals(_)
|
||||||
|
| DustTag::DTHelperLessThanOrEquals(_) => Some(dt),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.map(|dt| {
|
||||||
|
self.perform_comparison_check(
|
||||||
|
dt,
|
||||||
|
new_breadcrumbs_ref,
|
||||||
|
Some(&calculated_context),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.any(|check_result| check_result.unwrap_or(false));
|
||||||
// Generate a SelectContext
|
// Generate a SelectContext
|
||||||
|
let select_context =
|
||||||
|
SelectContext::new(&calculated_context, are_any_checks_true);
|
||||||
// render_maybe_body
|
// render_maybe_body
|
||||||
|
return self.render_maybe_body(
|
||||||
|
¶meterized_block.contents,
|
||||||
|
new_breadcrumbs_ref,
|
||||||
|
blocks,
|
||||||
|
&mut Some(select_context),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user