proplate_core/
local.rs

1use std::{
2  env::current_exe,
3  path::{Path, PathBuf},
4};
5
6use proplate_errors::{ProplateError, ProplateErrorKind, ProplateResult, TemplateErrorKind};
7
8pub fn local_template_path() -> PathBuf {
9  proplate_dir().join("builtins").join("templates")
10}
11
12pub fn get_local_template<P>(path: P) -> ProplateResult<PathBuf>
13where
14  P: AsRef<Path> + Copy,
15{
16  let tpath = local_template_path().join(path);
17  match tpath.exists() {
18    true => Ok(tpath),
19    _ => Err(
20      ProplateError::create(ProplateErrorKind::Template {
21        kind: TemplateErrorKind::NotFound { is_remote: false },
22        location: path.as_ref().display().to_string(),
23      })
24      .with_ctx("template:get_local"),
25    ),
26  }
27}
28
29pub fn proplate_dir() -> PathBuf {
30  let exe = current_exe().expect("Unable to resolve proplate path");
31  exe.parent().unwrap().to_owned()
32}