From 3a12217262353783fe0c7b655e0f56b696662101 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 27 Jan 2015 16:18:16 -0500 Subject: [PATCH] Show row numbers in table HTML --- tablizer.go | 10 +++++++++- templates/table.html | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) 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}} - {{range .Table.Rows}} + {{range $i, $r := .Table.Rows}} + {{range .Data}} {{end}}
 {{.}}
{{add $i 1}}{{.}}