From d9fcd348d121b6dd0568314b28ec187f11e32c77 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 11 Apr 2022 16:16:36 +0200 Subject: Add config option to derive macro so we can specify config file location --- askama_shared/src/lib.rs | 10 ++++++++-- 1 file changed, 8 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 2aa7114..07331bc 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -327,12 +327,18 @@ struct RawEscaper<'a> { extensions: Vec<&'a str>, } -fn read_config_file() -> std::result::Result { +fn read_config_file(config_path: &Option) -> std::result::Result { let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); - let filename = root.join(CONFIG_FILE_NAME); + let filename = match config_path { + Some(config_path) => root.join(config_path), + None => root.join(CONFIG_FILE_NAME), + }; + if filename.exists() { fs::read_to_string(&filename) .map_err(|_| format!("unable to read {:?}", filename.to_str().unwrap()).into()) + } else if config_path.is_some() { + Err(format!("`{}` does not exist", root.display()).into()) } else { Ok("".to_string()) } -- cgit