dynja/
lib.rs

1// Re-export askama template, if askama_release is enabled and the build type is release
2#[cfg(all(feature = "askama_release", not(debug_assertions)))]
3pub use askama::Template;
4
5// Declare minijinja wrapper on debug, or if askama_release isn't enabled
6#[cfg(any(debug_assertions, not(feature = "askama_release")))]
7mod dynja_minijinja {
8    use minijinja::Environment;
9    use std::sync::{Mutex, OnceLock};
10
11    pub use dynja_derive::Template;
12
13    pub use minijinja;
14
15    pub trait TemplateFile {
16        const PATH: &'static str; // NOTE: this is not the actual path of the template.
17                                  // It's just the name of the variable taken in the #[template] macro,
18                                  // just like with 'askama'.
19    }
20
21    pub fn environment() -> &'static Mutex<Environment<'static>> {
22        static ENV: OnceLock<Mutex<Environment>> = OnceLock::new();
23        ENV.get_or_init(|| {
24            let mut env = Environment::new();
25            env.set_loader(minijinja::path_loader("templates"));
26
27            let mutex = Mutex::new(env);
28            mutex
29        })
30    }
31}
32
33// Re-export minijinja wrapper
34#[cfg(any(debug_assertions, not(feature = "askama_release")))]
35pub use dynja_minijinja::*;