Add support for the exists tag.
This commit is contained in:
parent
35f1ba8447
commit
0f47000a9b
1
js/test_cases/exists/README.md
Normal file
1
js/test_cases/exists/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
Exists appears to follow the same truthiness rules that sections follow, rather than merely checking if a value exists.
|
1
js/test_cases/exists/input1.json
Normal file
1
js/test_cases/exists/input1.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": ["Alice", "Bob", "Chris"]}
|
1
js/test_cases/exists/input10.json
Normal file
1
js/test_cases/exists/input10.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": {}}
|
1
js/test_cases/exists/input11.json
Normal file
1
js/test_cases/exists/input11.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
["cat", "dog"]
|
1
js/test_cases/exists/input2.json
Normal file
1
js/test_cases/exists/input2.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": {"name": "Alice", "keyboard": "K-Type"}}
|
1
js/test_cases/exists/input3.json
Normal file
1
js/test_cases/exists/input3.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"there_are_no_things": 4}
|
1
js/test_cases/exists/input4.json
Normal file
1
js/test_cases/exists/input4.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": "just a string"}
|
1
js/test_cases/exists/input5.json
Normal file
1
js/test_cases/exists/input5.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": false}
|
1
js/test_cases/exists/input6.json
Normal file
1
js/test_cases/exists/input6.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": null}
|
1
js/test_cases/exists/input7.json
Normal file
1
js/test_cases/exists/input7.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": 0}
|
1
js/test_cases/exists/input8.json
Normal file
1
js/test_cases/exists/input8.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": ""}
|
1
js/test_cases/exists/input9.json
Normal file
1
js/test_cases/exists/input9.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": []}
|
5
js/test_cases/exists/main.dust
Normal file
5
js/test_cases/exists/main.dust
Normal file
@ -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
|
// an empty array or null), Dust uses the
|
||||||
// original context before walking the path as
|
// original context before walking the path as
|
||||||
// the context for rendering the else block
|
// 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 {
|
return match &container.else_contents {
|
||||||
Some(body) => self.render_body(&body, breadcrumbs),
|
Some(body) => self.render_body(&body, breadcrumbs),
|
||||||
None => Ok("".to_owned()),
|
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
|
_ => (), // TODO: Implement the rest
|
||||||
}
|
}
|
||||||
Ok("".to_owned())
|
Ok("".to_owned())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user