Implemented the not equals helper.

This commit is contained in:
Tom Alexander 2020-05-16 12:26:28 -04:00
parent 94cedef3ef
commit f4a935224c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -265,6 +265,47 @@ impl<'a> DustRenderer<'a> {
}
}
}
DustTag::DTHelperNotEquals(parameterized_block) => {
let param_map: HashMap<&str, &RValue<'a>> = parameterized_block
.params
.iter()
.map(|pair: &KVPair<'a>| (pair.key, &pair.value))
.collect();
let left_side: Result<&dyn ContextElement, WalkError> = match param_map.get("key") {
None => return Ok("".to_owned()),
Some(rval) => match rval {
RValue::RVString(text) => Ok(text),
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
RValue::RVPositiveInteger(num) => Ok(num),
},
};
let right_side: Result<&dyn ContextElement, WalkError> =
match param_map.get("value") {
None => Err(WalkError::CantWalk),
Some(rval) => match rval {
RValue::RVString(text) => Ok(text),
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
RValue::RVPositiveInteger(num) => Ok(num),
},
};
if left_side != right_side {
match &parameterized_block.contents {
None => return Ok("".to_owned()),
Some(body) => {
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
return Ok(rendered_content);
}
}
} else {
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);
}
}
}
}
_ => (), // TODO: Implement the rest
}
Ok("".to_owned())