Rendering a reference appears to do a truthiness check because false renders an empty string despite rendering as "false" in an array element.
This commit is contained in:
parent
0f47000a9b
commit
b45688351e
1
js/test_cases/not_exists/input1.json
Normal file
1
js/test_cases/not_exists/input1.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": ["Alice", "Bob", "Chris"]}
|
1
js/test_cases/not_exists/input10.json
Normal file
1
js/test_cases/not_exists/input10.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": {}}
|
1
js/test_cases/not_exists/input11.json
Normal file
1
js/test_cases/not_exists/input11.json
Normal file
@ -0,0 +1 @@
|
||||
["cat", "dog"]
|
1
js/test_cases/not_exists/input2.json
Normal file
1
js/test_cases/not_exists/input2.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": {"name": "Alice", "keyboard": "K-Type"}}
|
1
js/test_cases/not_exists/input3.json
Normal file
1
js/test_cases/not_exists/input3.json
Normal file
@ -0,0 +1 @@
|
||||
{"there_are_no_things": 4}
|
1
js/test_cases/not_exists/input4.json
Normal file
1
js/test_cases/not_exists/input4.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": "just a string"}
|
1
js/test_cases/not_exists/input5.json
Normal file
1
js/test_cases/not_exists/input5.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": false}
|
1
js/test_cases/not_exists/input6.json
Normal file
1
js/test_cases/not_exists/input6.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": null}
|
1
js/test_cases/not_exists/input7.json
Normal file
1
js/test_cases/not_exists/input7.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": 0}
|
1
js/test_cases/not_exists/input8.json
Normal file
1
js/test_cases/not_exists/input8.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": ""}
|
1
js/test_cases/not_exists/input9.json
Normal file
1
js/test_cases/not_exists/input9.json
Normal file
@ -0,0 +1 @@
|
||||
{"things": []}
|
5
js/test_cases/not_exists/main.dust
Normal file
5
js/test_cases/not_exists/main.dust
Normal file
@ -0,0 +1,5 @@
|
||||
{^things}
|
||||
Thing: {things}
|
||||
{:else}
|
||||
No things {.}
|
||||
{/things}
|
1
js/test_cases/render_unusual_types/input6.json
Normal file
1
js/test_cases/render_unusual_types/input6.json
Normal file
@ -0,0 +1 @@
|
||||
{"name": false}
|
1
js/test_cases/render_unusual_types/input7.json
Normal file
1
js/test_cases/render_unusual_types/input7.json
Normal file
@ -0,0 +1 @@
|
||||
{"name": true}
|
1
js/test_cases/render_unusual_types/input8.json
Normal file
1
js/test_cases/render_unusual_types/input8.json
Normal file
@ -0,0 +1 @@
|
||||
{"name": [[], {}, true, false, ""]}
|
@ -99,7 +99,9 @@ impl<'a> DustRenderer<'a> {
|
||||
}
|
||||
DustTag::DTReference(reference) => {
|
||||
let val = walk_path(breadcrumbs, &reference.path.keys);
|
||||
if let Err(RenderError::NotFound { .. }) = val {
|
||||
let loop_elements: Vec<&dyn ContextElement> = self.get_loop_elements(val)?;
|
||||
if loop_elements.is_empty() {
|
||||
// if let Err(RenderError::NotFound { .. }) = val {
|
||||
// If reference does not exist in the context, it becomes an empty string
|
||||
return Ok("".to_owned());
|
||||
} else {
|
||||
@ -151,6 +153,21 @@ impl<'a> DustRenderer<'a> {
|
||||
};
|
||||
}
|
||||
}
|
||||
DustTag::DTNotExists(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…
Reference in New Issue
Block a user