archive
/
md-pdf-rs
Archived
1
Fork 0
This commit is contained in:
Jake Howard 2017-09-10 16:26:02 +01:00
parent 2950b0b9f8
commit c7d89e4c03
Signed by: jake
GPG Key ID: 57AFB45680EDD477
3 changed files with 38 additions and 9 deletions

View File

@ -17,13 +17,20 @@ fn get_temp_file() -> PathBuf {
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 mut archive = try!(result_override(ZipArchive::new(zip_file), "Failed to load zip file".into()));
let zip_file =
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);
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);
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);
}

View File

@ -52,8 +52,21 @@ fn check_references(config: Value) -> ValidationResult {
return Ok(());
}
let references = config.get("references").unwrap();
let bibliography = 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"];
let bibliography =
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() {
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 {
return unwrap_group(
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,
]
);
}

View File

@ -57,7 +57,7 @@ fn check_title(config: Value) -> ValidationResult {
fn check_references(config: Value) -> ValidationResult {
if config.get("references").is_none() {
return Ok(()); // references is optional, dont type it if it's not there
return Ok(()); // references is optional, dont type it if it's not there
}
if !config.get("references").unwrap().is_mapping() {
return Err("References should be mapping".into());
@ -82,5 +82,8 @@ fn check_references(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]
);
}