use tera::Tera; use include_dir::Dir; /// Add templates from include_dir!() to Tera pub(crate) fn tera_includedir_walk_folder(tera : &mut Tera, dir: &Dir) { let mut templates = vec![]; tera_includedir_walk_folder_inner(&mut templates, tera, dir); tera.add_raw_templates(templates); } fn tera_includedir_walk_folder_inner(collected : &mut Vec<(String, String)>, tera : &mut Tera, dir: &Dir) { for f in dir.files() { if f.path().extension().unwrap_or_default() != "tera" { continue; } let name = f.path().file_stem().unwrap().to_str().unwrap().split('.').nth(0).unwrap(); let content = f.contents_utf8().unwrap(); let p = f.path().parent().unwrap().join(name); let template_path = p.to_str().unwrap(); debug!("Add template: {}", template_path); collected.push((template_path.to_string(), content.to_string())); } for subdir in dir.dirs() { tera_includedir_walk_folder_inner(collected, tera, subdir) } }