Skip to content

Commit 765fd2a

Browse files
committed
(fix) fix partial included on evaluation [#146]
Signed-off-by: Ning Sun <[email protected]>
1 parent db5cc8d commit 765fd2a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/render.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,12 @@ impl Renderable for TemplateElement {
688688
}
689689
}
690690
DirectiveExpression(_) |
691-
DirectiveBlock(_) |
692-
PartialExpression(_) |
693-
PartialBlock(_) => self.eval(registry, rc),
691+
DirectiveBlock(_) => self.eval(registry, rc),
692+
#[cfg(not(feature="partial_legacy"))]
693+
PartialExpression(ref dt) | PartialBlock(ref dt) => {
694+
Directive::from_template(dt, registry, rc)
695+
.and_then(|di| partial::expand_partial(&di, registry, rc))
696+
}
694697
_ => Ok(()),
695698
}
696699
}
@@ -710,11 +713,6 @@ impl Evaluable for TemplateElement {
710713
}
711714
})
712715
}
713-
#[cfg(not(feature="partial_legacy"))]
714-
PartialExpression(ref dt) | PartialBlock(ref dt) => {
715-
Directive::from_template(dt, registry, rc)
716-
.and_then(|di| partial::expand_partial(&di, registry, rc))
717-
}
718716
_ => Ok(()),
719717
}
720718
}
@@ -907,3 +905,16 @@ fn test_render_error_line_no() {
907905
panic!("Error expected");
908906
}
909907
}
908+
909+
#[test]
910+
#[cfg(not(feature="partial_legacy"))]
911+
fn test_partial_failback_render() {
912+
let mut r = Registry::new();
913+
914+
assert!(r.register_template_string("parent", "<html>{{> layout}}</html>").is_ok());
915+
assert!(r.register_template_string("child", "{{#*inline \"layout\"}}content{{/inline}}{{#> parent}}{{> seg}}{{/parent}}").is_ok());
916+
assert!(r.register_template_string("seg", "1234").is_ok());
917+
918+
let r = r.render("child", &true).expect("should work");
919+
assert_eq!(r, "<html>content</html>");
920+
}

0 commit comments

Comments
 (0)