From 0996a6c98a6c5522a13b7f66db0a10ea10a8028c Mon Sep 17 00:00:00 2001 From: Ed Lewis Date: Tue, 3 Mar 2020 15:18:35 +0000 Subject: [PATCH 01/13] chore(travis): remove old rust versions from build matrix Fixes #70 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) 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 From 5cd7a565712c29923029bf4c509f4e9a379bed80 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Sun, 12 Aug 2018 14:57:28 +0200 Subject: [PATCH 02/13] fix(template): allow rendering boolean values as leafs Fixes #60. --- src/template.rs | 5 +++++ tests/template.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) 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 = "\ From 4dbc137bd06d1b471a735dbf4b213a3713eb79d8 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 24 May 2019 19:09:58 +0200 Subject: [PATCH 03/13] chore(log): update log to 0.4 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4586cea..ca75359 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT/Apache-2.0" unstable = [] [dependencies] -log = "0.3.5" +log = "0.4" serde = "1.0.0" [dev-dependencies] From af5ec8c2f6eb7acd9ad7600be9330e083c96d2c9 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 24 May 2019 19:15:30 +0200 Subject: [PATCH 04/13] chore(*): switch from tempdir to tempfile tempdir is deprecated --- Cargo.toml | 2 +- tests/template.rs | 4 ++-- tests/test.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca75359..d46f3d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ 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/tests/template.rs b/tests/template.rs index 8c6a472..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; @@ -538,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; From 222303308c1f00f0d5fd3cc5b63560deb226dd23 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 24 May 2019 19:16:01 +0200 Subject: [PATCH 05/13] feat(version): 0.9.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d46f3d3..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" From 11eb0ea72b30cf827d044af273933517ee699b1d Mon Sep 17 00:00:00 2001 From: Ben Stern Date: Sat, 3 Apr 2021 17:02:59 -0400 Subject: [PATCH 06/13] Eliminate panics from live code. As a library, panicking, even in the face of a bug, is a problem. Also, a lot of warnings (mostly `try!` vs `?` and `dyn`) were removed, as part of the edit/rebuild/test cycle. --- src/compiler.rs | 6 ++-- src/context.rs | 8 ++--- src/data.rs | 12 +++++-- src/encoder.rs | 14 ++++---- src/error.rs | 6 ++-- src/macros.rs | 4 +-- src/parser.rs | 33 ++++++++--------- src/template.rs | 92 +++++++++++++++++++++-------------------------- tests/template.rs | 11 +++--- 9 files changed, 89 insertions(+), 97 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index dcd6eae..b40e558 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -51,7 +51,7 @@ impl> Compiler { pub fn compile(mut self) -> Result<(Vec, PartialsMap)> { let (tokens, partials) = { let parser = Parser::new(&mut self.reader, &self.otag, &self.ctag); - try!(parser.parse()) + parser.parse()? }; // Compile the partials if we haven't done so already. @@ -66,7 +66,7 @@ impl> Compiler { match File::open(&path) { Ok(mut file) => { let mut string = String::new(); - try!(file.read_to_string(&mut string)); + file.read_to_string(&mut string)?; let compiler = Compiler { ctx: self.ctx.clone(), @@ -76,7 +76,7 @@ impl> Compiler { ctag: "}}".to_string(), }; - let (tokens, subpartials) = try!(compiler.compile()); + let (tokens, subpartials) = compiler.compile()?; // Include subpartials self.partials.extend(subpartials.into_iter()); diff --git a/src/context.rs b/src/context.rs index e95aef6..16ef0db 100644 --- a/src/context.rs +++ b/src/context.rs @@ -37,7 +37,7 @@ impl Context { /// Compiles a template from a string pub fn compile>(&self, reader: IT) -> Result