Skip to content

Commit 60daafd

Browse files
committed
- [+] add sprintf alias
1 parent 8488377 commit 60daafd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

t_strings_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ func TestStringManipulation(t *testing.T) {
126126
`The {{if eq .StrTest "these rights belong to those people"}}eq says Yea{{else}}eq says Nay{{end}} but {{if eqf .StrTest "these rights belong to those people"}}eqf says Yea{{else}}eqf says Nay{{end}}.`,
127127
"The eq says Nay but eqf says Yea.",
128128
},
129+
{
130+
`{{$s := sprintf .StrTest}} {{$s}}`,
131+
" These rights belong to those people",
132+
},
133+
{
134+
`{{$s := sprintf "%s, %.2f" .StrTest 12.3456}} {{$s}}`,
135+
" These rights belong to those people, 12.35",
136+
},
129137

130138
// == standard regexp functions
131139
{

template.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package easygen
88

99
import (
10+
"fmt"
1011
"io"
1112
"os"
1213
"strings"
@@ -74,6 +75,7 @@ type Template interface {
7475
7576
eqf is wrapper for strings.EqualFold
7677
split is wrapper for strings.Fields
78+
sprintf is wrapper for fmt.Sprintf
7779
7880
regexpFindAllString is template function for RegexpFindAllString
7981
regexpFindAllStringIndex is template function for RegexpFindAllStringIndex
@@ -156,6 +158,7 @@ var egFuncMap = FuncMap{
156158
// aliases
157159
"eqf": strings.EqualFold,
158160
"split": strings.Fields,
161+
"sprintf": fmt.Sprintf,
159162

160163
// == standard regexp function definitions
161164
"regexpFindAllString": RegexpFindAllString,

0 commit comments

Comments
 (0)