Add support for the exists tag.

This commit is contained in:
Tom Alexander
2020-05-06 19:10:09 -04:00
parent 35f1ba8447
commit 0f47000a9b
14 changed files with 32 additions and 3 deletions

View File

@@ -114,9 +114,6 @@ impl<'a> DustRenderer<'a> {
// an empty array or null), Dust uses the
// original context before walking the path as
// the context for rendering the else block
//
// TODO: do filters apply? I don't think so
// but I should test
return match &container.else_contents {
Some(body) => self.render_body(&body, breadcrumbs),
None => Ok("".to_owned()),
@@ -139,6 +136,21 @@ impl<'a> DustRenderer<'a> {
}
}
}
DustTag::DTExists(container) => {
let val = walk_path(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = self.get_loop_elements(val)?;
if loop_elements.is_empty() {
return match &container.else_contents {
Some(body) => self.render_body(&body, breadcrumbs),
None => Ok("".to_owned()),
};
} else {
return match &container.contents {
None => Ok("".to_owned()),
Some(body) => self.render_body(&body, breadcrumbs),
};
}
}
_ => (), // TODO: Implement the rest
}
Ok("".to_owned())