aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-10 15:39:45 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-10 15:39:45 +0100
commit325cb975a35579aaad273fc82c1ecc05a31ebe52 (patch)
treec356536e35ccc480055381f7f8e7d982a7ce3c3d
parentec61d60d69d65a6baceef76d644948a70217aaf2 (diff)
downloadaskama-325cb975a35579aaad273fc82c1ecc05a31ebe52.tar.gz
askama-325cb975a35579aaad273fc82c1ecc05a31ebe52.tar.bz2
askama-325cb975a35579aaad273fc82c1ecc05a31ebe52.zip
Simplify find_template_from_path() to use Config directly
-rw-r--r--askama_shared/src/path.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/askama_shared/src/path.rs b/askama_shared/src/path.rs
index 16ac0e5..f6eef40 100644
--- a/askama_shared/src/path.rs
+++ b/askama_shared/src/path.rs
@@ -5,10 +5,6 @@ use std::path::{Path, PathBuf};
use toml;
-fn search_template_in_dirs<'a>(dirs: &'a [PathBuf], path: &Path) -> Option<&'a PathBuf> {
- dirs.iter().find(|dir| dir.join(path).exists())
-}
-
pub fn get_template_source(tpl_path: &Path) -> String {
let mut f = match File::open(tpl_path) {
Err(_) => panic!("unable to open template file '{}'", tpl_path.to_str().unwrap()),
@@ -24,7 +20,6 @@ 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(root) = start_at {
let relative = root.with_file_name(path);
if relative.exists() {
@@ -32,13 +27,15 @@ pub fn find_template_from_path(path: &str, start_at: Option<&Path>) -> PathBuf {
}
}
- let mut rooted = PathBuf::new();
- match search_template_in_dirs(&dirs, &Path::new(path)) {
- Some(dir) => rooted.push(&dir),
- None => panic!("template {:?} not found in directories {:?}", path, dirs),
- };
- rooted.push(path);
- rooted
+ let config = Config::from_file();
+ for dir in &config.dirs {
+ let rooted = dir.join(path);
+ if rooted.exists() {
+ return rooted;
+ }
+ }
+
+ panic!("template {:?} not found in directories {:?}", path, config.dirs)
}
pub fn template_dirs() -> Vec<PathBuf> {