File tree Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -13,9 +13,12 @@ import (
13
13
log "github.com/sirupsen/logrus"
14
14
)
15
15
16
- // _trim trims a string for you... obviously
17
- func (t * Template ) _trim (s string ) string {
18
- return strings .TrimSpace (s )
16
+ // _space adds a space to the beginning of
17
+ // a string this way you can {{- -}} compress
18
+ // lines, and still have a space
19
+ func (t * Template ) _space (s string ) string {
20
+ s = strings .TrimSpace (s )
21
+ return " " + s
19
22
}
20
23
21
24
// _templateExists allows you to check if a
@@ -69,9 +72,10 @@ func (t *Template) _boolEnv(s string) bool {
69
72
func (t * Template ) addFuncs () * Template {
70
73
t .template .Funcs (template.FuncMap {
71
74
"boolEnv" : t ._boolEnv ,
75
+ "split" : strings .Split ,
72
76
"templateExists" : t ._templateExists ,
73
77
"envExists" : t ._envExists ,
74
- "trim" : t . _trim ,
78
+ "trim" : strings . Trim ,
75
79
"env" : t ._env ,
76
80
})
77
81
Original file line number Diff line number Diff line change @@ -28,15 +28,14 @@ func createTemplate(data string) *Template {
28
28
return t
29
29
}
30
30
31
- func TestTemplate__trim (t * testing.T ) {
31
+ func TestTemplate__space (t * testing.T ) {
32
32
tt := createTemplate ("" )
33
33
for _ , v := range [][3 ]interface {}{
34
- {"" , " " , "strips a blank string" },
35
- {"string" , " string" , "it strips l whitespace" },
36
- {"string" , "string " , "it strips r whitespace" },
37
- {"string" , "string\n " , "it strips newlines" },
34
+ {" 1" , "1" , "it works for simple strings" },
35
+ {" 1" , " 1 " , "it works for strings with space" },
36
+ {" 1" , "1\n " , "it works with newline" },
38
37
} {
39
- actual := tt ._trim (v [1 ].(string ))
38
+ actual := tt ._space (v [1 ].(string ))
40
39
assert .Equal (t , v [0 ], actual , v [2 ])
41
40
}
42
41
}
You can’t perform that action at this time.
0 commit comments