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
|
UpdatedForHumans string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func add(x, y int) int {
|
||||||
|
return x + y
|
||||||
|
}
|
||||||
|
|
||||||
func generate(title string, table *Table, outputFile string) {
|
func generate(title string, table *Table, outputFile string) {
|
||||||
fmt.Println("Generating page.")
|
fmt.Println("Generating page.")
|
||||||
|
|
||||||
@ -118,8 +122,12 @@ func generate(title string, table *Table, outputFile string) {
|
|||||||
|
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
funcMap := template.FuncMap {
|
||||||
|
"add": add,
|
||||||
|
}
|
||||||
|
|
||||||
w := bufio.NewWriter(f)
|
w := bufio.NewWriter(f)
|
||||||
template, err := template.ParseFiles("templates/table.html")
|
template, err := template.New("").Funcs(funcMap).ParseFiles("templates/table.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,14 @@
|
|||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th> </th>
|
||||||
{{range .Table.Headers}}
|
{{range .Table.Headers}}
|
||||||
<th>{{.}}</th>
|
<th>{{.}}</th>
|
||||||
{{end}}
|
{{end}}
|
||||||
</tr>
|
</tr>
|
||||||
{{range .Table.Rows}}
|
{{range $i, $r := .Table.Rows}}
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>{{add $i 1}}</td>
|
||||||
{{range .Data}}
|
{{range .Data}}
|
||||||
<td>{{.}}</td>
|
<td>{{.}}</td>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
Reference in New Issue
Block a user