Initial structure for the perform_math_operation function.
This commit is contained in:
@@ -644,7 +644,32 @@ impl<'a> DustRenderer<'a> {
|
||||
}
|
||||
_ => return Ok("".to_owned()),
|
||||
},
|
||||
DustTag::DTHelperMath(parameterized_block) => {}
|
||||
DustTag::DTHelperMath(parameterized_block) => {
|
||||
let new_breadcrumbs = self.new_breadcrumbs_partial(
|
||||
breadcrumbs,
|
||||
breadcrumbs,
|
||||
None,
|
||||
¶meterized_block.explicit_context,
|
||||
);
|
||||
let new_breadcrumbs_ref = new_breadcrumbs.as_ref().unwrap_or(breadcrumbs);
|
||||
let param_map =
|
||||
ParametersContext::new(self, breadcrumbs, ¶meterized_block.params, None);
|
||||
match ¶meterized_block.contents {
|
||||
None => {
|
||||
// TODO: math without body, calculate the value and render it
|
||||
// Calculate the value
|
||||
// Render
|
||||
}
|
||||
Some(_) => {
|
||||
// TODO: math with body, calculate the value and use it like a select block
|
||||
// Calculate the value
|
||||
// Generate a ParametersContext with the result of the math operation as key
|
||||
// calculate are_any_checks_true
|
||||
// Generate a SelectContext
|
||||
// render_maybe_body
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok("".to_owned())
|
||||
@@ -902,6 +927,52 @@ impl<'a> DustRenderer<'a> {
|
||||
_ => panic!("perform_comparison_check only implemented for comparison helpers (eq, ne, gt, gte, lt, lte)")
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs a math operation (add, subtract, multiply, divide,
|
||||
/// mod, abs, floor, ceil) and returns the result or None if
|
||||
/// nothing should be rendered.
|
||||
fn performance_math_operation(
|
||||
&'a self,
|
||||
breadcrumbs: &'a Vec<BreadcrumbTreeElement<'a>>,
|
||||
math_parameters: &'a ParametersContext<'a>,
|
||||
) -> Option<IceResult<'a>> {
|
||||
let method = match self.tap(breadcrumbs, math_parameters, "method") {
|
||||
None | Some(Err(_)) => return None,
|
||||
Some(Ok(ice_result)) => ice_result,
|
||||
};
|
||||
let method_rendered = match method.get_context_element_reference().render(&Vec::new()) {
|
||||
Ok(text) => text,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let left_side = self.tap(breadcrumbs, math_parameters, "key");
|
||||
let right_side = self.tap(breadcrumbs, math_parameters, "operand");
|
||||
|
||||
let left_side_ce = left_side.as_ref().map(|maybe_ice| {
|
||||
maybe_ice
|
||||
.as_ref()
|
||||
.map(|ice| ice.get_context_element_reference())
|
||||
});
|
||||
let right_side_ce = right_side.as_ref().map(|maybe_ice| {
|
||||
maybe_ice
|
||||
.as_ref()
|
||||
.map(|ice| ice.get_context_element_reference())
|
||||
});
|
||||
|
||||
match method_rendered.as_str() {
|
||||
"add" => todo!(),
|
||||
"subtract" => todo!(),
|
||||
"multiply" => todo!(),
|
||||
"divide" => todo!(),
|
||||
"mod" => todo!(),
|
||||
"abs" => todo!(),
|
||||
"floor" => todo!(),
|
||||
"ceil" => todo!(),
|
||||
_ => return None,
|
||||
}
|
||||
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct BlockContext<'a> {
|
||||
|
||||
Reference in New Issue
Block a user