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
use std::{
  env::current_exe,
  path::{Path, PathBuf},
};

use proplate_errors::{ProplateError, ProplateResult};

pub fn local_template_path() -> PathBuf {
  proplate_dir().join("builtins").join("templates")
}

pub fn get_local_template<P>(path: P) -> ProplateResult<PathBuf>
where
  P: AsRef<Path>,
{
  let tpath = local_template_path().join(path);
  match tpath.exists() {
    true => Ok(tpath),
    _ => Err(ProplateError::local_template_not_found(
      tpath.display().to_string().as_str(),
    )),
  }
}

pub fn proplate_dir() -> PathBuf {
  let exe = current_exe().expect("Unable to resolve proplate path");
  exe.parent().unwrap().to_owned()
}