Added some notes about observed behavior and fixed return types for missing/absent keys.

master
Tom Alexander 4 years ago
parent 69fa266692
commit 716a110d2e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -7,3 +7,12 @@ Excerpt from [the DustJS tutorial](https://github.com/linkedin/dustjs/wiki/Dust-
Undefined, 0, empty string - zero
Any other value - length after conversion to string
This appears to be inaccurate (probably out of date because that tutorial was deprecated in favor of [dustjs.com](https://www.dustjs.com/), but the latter is incomplete and lacking any reference to the `@size` helper.
Corrections
-----------
- Booleans are 0, not converted to strings
Oddities
--------
Reference parameters (like `foo="{bar}"`) are usually treated as strings but it seems if it contains ONLY a reference to a value and not anything else, then it is still treated as a number.

@ -1,6 +1,6 @@
{
"val": {
"pet": "cat",
"name": "fluffy"
"name": "fluffy",
"pet": "cat"
}
}

@ -1,3 +1,3 @@
The size of val ({val|js|s}) is {@size key=val /}{~n}
The size of "{val}" is {@size key="{val}" /}{~n}
The size of "{~lb}val{~rb}" is {@size key="{val}" /}{~n}
The size with no key is {@size /}{~n}

@ -733,7 +733,12 @@ impl<'a> DustRenderer<'a> {
.map(|ce| ce.get_size())
});
match value_ce {
None | Some(Err(_)) | Some(Ok(None)) => return Ok("".to_owned()),
// If we found the key but could not get the size from it, render nothing.
Some(Ok(None)) => return Ok("".to_owned()),
// If "key" is not on the @size tag at all, render 0.
None => return Ok("0".to_owned()),
// If the key value could not be found in the context, render 0.
Some(Err(_)) => return Ok("0".to_owned()),
Some(Ok(Some(ce_size))) => {
return ce_size.get_context_element_reference().render(&Vec::new())
}

Loading…
Cancel
Save