diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-02 16:31:49 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-02 16:31:49 +0100 |
commit | bc9c81a84f8b8ba33098d12104c39b171deb649e (patch) | |
tree | 3c42e4e605a41ea34bae90e9c3d7a5efb027c751 /src/resource.rs | |
parent | 3976034a4b99a750946d2f5242158db2fef33d35 (diff) | |
download | subplot-bc9c81a84f8b8ba33098d12104c39b171deb649e.tar.gz |
resources: Use new path checking order
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/resource.rs')
-rw-r--r-- | src/resource.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/resource.rs b/src/resource.rs index a03086c..2951654 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -28,10 +28,13 @@ pub struct ResourceOpts { impl ResourceOpts { /// Handle any supplied resource related arguments - pub fn handle(&self) { + pub fn handle<P: AsRef<Path>>(&self, doc_path: Option<P>) { for rpath in &self.resources { add_search_path(rpath); } + if let Some(doc_path) = doc_path.as_ref() { + add_search_path(doc_path); + } } } @@ -61,7 +64,17 @@ pub fn set_template(template: &str) { } /// Open a file for reading, honouring search paths established during -/// startup, and falling back to potentially embedded file content +/// startup, and falling back to potentially embedded file content. +/// +/// The search path sequence is: +/// +/// First any path given to `--resources` in the order of the arguments +/// Second, it's relative to the input document. +/// Third we look in `FALLBACK_PATH` if it's defined +/// Finally we check for an embedded file. +/// +/// Then we repeat all the above, inserting the template name in the subpath +/// too. pub fn open<P: AsRef<Path>>(subpath: P) -> io::Result<Box<dyn Read>> { let subpath = subpath.as_ref(); match internal_open(subpath) { @@ -100,7 +113,6 @@ fn internal_open(subpath: &Path) -> io::Result<Box<dyn Read>> { let search_paths = SEARCH_PATHS.lock().expect("Unable to lock SEARCH_PATHS"); let search_paths = search_paths.iter().map(|p| p.as_path()); let search_paths = std::iter::empty() - .chain(Some(Path::new("."))) .chain(search_paths) .chain(internal_fallback_path()); let mut ret = Err(io::Error::new( |