Skip to content

Commit

Permalink
Add "last"
Browse files Browse the repository at this point in the history
  • Loading branch information
md5 committed Oct 29, 2014
1 parent 3de56f0 commit 842073e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"log"
"os"
"path/filepath"
"reflect"
"sort"
"strings"
"syscall"
"text/template"
Expand Down Expand Up @@ -90,6 +92,11 @@ func marshalJson(input interface{}) (string,error) {
return strings.TrimSuffix(buf.String(), "\n"), nil
}

func arrayLast(input interface{}) interface{} {
arr := reflect.ValueOf(input)
return arr.Index(arr.Len() - 1).Interface()
}

func generateFile(config Config, containers Context) bool {
templatePath := config.Template
tmpl, err := template.New(filepath.Base(templatePath)).Funcs(template.FuncMap{
Expand All @@ -102,6 +109,7 @@ func generateFile(config Config, containers Context) bool {
"dict": dict,
"sha1": hashSha1,
"json": marshalJson,
"last": arrayLast,
}).ParseFiles(templatePath)
if err != nil {
log.Fatalf("unable to parse template: %s", err)
Expand Down

0 comments on commit 842073e

Please sign in to comment.