-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
42 lines (34 loc) · 802 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package internal
import (
"bytes"
"strings"
)
// TBuf is to hold the executed templates.
type TBuf struct {
TemplateType TemplateType
EditableType EditableType
Name string
Subname string
Buf *bytes.Buffer
}
// TBufSlice is a slice of TBuf compatible with sort.Interface.
type TBufSlice []TBuf
func (t TBufSlice) Len() int {
return len(t)
}
func (t TBufSlice) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}
func (t TBufSlice) Less(i, j int) bool {
if t[i].TemplateType < t[j].TemplateType {
return true
} else if t[j].TemplateType < t[i].TemplateType {
return false
}
if strings.Compare(t[i].Name, t[j].Name) < 0 {
return true
} else if strings.Compare(t[j].Name, t[i].Name) < 0 {
return false
}
return strings.Compare(t[i].Subname, t[j].Subname) < 0
}