aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-08 19:34:22 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-08 19:34:22 +0100
commit4e34adcbbee5a1bc592692521bb1de5b24977931 (patch)
treeddf0b90c9e0e98cff5f586988eaeda0c78dd8a20
parent0bc54d366ae02347bd902111a311435790b46d2f (diff)
downloadaskama-4e34adcbbee5a1bc592692521bb1de5b24977931.tar.gz
askama-4e34adcbbee5a1bc592692521bb1de5b24977931.tar.bz2
askama-4e34adcbbee5a1bc592692521bb1de5b24977931.zip
Extract template_dir() helper method
Diffstat (limited to '')
-rw-r--r--askama/src/path.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/askama/src/path.rs b/askama/src/path.rs
index 5f500e2..7d75f1b 100644
--- a/askama/src/path.rs
+++ b/askama/src/path.rs
@@ -3,10 +3,14 @@ use std::fs::{self, DirEntry, File};
use std::io::{self, Read};
use std::path::{Path, PathBuf};
-pub fn get_template_source(tpl_file: &str) -> String {
- let root = env::var("CARGO_MANIFEST_DIR").unwrap();
- let mut path = PathBuf::from(root);
+fn template_dir() -> PathBuf {
+ let mut path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
path.push("templates");
+ path
+}
+
+pub fn get_template_source(tpl_file: &str) -> String {
+ let mut path = template_dir();
path.push(Path::new(tpl_file));
let mut f = File::open(path).unwrap();
let mut s = String::new();
@@ -30,8 +34,7 @@ fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> {
}
pub fn rerun_if_templates_changed() {
- let root = env::var("CARGO_MANIFEST_DIR").unwrap();
- visit_dirs(&Path::new(&root).join("templates"), &|e: &DirEntry| {
+ visit_dirs(&template_dir(), &|e: &DirEntry| {
println!("cargo:rerun-if-changed={}", e.path().to_str().unwrap());
}).unwrap();
}