diff --git a/tablizer.go b/tablizer.go index 5d7e43b..c9887a6 100644 --- a/tablizer.go +++ b/tablizer.go @@ -108,6 +108,10 @@ type Page struct { UpdatedForHumans string } +func add(x, y int) int { + return x + y +} + func generate(title string, table *Table, outputFile string) { fmt.Println("Generating page.") @@ -118,8 +122,12 @@ func generate(title string, table *Table, outputFile string) { defer f.Close() + funcMap := template.FuncMap { + "add": add, + } + w := bufio.NewWriter(f) - template, err := template.ParseFiles("templates/table.html") + template, err := template.New("").Funcs(funcMap).ParseFiles("templates/table.html") if err != nil { panic(err) } diff --git a/templates/table.html b/templates/table.html index 674b1a3..cd14c90 100644 --- a/templates/table.html +++ b/templates/table.html @@ -14,12 +14,14 @@
{{range .Table.Headers}} | {{.}} | {{end}}
---|---|
{{add $i 1}} | {{range .Data}}{{.}} | {{end}}