aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Guillaume Gomez <guillaume1.gomez@gmail.com>2022-04-07 16:51:09 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2022-04-21 10:08:42 +0200
commitf447a2a8d20b5cd6995b5c33260db23d04716f17 (patch)
tree12a7db258519f97a0561450c0cfabc3d4ff7738a /askama_shared/src/lib.rs
parentfc779e22c3bfa0e94df208a88a361b99e28a9129 (diff)
downloadaskama-f447a2a8d20b5cd6995b5c33260db23d04716f17.tar.gz
askama-f447a2a8d20b5cd6995b5c33260db23d04716f17.tar.bz2
askama-f447a2a8d20b5cd6995b5c33260db23d04716f17.zip
Add suppress_whitespace config option
Diffstat (limited to '')
-rw-r--r--askama_shared/src/lib.rs21
1 files changed, 19 insertions, 2 deletions
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<String, Syntax<'a>>,
default_syntax: &'a str,
escapers: Vec<(HashSet<String>, 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<Vec<&'a str>>,
default_syntax: Option<&'a str>,
+ suppress_whitespace: Option<bool>,
}
#[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);
+ }
}