Format
This commit is contained in:
parent
2950b0b9f8
commit
c7d89e4c03
3 changed files with 38 additions and 9 deletions
|
@ -17,13 +17,20 @@ fn get_temp_file() -> PathBuf {
|
||||||
|
|
||||||
|
|
||||||
fn get_csl_data(csl_name: String) -> Result<String, String> {
|
fn get_csl_data(csl_name: String) -> Result<String, String> {
|
||||||
let zip_file = try!(result_override(File::open(get_csl_path()), "Failed to read CSL zip".into()));
|
let zip_file =
|
||||||
let mut archive = try!(result_override(ZipArchive::new(zip_file), "Failed to load zip file".into()));
|
try!(result_override(File::open(get_csl_path()), "Failed to read CSL zip".into()));
|
||||||
|
let mut archive =
|
||||||
|
try!(result_override(ZipArchive::new(zip_file), "Failed to load zip file".into()));
|
||||||
debug_assert!(archive.len() >= 10);
|
debug_assert!(archive.len() >= 10);
|
||||||
let mut csl_zip_file = try!(result_override(archive.by_name(&format!("{}.csl", csl_name)), format!("Can't find CSL {}.", csl_name)));
|
let mut csl_zip_file = try!(result_override(
|
||||||
|
archive.by_name(&format!("{}.csl", csl_name)),
|
||||||
|
format!("Can't find CSL {}.", csl_name)
|
||||||
|
));
|
||||||
debug_assert!(csl_zip_file.size() > 0);
|
debug_assert!(csl_zip_file.size() > 0);
|
||||||
let mut csl_buffer = String::new();
|
let mut csl_buffer = String::new();
|
||||||
try!(result_override(csl_zip_file.read_to_string(&mut csl_buffer), "Failed to read CSL".into()));
|
try!(
|
||||||
|
result_override(csl_zip_file.read_to_string(&mut csl_buffer), "Failed to read CSL".into())
|
||||||
|
);
|
||||||
return Ok(csl_buffer);
|
return Ok(csl_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,21 @@ fn check_references(config: Value) -> ValidationResult {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let references = config.get("references").unwrap();
|
let references = config.get("references").unwrap();
|
||||||
let bibliography = resolve_path(references.get("bibliography").unwrap().as_str().unwrap().into());
|
let bibliography =
|
||||||
let valid_extensions = vec!["bib", "bibtex", "copac", "json", "yaml", "enl", "xml", "wos", "medline", "mods", "ris"];
|
resolve_path(references.get("bibliography").unwrap().as_str().unwrap().into());
|
||||||
|
let valid_extensions = vec![
|
||||||
|
"bib",
|
||||||
|
"bibtex",
|
||||||
|
"copac",
|
||||||
|
"json",
|
||||||
|
"yaml",
|
||||||
|
"enl",
|
||||||
|
"xml",
|
||||||
|
"wos",
|
||||||
|
"medline",
|
||||||
|
"mods",
|
||||||
|
"ris",
|
||||||
|
];
|
||||||
if !bibliography.exists() {
|
if !bibliography.exists() {
|
||||||
return Err(format!("Can't find bibliography at {}.", bibliography.display()));
|
return Err(format!("Can't find bibliography at {}.", bibliography.display()));
|
||||||
}
|
}
|
||||||
|
@ -78,6 +91,12 @@ pub fn unwrap_group(config: Value, funcs: Vec<&Fn(Value) -> ValidationResult>) -
|
||||||
pub fn validate(config: Value) -> ValidationResult {
|
pub fn validate(config: Value) -> ValidationResult {
|
||||||
return unwrap_group(
|
return unwrap_group(
|
||||||
config,
|
config,
|
||||||
vec![&check_required_keys, &check_config_types, &check_input_files, &check_output_files, &check_references]
|
vec![
|
||||||
|
&check_required_keys,
|
||||||
|
&check_config_types,
|
||||||
|
&check_input_files,
|
||||||
|
&check_output_files,
|
||||||
|
&check_references,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,5 +82,8 @@ fn check_references(config: Value) -> ValidationResult {
|
||||||
|
|
||||||
|
|
||||||
pub fn check_config_types(config: Value) -> ValidationResult {
|
pub fn check_config_types(config: Value) -> ValidationResult {
|
||||||
return unwrap_group(config, vec![&check_root, &check_input, &check_output, &check_title, &check_references]);
|
return unwrap_group(
|
||||||
|
config,
|
||||||
|
vec![&check_root, &check_input, &check_output, &check_title, &check_references]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue