9
9
10
10
const GO_TEMPLATE = "go"
11
11
12
-
13
12
// Adapter for Go Templates.
14
13
type GoTemplate struct {
15
14
* template.Template
@@ -23,35 +22,34 @@ func (gotmpl GoTemplate) Render(wr io.Writer, arg interface{}) error {
23
22
}
24
23
25
24
type GoEngine struct {
26
- loader * TemplateLoader
27
- templateSet * template.Template
28
- // TemplatesBylowerName is a map from lower case template name to the real template.
29
- templatesBylowerName map [string ]* GoTemplate
30
- splitDelims []string
31
- CaseInsensitiveMode bool
25
+ loader * TemplateLoader
26
+ templateSet * template.Template
27
+ templatesByName map [string ]* GoTemplate
28
+ splitDelims []string
29
+ CaseInsensitive bool
32
30
}
33
31
34
32
func (i * GoEngine ) ConvertPath (path string ) string {
35
- if i .CaseInsensitiveMode {
33
+ if i .CaseInsensitive {
36
34
return strings .ToLower (path )
37
35
}
38
36
return path
39
37
}
40
38
41
- func (i * GoEngine ) Handles (templateView * TemplateView ) bool {
39
+ func (i * GoEngine ) Handles (templateView * TemplateView ) bool {
42
40
return EngineHandles (i , templateView )
43
41
}
44
42
45
43
func (engine * GoEngine ) ParseAndAdd (baseTemplate * TemplateView ) error {
46
44
// If alternate delimiters set for the project, change them for this set
47
- if engine .splitDelims != nil && strings .Index (baseTemplate .Location (), ViewsPath )> - 1 {
45
+ if engine .splitDelims != nil && strings .Index (baseTemplate .Location (), ViewsPath ) > - 1 {
48
46
engine .templateSet .Delims (engine .splitDelims [0 ], engine .splitDelims [1 ])
49
47
} else {
50
48
// Reset to default otherwise
51
49
engine .templateSet .Delims ("" , "" )
52
50
}
53
51
templateSource := string (baseTemplate .FileBytes )
54
- lowerTemplateName := engine .ConvertPath (baseTemplate .TemplateName )
52
+ templateName := engine .ConvertPath (baseTemplate .TemplateName )
55
53
tpl , err := engine .templateSet .New (baseTemplate .TemplateName ).Parse (templateSource )
56
54
if nil != err {
57
55
_ , line , description := ParseTemplateError (err )
@@ -63,13 +61,13 @@ func (engine *GoEngine) ParseAndAdd(baseTemplate *TemplateView) error {
63
61
SourceLines : strings .Split (templateSource , "\n " ),
64
62
}
65
63
}
66
- engine .templatesBylowerName [ lowerTemplateName ] = & GoTemplate {Template : tpl , engine : engine , TemplateView : baseTemplate }
64
+ engine .templatesByName [ templateName ] = & GoTemplate {Template : tpl , engine : engine , TemplateView : baseTemplate }
67
65
return nil
68
66
}
69
67
70
68
func (engine * GoEngine ) Lookup (templateName string ) Template {
71
69
// Case-insensitive matching of template file name
72
- if tpl , found := engine .templatesBylowerName [engine .ConvertPath (templateName )]; found {
70
+ if tpl , found := engine .templatesByName [engine .ConvertPath (templateName )]; found {
73
71
return tpl
74
72
}
75
73
return nil
@@ -80,10 +78,10 @@ func (engine *GoEngine) Name() string {
80
78
func (engine * GoEngine ) Event (action int , i interface {}) {
81
79
if action == TEMPLATE_REFRESH_REQUESTED {
82
80
// At this point all the templates have been passed into the
83
- engine .templatesBylowerName = map [string ]* GoTemplate {}
81
+ engine .templatesByName = map [string ]* GoTemplate {}
84
82
engine .templateSet = template .New ("__root__" ).Funcs (TemplateFuncs )
85
83
// Check to see what should be used for case sensitivity
86
- engine .CaseInsensitiveMode = Config .StringDefault ("go.template.path " , "lower" ) != "case"
84
+ engine .CaseInsensitive = Config .BoolDefault ("go.template.caseinsensitive " , true )
87
85
}
88
86
}
89
87
func init () {
@@ -101,10 +99,10 @@ func init() {
101
99
}
102
100
103
101
return & GoEngine {
104
- loader : loader ,
105
- templateSet : template .New ("__root__" ).Funcs (TemplateFuncs ),
106
- templatesBylowerName : map [string ]* GoTemplate {},
107
- splitDelims : splitDelims ,
102
+ loader : loader ,
103
+ templateSet : template .New ("__root__" ).Funcs (TemplateFuncs ),
104
+ templatesByName : map [string ]* GoTemplate {},
105
+ splitDelims : splitDelims ,
108
106
}, nil
109
107
})
110
108
}
0 commit comments