Skip to content

Commit ca8d406

Browse files
committed
- [#] Iterate accepts strings instead
1 parent 892786b commit ca8d406

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

test/nested_demo_argsm_iterate.ref

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Ape ate Apple000002 at 1234.56 - true2
44
Ape ate Apple000003 at 1234.56 - true3
55
Ape ate Apple000004 at 1234.56 - true4
66
Ape ate Apple000005 at 1234.56 - true5
7+
Ape ate Apple000000 at 1234.56 - true0
8+
Ape ate Apple000001 at 1234.56 - true1
9+
Ape ate Apple000002 at 1234.56 - true2
710
Ape ate Apple001001 at 1234.56 - true1001
811
Ape ate Apple001002 at 1234.56 - true1002
912
Ape ate Apple001003 at 1234.56 - true1003
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{{- define "T1"}}Apple{{.i}} at {{.c.Price}} - {{.c.Shipped}}{{end}} {{- define "T2"}}Ape{{end}}
2-
{{- range $val := iterate 5 }}
2+
{{- range $val := iterate "5" }}
33
{{- template "T2"}} ate {{template "T1" argsm "c" $ "i" (printf "%06d" $val)}}{{ $val }}
44
{{end }}
5-
{{- range $val := iterate 1003 1001 }}
5+
{{- range $val := iterate "2" (ENV "__START") }}
6+
{{- template "T2"}} ate {{template "T1" argsm "c" $ "i" (printf "%06d" $val)}}{{ $val }}
7+
{{end }}
8+
{{- range $val := iterate "1003" "1001" }}
69
{{- template "T2"}} ate {{template "T1" argsm "c" $ "i" (printf "%06d" $val)}}{{ $val }}
710
{{end }}

tf-calc.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package easygen
22

33
import (
44
"errors"
5+
"strconv"
56
)
67

78
//==========================================================================
89
// template function somewhat related to calculations
910

1011
// Iterate returns a slice whose end (& start) is controlled by the ic
11-
func Iterate(ic ...int) []int {
12-
end := ic[0]
12+
func Iterate(ic ...string) []int {
13+
// cannot think of a better way to report the Atoi error, other than --
14+
end, _ := strconv.Atoi(ic[0])
1315
start := 0
1416
if len(ic) > 1 {
15-
start = ic[1]
17+
start, _ = strconv.Atoi(ic[1])
1618
}
1719
var Items []int
1820
for i := start; i <= (end); i++ {

0 commit comments

Comments
 (0)