From b3a702a544ec28697802992da62e3756e95b249b Mon Sep 17 00:00:00 2001 From: Mira5121804 Date: Mon, 16 Feb 2026 17:22:12 +0100 Subject: [PATCH] feat(templates): add glob pattern support to exclude_templates (#66) --- src/components/templates.rs | 46 ++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/components/templates.rs b/src/components/templates.rs index 09d2f82..333b2ad 100644 --- a/src/components/templates.rs +++ b/src/components/templates.rs @@ -1,6 +1,7 @@ use crate::LUA; use minijinja::ErrorKind::UndefinedError; use mlua::{ExternalError, FromLua, LuaSerdeExt, UserData}; +use regex; use std::sync::Arc; /// Will include the name, path, and source @@ -145,14 +146,43 @@ impl UserData for TemplatingEngine<'_> { .collect::>()) }); methods.add_method_mut("exclude_templates", |_, this, names: Vec| { - for i in names { - this.templates = this - .templates - .iter() - .filter(|template| template.name != i) - .cloned() - .collect::>(); - this.exclusions.push(i.into()); + for pattern in names { + if pattern.contains('*') || pattern.contains('?') || pattern.contains('[') { + let re_pattern = pattern + .replace(".", "\\.") + .replace("**", "###DOUBLESTAR###") + .replace("*", "[^/]*") + .replace("###DOUBLESTAR###", ".*") + .replace("?", "."); + let re = regex::Regex::new(&re_pattern) + .unwrap_or_else(|_| regex::Regex::new(".*").unwrap()); + this.templates = this + .templates + .iter() + .filter(|template| { + let name_match = re.is_match(&template.name); + let path_match = template + .path + .as_ref() + .map(|p| { + let path_str = p.replace("\\", "/"); + re.is_match(&path_str) + }) + .unwrap_or(false); + !name_match && !path_match + }) + .cloned() + .collect::>(); + this.exclusions.push(pattern.into()); + } else { + this.templates = this + .templates + .iter() + .filter(|template| template.name != pattern) + .cloned() + .collect::>(); + this.exclusions.push(pattern.into()); + } } Ok(())