A Rust application to showcase badge awards in the AT Protocol ecosystem.
1//! Template engine configuration for embedded and reloadable templates.
2//!
3//! Provides template engines with embedded assets (production) or
4//! filesystem auto-reloading (development). Feature-flag controlled.
5
6#[cfg(feature = "reload")]
7use minijinja_autoreload::AutoReloader;
8
9#[cfg(feature = "embed")]
10use minijinja::Environment;
11
12#[cfg(feature = "reload")]
13/// Build template environment with auto-reloading for development
14pub fn build_env() -> AutoReloader {
15 reload_env::build_env()
16}
17
18#[cfg(feature = "embed")]
19/// Build template environment with embedded templates for production
20pub fn build_env(http_external: String, version: String) -> Environment<'static> {
21 embed_env::build_env(http_external, version)
22}
23
24#[cfg(feature = "reload")]
25mod reload_env {
26 use std::path::PathBuf;
27
28 use minijinja::{Environment, path_loader};
29 use minijinja_autoreload::AutoReloader;
30
31 pub fn build_env() -> AutoReloader {
32 AutoReloader::new(move |notifier| {
33 let template_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("templates");
34 let mut env = Environment::new();
35 env.set_trim_blocks(true);
36 env.set_lstrip_blocks(true);
37 env.set_loader(path_loader(&template_path));
38 notifier.set_fast_reload(true);
39 notifier.watch_path(&template_path, true);
40 Ok(env)
41 })
42 }
43}
44
45#[cfg(feature = "embed")]
46mod embed_env {
47 use minijinja::Environment;
48
49 pub fn build_env(http_external: String, version: String) -> Environment<'static> {
50 let mut env = Environment::new();
51 env.set_trim_blocks(true);
52 env.set_lstrip_blocks(true);
53 env.add_global("base", format!("https://{}", http_external));
54 env.add_global("version", version.clone());
55 minijinja_embed::load_templates!(&mut env);
56 env
57 }
58}