From 823c8bc1ad7574462b8019fb5900a1ceb16cc02a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 10 Sep 2017 18:51:40 +0100 Subject: [PATCH] Add struct for storing references data --- src/config/mod.rs | 10 +++++++++- src/config/read.rs | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index cf86287..8d16a03 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -15,7 +15,14 @@ pub struct Config { pub input: Vec, pub output: HashMap, pub title: String, - pub verbosity: u64 + pub verbosity: u64, + pub references: References +} + +#[derive(Debug, Serialize, Deserialize, Default, Clone)] +pub struct References { + pub bibliography: PathBuf, + pub csl: PathBuf } impl Config { @@ -24,6 +31,7 @@ impl Config { input: read::get_input_files(raw.clone()), output: read::get_output_files(raw.clone()), title: read::get_string(&raw, "title"), + references: read::get_references(raw.clone()), ..Default::default() }; } diff --git a/src/config/read.rs b/src/config/read.rs index 80b8834..36f7d7a 100644 --- a/src/config/read.rs +++ b/src/config/read.rs @@ -5,8 +5,10 @@ use std::io::Read; use serde_yaml::Value; use std::collections::HashMap; +use config::csl::unpack_csl; use config::consts; -use utils::result_override; +use config::References; +use utils::{result_override, resolve_path}; fn get_config_path() -> PathBuf { let mut working_dir = current_dir().unwrap(); @@ -55,3 +57,11 @@ pub fn get_output_files(conf: Value) -> HashMap { } return output_map; } + +pub fn get_references(config: Value) -> References { + let references = config.get("references").unwrap(); + return References { + bibliography: resolve_path(references.get("bibliography").unwrap().as_str().unwrap().into()), + csl: unpack_csl(references.get("csl").unwrap().as_str().unwrap().into()) + } +}