Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ For example, this is a JSON version of an emitted RuntimeContainer struct:
* *`keys $map`*: Returns the keys from `$map`. If `$map` is `nil`, a `nil` is returned. If `$map` is not a `map`, an error will be thrown.
* *`last $array`*: Returns the last value of an array.
* *`parseBool $string`*: parseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error. Alias for [`strconv.ParseBool`](http://golang.org/pkg/strconv/#ParseBool)
* *`read $string`*: Read the content of the file located at `$path`
* *`replace $string $old $new $count`*: Replaces up to `$count` occurences of `$old` with `$new` in `$string`. Alias for [`strings.Replace`](http://golang.org/pkg/strings/#Replace)
* *`sha1 $string`*: Returns the hexadecimal representation of the SHA1 hash of `$string`.
* *`split $string $sep`*: Splits `$string` into a slice of substrings delimited by `$sep`. Alias for [`strings.Split`](http://golang.org/pkg/strings/#Split)
Expand Down
16 changes: 16 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ func exists(path string) (bool, error) {
return false, err
}

func read(path string) (string, error) {
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return "", nil
}
return "", err
}
b, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
return string(b), nil
}

func getArrayValues(funcName string, entries interface{}) (*reflect.Value, error) {
entriesVal := reflect.ValueOf(entries)

Expand Down Expand Up @@ -426,6 +441,7 @@ func newTemplate(name string) *template.Template {
"dict": dict,
"dir": dirList,
"exists": exists,
"read": read,
"first": arrayFirst,
"groupBy": groupBy,
"groupByKeys": groupByKeys,
Expand Down