Handle missing references
This commit is contained in:
parent
fe32edbc28
commit
24d2c1831c
1
js/test_cases/missing_reference/input1.json
Normal file
1
js/test_cases/missing_reference/input1.json
Normal file
@ -0,0 +1 @@
|
||||
{"rank": "Admiral"}
|
1
js/test_cases/missing_reference/main.dust
Normal file
1
js/test_cases/missing_reference/main.dust
Normal file
@ -0,0 +1 @@
|
||||
Hello {name}!
|
@ -87,8 +87,13 @@ impl<'a> DustRenderer<'a> {
|
||||
match tag {
|
||||
DustTag::DTComment(_comment) => (),
|
||||
DustTag::DTReference(reference) => {
|
||||
let val = walk_path(context, &reference.path.keys)?;
|
||||
return val.render();
|
||||
let val = walk_path(context, &reference.path.keys);
|
||||
if let Err(RenderError::WontWalk { .. }) = val {
|
||||
// If reference does not exist in the context, it becomes an empty string
|
||||
return Ok("".to_owned());
|
||||
} else {
|
||||
return val?.render();
|
||||
}
|
||||
}
|
||||
_ => (), // TODO: Implement the rest
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user