1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::properties::Properties;
use std::path::{Path, PathBuf};
mod collection;
mod iter;
mod name;
mod registry;
pub use self::{collection::Collection, iter::Iter, name::Name};
const APP_BIN_DIR: &str = "src/bin/app";
pub struct Template<'a> {
name: Name,
inner: &'a handlebars::Template,
}
impl<'a> Template<'a> {
fn new(name: &'a str, template: &'a handlebars::Template) -> Self {
Self {
name: Name::from(name),
inner: template,
}
}
pub fn name(&self) -> &Name {
&self.name
}
}
impl<'a> Template<'a> {
pub fn output_path(&self, properties: &Properties) -> PathBuf {
let path = Path::new(self.name().as_ref());
let stemmed_path = path
.parent()
.expect("no output parent path")
.join(path.file_stem().expect("no file stem"));
if stemmed_path.starts_with(APP_BIN_DIR) {
Path::new(APP_BIN_DIR)
.parent()
.unwrap()
.join(properties.name.as_ref())
.join(stemmed_path.strip_prefix(APP_BIN_DIR).unwrap())
} else {
stemmed_path
}
}
}