From f447a2a8d20b5cd6995b5c33260db23d04716f17 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 7 Apr 2022 16:51:09 +0200 Subject: Add suppress_whitespace config option --- askama_shared/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'askama_shared/src/lib.rs') diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index 5913eb3..2aa7114 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -118,6 +118,7 @@ struct Config<'a> { syntaxes: BTreeMap>, default_syntax: &'a str, escapers: Vec<(HashSet, String)>, + suppress_whitespace: bool, } impl Config<'_> { @@ -134,17 +135,19 @@ impl Config<'_> { RawConfig::from_toml_str(s)? }; - let (dirs, default_syntax) = match raw.general { + let (dirs, default_syntax, suppress_whitespace) = match raw.general { Some(General { dirs, default_syntax, + suppress_whitespace, }) => ( dirs.map_or(default_dirs, |v| { v.into_iter().map(|dir| root.join(dir)).collect() }), default_syntax.unwrap_or(DEFAULT_SYNTAX_NAME), + suppress_whitespace.unwrap_or(false), ), - None => (default_dirs, DEFAULT_SYNTAX_NAME), + None => (default_dirs, DEFAULT_SYNTAX_NAME, false), }; if let Some(raw_syntaxes) = raw.syntax { @@ -186,6 +189,7 @@ impl Config<'_> { syntaxes, default_syntax, escapers, + suppress_whitespace, }) } @@ -303,6 +307,7 @@ struct General<'a> { #[cfg_attr(feature = "serde", serde(borrow))] dirs: Option>, default_syntax: Option<&'a str>, + suppress_whitespace: Option, } #[cfg_attr(feature = "serde", derive(Deserialize))] @@ -646,4 +651,16 @@ mod tests { test.dyn_write_into(&mut vec).unwrap(); assert_eq!(vec, vec![b't', b'e', b's', b't']); } + + #[test] + fn test_suppress_whitespace_parsing() { + let config = Config::new( + r#" + [general] + suppress_whitespace = true + "#, + ) + .unwrap(); + assert!(config.suppress_whitespace); + } } -- cgit