aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-14 14:42:25 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-14 14:42:25 +0100
commit8be198581864eab72582b0f76c7a1adf72d618af (patch)
tree9cc6e72e626ab966af14a7364cbc3ec12296b545 /askama_shared/src/lib.rs
parentafee9b771b28fe4f8f5f7a687cb7a50d82a3f707 (diff)
downloadaskama-8be198581864eab72582b0f76c7a1adf72d618af.tar.gz
askama-8be198581864eab72582b0f76c7a1adf72d618af.tar.bz2
askama-8be198581864eab72582b0f76c7a1adf72d618af.zip
Make config file structure more future-proof
Diffstat (limited to '')
-rw-r--r--askama_shared/src/lib.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs
index bff7b57..2b82782 100644
--- a/askama_shared/src/lib.rs
+++ b/askama_shared/src/lib.rs
@@ -39,9 +39,14 @@ impl Config {
let default = vec![root.join("templates")];
let raw: RawConfig =
toml::from_str(&s).expect(&format!("invalid TOML in {}", CONFIG_FILE_NAME));
- let dirs = raw.dirs
- .map(|dirs| dirs.into_iter().map(|dir| root.join(dir)).collect())
- .unwrap_or_else(|| default);
+
+ let dirs = match raw.general {
+ Some(General { dirs: Some(dirs) }) => {
+ dirs.into_iter().map(|dir| root.join(dir)).collect()
+ }
+ Some(General { dirs: None }) | None => default,
+ };
+
Self { dirs }
}
@@ -69,6 +74,11 @@ impl Config {
#[derive(Deserialize)]
struct RawConfig {
+ general: Option<General>,
+}
+
+#[derive(Deserialize)]
+struct General {
dirs: Option<Vec<String>>,
}
@@ -92,7 +102,7 @@ mod tests {
fn test_config_dirs() {
let mut root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
root.push("tpl");
- let config = Config::from_str("dirs = [\"tpl\"]");
+ let config = Config::from_str("[general]\ndirs = [\"tpl\"]");
assert_eq!(config.dirs, vec![root]);
}