@@ -29,6 +29,8 @@ type TemplateLoader struct {
29
29
paths []string
30
30
// Map from template name to the path from whence it was loaded.
31
31
templatePaths map [string ]string
32
+ // templateNames is a map from lower case template name to the real template name.
33
+ templateNames map [string ]string
32
34
}
33
35
34
36
type Template interface {
@@ -192,6 +194,7 @@ func (loader *TemplateLoader) Refresh() *Error {
192
194
193
195
loader .compileError = nil
194
196
loader .templatePaths = map [string ]string {}
197
+ loader .templateNames = map [string ]string {}
195
198
196
199
// Set the template delimiters for the project if present, then split into left
197
200
// and right delimiters around a space character
@@ -279,11 +282,13 @@ func (loader *TemplateLoader) Refresh() *Error {
279
282
}
280
283
281
284
// If we already loaded a template of this name, skip it.
282
- if _ , ok := loader .templatePaths [templateName ]; ok {
285
+ lowerTemplateName := strings .ToLower (templateName )
286
+ if _ , ok := loader .templateNames [lowerTemplateName ]; ok {
283
287
return nil
284
288
}
285
289
286
290
loader .templatePaths [templateName ] = path
291
+ loader .templateNames [lowerTemplateName ] = templateName
287
292
288
293
// Load the file if we haven't already
289
294
if fileStr == "" {
@@ -407,14 +412,10 @@ func parseTemplateError(err error) (templateName string, line int, description s
407
412
// this case, if a template is returned, it may still be usable.)
408
413
func (loader * TemplateLoader ) Template (name string ) (Template , error ) {
409
414
// Case-insensitive matching of template file name
410
- name = strings .ToLower (name )
411
- for k := range loader .templatePaths {
412
- if name == strings .ToLower (k ) {
413
- name = k
414
- }
415
- }
415
+ templateName := loader .templateNames [strings .ToLower (name )]
416
+
416
417
// Look up and return the template.
417
- tmpl := loader .templateSet .Lookup (name )
418
+ tmpl := loader .templateSet .Lookup (templateName )
418
419
419
420
// This is necessary.
420
421
// If a nil loader.compileError is returned directly, a caller testing against
0 commit comments