diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-08-22 13:21:55 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-09-07 17:32:20 +0100 |
commit | dd97ce7e9ddf146e70d0d7d966f001c64d8b03a5 (patch) | |
tree | e589e55ee1711744cdb3418e52647e958b1c2186 /src | |
parent | d5c69db746b5c4ba938248a7d1c285256c6e6412 (diff) | |
download | subplot-dd97ce7e9ddf146e70d0d7d966f001c64d8b03a5.tar.gz |
core: Adjust behaviour for bindings and function file finding
From now on, we search $ common/$ then template/$ and as such
we will find common (polyglot) bindings automatically
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/metadata.rs | 18 | ||||
-rw-r--r-- | src/resource.rs | 48 |
2 files changed, 34 insertions, 32 deletions
diff --git a/src/metadata.rs b/src/metadata.rs index 3fd2f08..4542c09 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -33,8 +33,8 @@ impl Metadata { { let title = get_title(&doc.meta); let date = get_date(&doc.meta); - let bindings_filenames = get_bindings_filenames(basedir.as_ref(), &doc.meta); - let functions_filenames = get_functions_filenames(basedir.as_ref(), &doc.meta); + let bindings_filenames = get_bindings_filenames(&doc.meta); + let functions_filenames = get_functions_filenames(&doc.meta); let bibliographies = get_bibliographies(basedir.as_ref(), &doc.meta); let classes = get_classes(&doc.meta); event!( @@ -128,18 +128,12 @@ fn get_date(map: &Mapp) -> Option<String> { get_string(map, "date") } -fn get_bindings_filenames<P>(basedir: P, map: &Mapp) -> Vec<PathBuf> -where - P: AsRef<Path>, -{ - get_paths(basedir, map, "bindings") +fn get_bindings_filenames(map: &Mapp) -> Vec<PathBuf> { + get_paths("", map, "bindings") } -fn get_functions_filenames<P>(basedir: P, map: &Mapp) -> Vec<PathBuf> -where - P: AsRef<Path>, -{ - get_paths(basedir, map, "functions") +fn get_functions_filenames(map: &Mapp) -> Vec<PathBuf> { + get_paths("", map, "functions") } fn get_template_spec(map: &Mapp) -> Result<Option<(String, TemplateSpec)>> { diff --git a/src/resource.rs b/src/resource.rs index bd6fc34..758ffca 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -71,31 +71,39 @@ fn add_search_path<P: AsRef<Path>>(path: P) { /// Second, it's relative to the input document. /// Finally we check for an embedded file. /// -/// Then we repeat all the above, inserting the template name in the subpath +/// Then we repeat all the above, inserting 'common' as the template name, and +/// finally repeat the above inserting the real template name in the subpath /// too. fn open<P: AsRef<Path>>(subpath: P, template: Option<&str>) -> io::Result<Box<dyn Read>> { let subpath = subpath.as_ref(); - match internal_open(subpath) { - Ok(r) => Ok(r), - Err(e) => { - if let Some(templ) = template { - let subpath = Path::new(templ).join(subpath); - match internal_open(&subpath) { - Ok(r) => Ok(r), - Err(sub_e) => { - if sub_e.kind() != io::ErrorKind::NotFound - && e.kind() == io::ErrorKind::NotFound - { - Err(sub_e) - } else { - Err(e) - } - } - } - } else { - Err(e) + let plain = match internal_open(subpath) { + Ok(r) => return Ok(r), + Err(e) => e, + }; + let commonpath = Path::new("common").join(subpath); + let common = match internal_open(&commonpath) { + Ok(r) => return Ok(r), + Err(e) => e, + }; + let templated = match template { + Some(templ) => { + let templpath = Path::new(templ).join(subpath); + match internal_open(&templpath) { + Ok(r) => return Ok(r), + Err(e) => Some(e), } } + None => None, + }; + if plain.kind() != io::ErrorKind::NotFound { + return Err(plain); + } + if common.kind() != io::ErrorKind::NotFound { + return Err(common); + } + match templated { + Some(e) => Err(e), + None => Err(common), } } |