diff --git a/src/template.rs b/src/template.rs index 1d6825e..daf325b 100644 --- a/src/template.rs +++ b/src/template.rs @@ -220,6 +220,11 @@ impl<'a> RenderContext<'a> { try!(self.render(wr, stack, &tokens)); } + Data::Bool(val) => { + let s = if val { "true" } else { "false" }; + try!(self.write_tracking_newlines(wr, s)); + } + ref value => { bug!("render_utag: unexpected value {:?}", value); } diff --git a/tests/template.rs b/tests/template.rs index fad2292..8c6a472 100644 --- a/tests/template.rs +++ b/tests/template.rs @@ -216,6 +216,51 @@ mod context_search { assert_eq!(rendered, expected); } + #[test] + fn renders_bool() { + let template = compile_str( +"{{bool}} +#map{{#outer}} + {{#bool}} + #bool + #vec{{#inner}}{{{.}}}{{/inner}}/vec + {{/bool}}\n\ + {{^not_ok}} + ^not_ok + #vec{{#inner}}{{{.}}}{{/inner}}/vec + {{/not_ok}}\n\ +{{/outer}} +/map +{{ok}}"); + let ctx = MapBuilder::new() + .insert_bool("bool", false) + .insert_bool("not_ok", false) + .insert_map("outer", |map| { + map.insert_bool("bool", true) + .insert_vec("inner", |vec| { + vec.push_bool(false) + .push_bool(true) + .push_bool(false) + }) + }) + .insert_bool("ok", true) + .build(); + + let expected = "false +#map + #bool + #vecfalsetruefalse/vec + + ^not_ok + #vecfalsetruefalse/vec + +/map +true"; + let rendered = render_data(&template, &ctx); + println!("{}\n----\n{}", rendered, expected); + assert_eq!(rendered, expected); + } + #[test] fn from_base() { let template = "\