Skip to content

Commit

Permalink
add numbers function (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
natefinch authored Oct 21, 2017
1 parent 0ba6eb2 commit 973f5d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions environ/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"fmt"
"os/exec"
"path/filepath"
"strconv"
"strings"

"gnorm.org/gnorm/run/data"

"github.com/codemodus/kace"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -34,6 +37,7 @@ var FuncMap = map[string]interface{}{
"lastIndexAny": strings.LastIndexAny,
"makeMap": makeMap,
"makeSlice": makeSlice,
"numbers": numbers,
"pascal": kace.Pascal,
"repeat": strings.Repeat,
"replace": strings.Replace,
Expand Down Expand Up @@ -125,6 +129,15 @@ func sub(x int, vals ...int) int {
return x
}

// numbers returns a slice of strings of the numbers start to end (inclusive).
func numbers(start, end int) data.Strings {
var s data.Strings
for x := start; x <= end; x++ {
s = append(s, strconv.Itoa(x))
}
return s
}

// Plugin returns a function which can be used in templates for executing plugins,
// dirs is the list of directories which are used fo plugin lookup.
func Plugin(dirs []string) func(string, string, interface{}) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion site/content/cli/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ StaticDir = "static"
# "enums.gotmpl" would render the enums.gotmpl template with data from the
# "public.book_type" enum to ./gnorm/public/enums/users.go.
[EnumPaths]
"{{.Schema}}/enums/{{.Enum}}.go" = "enum.gotmpl"
"{{.Schema}}/enums/{{.Enum}}.go" = "templates/enum.gotmpl"
# TypeMap is a mapping of database type names to replacement type names
# (generally types from your language for deserialization), specifically for
Expand Down
5 changes: 5 additions & 0 deletions site/content/templates/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ gocog}}} -->
<tr><td>lastIndexAny</td><td>[https://golang.org/pkg/strings/#LastIndexAny](https://golang.org/pkg/strings/#LastIndexAny)</td></tr>
<tr><td>makeMap</td><td>[makeMap (see below)](/templates/functions/#makemap)</td></tr>
<tr><td>makeSlice</td><td>[makeSlice (see below)](/templates/functions/#makeslice)</td></tr>
<tr><td>numbers</td><td>[numbers (see below)](/templates/functions/#numbers)</td></tr>
<tr><td>pascal</td><td>[https://godoc.org/github.com/codemodus/kace#Pascal](https://godoc.org/github.com/codemodus/kace#Pascal)</td></tr>
<tr><td>repeat</td><td>[https://golang.org/pkg/strings/#Repeat](https://golang.org/pkg/strings/#Repeat)</td></tr>
<tr><td>replace</td><td>[https://golang.org/pkg/strings/#Replace](https://golang.org/pkg/strings/#Replace)</td></tr>
Expand Down Expand Up @@ -143,6 +144,10 @@ statements, etc.
makeSlice returns the arguments as a single slice. If all the arguments are
strings, they are returned as a []string, otherwise they're returned as
[]interface{}.
## numbers
` func numbers(start, end int) data.Strings `

numbers returns a slice of strings of the numbers start to end (inclusive).
## sliceString
` func sliceString(s string, start, end int) string `

Expand Down

0 comments on commit 973f5d9

Please sign in to comment.