Implemented the not equals helper.
This commit is contained in:
parent
94cedef3ef
commit
f4a935224c
@ -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 ¶meterized_block.contents {
|
||||||
|
None => return Ok("".to_owned()),
|
||||||
|
Some(body) => {
|
||||||
|
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
|
||||||
|
return Ok(rendered_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (), // TODO: Implement the rest
|
_ => (), // TODO: Implement the rest
|
||||||
}
|
}
|
||||||
Ok("".to_owned())
|
Ok("".to_owned())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user