From 62cd73f9c9c38d9999db0416dd4fcb92b66cc10e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 16 May 2020 18:28:23 -0400 Subject: [PATCH] Initial attempt at implementation, tests not working. --- .../{_helpers_gte => helpers_gte}/input1.json | 0 .../{_helpers_gte => helpers_gte}/main.dust | 0 src/renderer/renderer.rs | 50 ++++++++++++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) rename js/test_cases/{_helpers_gte => helpers_gte}/input1.json (100%) rename js/test_cases/{_helpers_gte => helpers_gte}/main.dust (100%) diff --git a/js/test_cases/_helpers_gte/input1.json b/js/test_cases/helpers_gte/input1.json similarity index 100% rename from js/test_cases/_helpers_gte/input1.json rename to js/test_cases/helpers_gte/input1.json diff --git a/js/test_cases/_helpers_gte/main.dust b/js/test_cases/helpers_gte/main.dust similarity index 100% rename from js/test_cases/_helpers_gte/main.dust rename to js/test_cases/helpers_gte/main.dust diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index dc190dc..d7c1df6 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -299,13 +299,13 @@ impl<'a> DustRenderer<'a> { Self::get_rval(breadcrumbs, ¶m_map, "value") .unwrap_or(Err(WalkError::CantWalk)); match (left_side, right_side) { - (Err(_), _) | (_, Err(_)) => match ¶meterized_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( + ¶meterized_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(¶meterized_block.params); + let left_side: Result<&dyn ContextElement, WalkError> = + match Self::get_rval(breadcrumbs, ¶m_map, "key") { + None => return Ok("".to_owned()), + Some(res) => res, + }; + let right_side: Result<&dyn ContextElement, WalkError> = + Self::get_rval(breadcrumbs, ¶m_map, "value") + .unwrap_or(Err(WalkError::CantWalk)); + match (left_side, right_side) { + (Err(_), _) | (_, Err(_)) => { + return self.render_maybe_body( + ¶meterized_block.contents, + breadcrumbs, + blocks, + ) + } + (Ok(left_side_unwrapped), Ok(right_side_unwrapped)) => { + if left_side_unwrapped >= right_side_unwrapped { + return self.render_maybe_body( + ¶meterized_block.contents, + breadcrumbs, + blocks, + ); + } else { + return self.render_maybe_body( + ¶meterized_block.else_contents, + breadcrumbs, + blocks, + ); + } + } + } + } _ => (), // TODO: Implement the rest } Ok("".to_owned())