summaryrefslogtreecommitdiff
path: root/src/resource.rs
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2021-08-22 13:21:55 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2021-09-07 17:32:20 +0100
commitdd97ce7e9ddf146e70d0d7d966f001c64d8b03a5 (patch)
treee589e55ee1711744cdb3418e52647e958b1c2186 /src/resource.rs
parentd5c69db746b5c4ba938248a7d1c285256c6e6412 (diff)
downloadsubplot-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/resource.rs')
-rw-r--r--src/resource.rs48
1 files changed, 28 insertions, 20 deletions
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),
}
}