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
use minijinja::Environment;
use std::cell::OnceCell;
use std::sync::{Arc, Mutex, OnceLock};

#[cfg(debug_assertions)]
pub use dynja_derive::Template;

#[cfg(not(debug_assertions))]
pub use askama::Template;

pub use minijinja;

pub trait TemplateFile {
    const PATH: &'static str; // NOTE: this is not the actual path of the template.
                              // It's just the name of the variable taken in the #[template] macro,
                              // just like with 'askama'.
}

pub fn templates() -> &'static Environment<'static> {
    static ENV: OnceLock<Environment> = OnceLock::new();
    ENV.get_or_init(|| {
        let mut env = Environment::new();
        env.set_loader(minijinja::path_loader("templates"));
        env
    })
}