tablib_html.go 930 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package tablib
  2. // HTML returns the HTML representation of the Dataset as an Exportable.
  3. func (d *Dataset) HTML() *Exportable {
  4. back := d.Records()
  5. b := newBuffer()
  6. b.WriteString("<table class=\"table table-striped\">\n\t<thead>")
  7. for i, r := range back {
  8. b.WriteString("\n\t\t<tr>")
  9. for _, c := range r {
  10. tag := "td"
  11. if i == 0 {
  12. tag = "th"
  13. }
  14. b.WriteString("\n\t\t\t<" + tag + ">")
  15. b.WriteString(c)
  16. b.WriteString("</" + tag + ">")
  17. }
  18. b.WriteString("\n\t\t</tr>")
  19. if i == 0 {
  20. b.WriteString("\n\t</thead>\n\t<tbody>")
  21. }
  22. }
  23. b.WriteString("\n\t</tbody>\n</table>")
  24. return newExportable(b)
  25. }
  26. // HTML returns a HTML representation of the Databook as an Exportable.
  27. func (d *Databook) HTML() *Exportable {
  28. b := newBuffer()
  29. for _, s := range d.sheets {
  30. b.WriteString("<h1>" + s.title + "</h1>\n")
  31. b.Write(s.dataset.HTML().Bytes())
  32. b.WriteString("\n\n")
  33. }
  34. return newExportable(b)
  35. }