diff --git a/.travis.yml b/.travis.yml index 5590434..004d35f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,6 @@ cache: - target rust: -- 1.16.0 -- 1.17.0 - stable - nightly - beta diff --git a/Cargo.toml b/Cargo.toml index 4586cea..d15c8b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "mustache" description = "Rust implementation of Mustache" repository = "https://github.com/nickel-org/rust-mustache" documentation = "http://nickel-org.github.io/rust-mustache" -version = "0.9.0" +version = "0.9.1" authors = ["erick.tryzelaar@gmail.com"] license = "MIT/Apache-2.0" @@ -11,13 +11,13 @@ license = "MIT/Apache-2.0" unstable = [] [dependencies] -log = "0.3.5" +log = "0.4" serde = "1.0.0" [dev-dependencies] serde_derive = "1.0.0" serde_json = "1.0.0" -tempdir = "0.3.4" +tempfile = "3" [[test]] name = "test" 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..de82d78 100644 --- a/tests/template.rs +++ b/tests/template.rs @@ -1,5 +1,5 @@ use std::cell::RefCell; -use tempdir::TempDir; +use tempfile::Builder; use std::fmt::Debug; use std::fs::File; use std::io::Write; @@ -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 = "\ @@ -493,7 +538,7 @@ fn run_test(test: serde_json::Map, data: Data) { // Make a temporary dir where we'll store our partials. This is to // avoid a race on filenames. - let tmpdir = TempDir::new("").expect("Failed to make tempdir"); + let tmpdir = Builder::new().tempdir().expect("Failed to make tempdir"); if let Some(value) = test.get("partials") { write_partials(tmpdir.path(), value) diff --git a/tests/test.rs b/tests/test.rs index a1c5017..bdfd0e0 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,7 +1,7 @@ extern crate mustache; extern crate serde; extern crate serde_json; -extern crate tempdir; +extern crate tempfile; #[macro_use] extern crate serde_derive;