diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-08 18:33:04 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-08 18:34:25 +0100 |
commit | 66dd21c8577330c625f32c7cf59635dbc7c36115 (patch) | |
tree | 6f0c16cf8ae5ae829345d98c94ae01b097aa68c1 | |
parent | 1dc554fafc8a97c211d35e7d756c04bc0dc93c1c (diff) | |
download | askama-66dd21c8577330c625f32c7cf59635dbc7c36115.tar.gz askama-66dd21c8577330c625f32c7cf59635dbc7c36115.tar.bz2 askama-66dd21c8577330c625f32c7cf59635dbc7c36115.zip |
Move build script helper code into askama crate
-rw-r--r-- | askama/src/lib.rs | 2 | ||||
-rw-r--r-- | askama/src/path.rs | 26 | ||||
-rw-r--r-- | testing/Cargo.toml | 3 | ||||
-rw-r--r-- | testing/build.rs | 25 |
4 files changed, 33 insertions, 23 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 80b5c25..2b59cf0 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -14,3 +14,5 @@ pub trait Template { pub mod filters; pub mod generator; pub mod parser; +mod path; +pub use path::rerun_if_templates_changed; diff --git a/askama/src/path.rs b/askama/src/path.rs new file mode 100644 index 0000000..c09b200 --- /dev/null +++ b/askama/src/path.rs @@ -0,0 +1,26 @@ +use std::env; +use std::fs::{self, DirEntry}; +use std::io; +use std::path::Path; + +fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> { + if dir.is_dir() { + for entry in try!(fs::read_dir(dir)) { + let entry = try!(entry); + let path = entry.path(); + if path.is_dir() { + try!(visit_dirs(&path, cb)); + } else { + cb(&entry); + } + } + } + Ok(()) +} + +pub fn rerun_if_templates_changed() { + let root = env::var("CARGO_MANIFEST_DIR").unwrap(); + visit_dirs(&Path::new(&root).join("templates"), &|e: &DirEntry| { + println!("cargo:rerun-if-changed={}", e.path().to_str().unwrap()); + }).unwrap(); +} diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 6acdaf5..449cc6b 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -8,3 +8,6 @@ build = "build.rs" [dependencies] askama = { path = "../askama" } askama_derive = { path = "../askama_derive" } + +[build-dependencies] +askama = { path = "../askama" } diff --git a/testing/build.rs b/testing/build.rs index 2f868f4..89e3e6b 100644 --- a/testing/build.rs +++ b/testing/build.rs @@ -1,26 +1,5 @@ -use std::env; -use std::fs::{self, DirEntry}; -use std::io; -use std::path::Path; - -fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> { - if dir.is_dir() { - for entry in try!(fs::read_dir(dir)) { - let entry = try!(entry); - let path = entry.path(); - if path.is_dir() { - try!(visit_dirs(&path, cb)); - } else { - cb(&entry); - } - } - } - Ok(()) -} +extern crate askama; fn main() { - let root = env::var("CARGO_MANIFEST_DIR").unwrap(); - visit_dirs(&Path::new(&root).join("templates"), &|e: &DirEntry| { - println!("cargo:rerun-if-changed={}", e.path().to_str().unwrap()); - }).unwrap(); + askama::rerun_if_templates_changed(); } |