Skip to content

Commit fdc18e4

Browse files
committed
Add a few more Stdlib funcs.
1 parent a7e0799 commit fdc18e4

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

funcs.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ import (
1313
log "github.com/sirupsen/logrus"
1414
)
1515

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
1922
}
2023

2124
// _templateExists allows you to check if a
@@ -69,9 +72,10 @@ func (t *Template) _boolEnv(s string) bool {
6972
func (t *Template) addFuncs() *Template {
7073
t.template.Funcs(template.FuncMap{
7174
"boolEnv": t._boolEnv,
75+
"split": strings.Split,
7276
"templateExists": t._templateExists,
7377
"envExists": t._envExists,
74-
"trim": t._trim,
78+
"trim": strings.Trim,
7579
"env": t._env,
7680
})
7781

funcs_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ func createTemplate(data string) *Template {
2828
return t
2929
}
3030

31-
func TestTemplate__trim(t *testing.T) {
31+
func TestTemplate__space(t *testing.T) {
3232
tt := createTemplate("")
3333
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"},
3837
} {
39-
actual := tt._trim(v[1].(string))
38+
actual := tt._space(v[1].(string))
4039
assert.Equal(t, v[0], actual, v[2])
4140
}
4241
}

0 commit comments

Comments
 (0)