Add support for the exists tag.

master
Tom Alexander 4 years ago
parent 35f1ba8447
commit 0f47000a9b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -0,0 +1 @@
Exists appears to follow the same truthiness rules that sections follow, rather than merely checking if a value exists.

@ -0,0 +1 @@
{"things": ["Alice", "Bob", "Chris"]}

@ -0,0 +1 @@
{"things": {"name": "Alice", "keyboard": "K-Type"}}

@ -0,0 +1 @@
{"there_are_no_things": 4}

@ -0,0 +1 @@
{"things": "just a string"}

@ -0,0 +1,5 @@
{?things}
Thing: {things}
{:else}
No things {.}
{/things}

@ -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())

Loading…
Cancel
Save