1
0
mirror of https://github.com/thebaer/tildes.git synced 2018-07-20 07:15:21 +00:00

Show row numbers in table HTML

This commit is contained in:
Matt Baer 2015-01-27 16:18:16 -05:00
parent 7a55895987
commit 3a12217262
2 changed files with 12 additions and 2 deletions

View File

@ -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)
}

View File

@ -14,12 +14,14 @@
<table>
<tr>
<th>&nbsp;</th>
{{range .Table.Headers}}
<th>{{.}}</th>
{{end}}
</tr>
{{range .Table.Rows}}
{{range $i, $r := .Table.Rows}}
<tr>
<td>{{add $i 1}}</td>
{{range .Data}}
<td>{{.}}</td>
{{end}}