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:
parent
7a55895987
commit
3a12217262
10
tablizer.go
10
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)
|
||||
}
|
||||
|
@ -14,12 +14,14 @@
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th> </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}}
|
||||
|
Loading…
Reference in New Issue
Block a user