diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2022-04-11 16:16:36 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-04-21 10:08:42 +0200 |
commit | d9fcd348d121b6dd0568314b28ec187f11e32c77 (patch) | |
tree | e5bf64890cba10eeb6150033d3f43e35600b1a9e /askama_shared/src/lib.rs | |
parent | a51433677d98ebdba2008315b6d79565530fdf7e (diff) | |
download | askama-d9fcd348d121b6dd0568314b28ec187f11e32c77.tar.gz askama-d9fcd348d121b6dd0568314b28ec187f11e32c77.tar.bz2 askama-d9fcd348d121b6dd0568314b28ec187f11e32c77.zip |
Add config option to derive macro so we can specify config file location
Diffstat (limited to 'askama_shared/src/lib.rs')
-rw-r--r-- | askama_shared/src/lib.rs | 10 |
1 files changed, 8 insertions, 2 deletions
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<String, CompileError> { +fn read_config_file(config_path: &Option<String>) -> std::result::Result<String, CompileError> { 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()) } |