aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_shared/src/path.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/askama_shared/src/path.rs b/askama_shared/src/path.rs
index d05d657..16ac0e5 100644
--- a/askama_shared/src/path.rs
+++ b/askama_shared/src/path.rs
@@ -25,14 +25,10 @@ pub fn get_template_source(tpl_path: &Path) -> String {
pub fn find_template_from_path(path: &str, start_at: Option<&Path>) -> PathBuf {
let dirs = template_dirs();
- if let Some(rel) = start_at {
- let root = search_template_in_dirs(&dirs, rel).expect(&format!(
- "unable to find previously available template file '{}'",
- rel.to_str().unwrap()
- ));
- let fs_rel_path = root.join(rel).with_file_name(path);
- if fs_rel_path.exists() {
- return fs_rel_path.to_owned();
+ if let Some(root) = start_at {
+ let relative = root.with_file_name(path);
+ if relative.exists() {
+ return relative.to_owned();
}
}
@@ -84,7 +80,6 @@ static CONFIG_FILE_NAME: &str = "askama.toml";
#[cfg(test)]
mod tests {
- use super::Path;
use super::{find_template_from_path, get_template_source};
#[test]
@@ -95,25 +90,29 @@ mod tests {
#[test]
fn find_absolute() {
- let path = find_template_from_path("sub/b.html", Some(Path::new("a.html")));
+ let root = find_template_from_path("a.html", None);
+ let path = find_template_from_path("sub/b.html", Some(&root));
assert!(path.to_str().unwrap().ends_with("sub/b.html"));
}
#[test]
#[should_panic]
fn find_relative_nonexistent() {
- find_template_from_path("b.html", Some(Path::new("a.html")));
+ let root = find_template_from_path("a.html", None);
+ find_template_from_path("b.html", Some(&root));
}
#[test]
fn find_relative() {
- let path = find_template_from_path("c.html", Some(Path::new("sub/b.html")));
+ let root = find_template_from_path("sub/b.html", None);
+ let path = find_template_from_path("c.html", Some(&root));
assert!(path.to_str().unwrap().ends_with("sub/c.html"));
}
#[test]
fn find_relative_sub() {
- let path = find_template_from_path("sub1/d.html", Some(Path::new("sub/b.html")));
+ let root = find_template_from_path("sub/b.html", None);
+ let path = find_template_from_path("sub1/d.html", Some(&root));
assert!(path.to_str().unwrap().ends_with("sub/sub1/d.html"));
}
}