Initial attempt at implementation, tests not working.

This commit is contained in:
Tom Alexander 2020-05-16 18:28:23 -04:00
parent 7cde89c601
commit 62cd73f9c9
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 43 additions and 7 deletions

View File

@ -299,13 +299,13 @@ impl<'a> DustRenderer<'a> {
Self::get_rval(breadcrumbs, &param_map, "value")
.unwrap_or(Err(WalkError::CantWalk));
match (left_side, right_side) {
(Err(_), _) | (_, Err(_)) => match &parameterized_block.else_contents {
None => return Ok("".to_owned()),
Some(body) => {
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
return Ok(rendered_content);
}
},
(Err(_), _) | (_, Err(_)) => {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
)
}
(Ok(left_side_unwrapped), Ok(right_side_unwrapped)) => {
if left_side_unwrapped > right_side_unwrapped {
return self.render_maybe_body(
@ -323,6 +323,42 @@ impl<'a> DustRenderer<'a> {
}
}
}
DustTag::DTHelperGreaterThenOrEquals(parameterized_block) => {
let param_map: HashMap<&str, &RValue<'a>> =
Self::get_rval_map(&parameterized_block.params);
let left_side: Result<&dyn ContextElement, WalkError> =
match Self::get_rval(breadcrumbs, &param_map, "key") {
None => return Ok("".to_owned()),
Some(res) => res,
};
let right_side: Result<&dyn ContextElement, WalkError> =
Self::get_rval(breadcrumbs, &param_map, "value")
.unwrap_or(Err(WalkError::CantWalk));
match (left_side, right_side) {
(Err(_), _) | (_, Err(_)) => {
return self.render_maybe_body(
&parameterized_block.contents,
breadcrumbs,
blocks,
)
}
(Ok(left_side_unwrapped), Ok(right_side_unwrapped)) => {
if left_side_unwrapped >= right_side_unwrapped {
return self.render_maybe_body(
&parameterized_block.contents,
breadcrumbs,
blocks,
);
} else {
return self.render_maybe_body(
&parameterized_block.else_contents,
breadcrumbs,
blocks,
);
}
}
}
}
_ => (), // TODO: Implement the rest
}
Ok("".to_owned())