File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use crate :: LUA ;
22use minijinja:: ErrorKind :: UndefinedError ;
33use mlua:: { ExternalError , FromLua , LuaSerdeExt , UserData } ;
4+ use regex;
45use std:: sync:: Arc ;
56
67/// Will include the name, path, and source
@@ -145,14 +146,43 @@ impl UserData for TemplatingEngine<'_> {
145146 . collect :: < Vec < _ > > ( ) )
146147 } ) ;
147148 methods. add_method_mut ( "exclude_templates" , |_, this, names : Vec < String > | {
148- for i in names {
149- this. templates = this
150- . templates
151- . iter ( )
152- . filter ( |template| template. name != i)
153- . cloned ( )
154- . collect :: < Vec < _ > > ( ) ;
155- this. exclusions . push ( i. into ( ) ) ;
149+ for pattern in names {
150+ if pattern. contains ( '*' ) || pattern. contains ( '?' ) || pattern. contains ( '[' ) {
151+ let re_pattern = pattern
152+ . replace ( "." , "\\ ." )
153+ . replace ( "**" , "###DOUBLESTAR###" )
154+ . replace ( "*" , "[^/]*" )
155+ . replace ( "###DOUBLESTAR###" , ".*" )
156+ . replace ( "?" , "." ) ;
157+ let re = regex:: Regex :: new ( & re_pattern)
158+ . unwrap_or_else ( |_| regex:: Regex :: new ( ".*" ) . unwrap ( ) ) ;
159+ this. templates = this
160+ . templates
161+ . iter ( )
162+ . filter ( |template| {
163+ let name_match = re. is_match ( & template. name ) ;
164+ let path_match = template
165+ . path
166+ . as_ref ( )
167+ . map ( |p| {
168+ let path_str = p. replace ( "\\ " , "/" ) ;
169+ re. is_match ( & path_str)
170+ } )
171+ . unwrap_or ( false ) ;
172+ !name_match && !path_match
173+ } )
174+ . cloned ( )
175+ . collect :: < Vec < _ > > ( ) ;
176+ this. exclusions . push ( pattern. into ( ) ) ;
177+ } else {
178+ this. templates = this
179+ . templates
180+ . iter ( )
181+ . filter ( |template| template. name != pattern)
182+ . cloned ( )
183+ . collect :: < Vec < _ > > ( ) ;
184+ this. exclusions . push ( pattern. into ( ) ) ;
185+ }
156186 }
157187
158188 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments