(dir string, table *schema.Table)
| 56 | } |
| 57 | |
| 58 | func (*Generator) renderTable(dir string, table *schema.Table) error { |
| 59 | t := template.New("") |
| 60 | t, err := t.New("table.md.go.tpl").ParseFS(templatesFS, "templates/table.md.go.tpl") |
| 61 | if err != nil { |
| 62 | return fmt.Errorf("failed to parse template: %v", err) |
| 63 | } |
| 64 | |
| 65 | outputPath := filepath.Join(dir, table.Name+".md") |
| 66 | |
| 67 | var b bytes.Buffer |
| 68 | if err := t.Execute(&b, table); err != nil { |
| 69 | return fmt.Errorf("failed to execute template: %v", err) |
| 70 | } |
| 71 | content := formatMarkdown(b.String()) |
| 72 | f, err := os.Create(outputPath) |
| 73 | if err != nil { |
| 74 | return fmt.Errorf("failed to create file %v: %v", outputPath, err) |
| 75 | } |
| 76 | defer f.Close() |
| 77 | f.WriteString(content) |
| 78 | return f.Close() |
| 79 | } |
| 80 | |
| 81 | func formatMarkdown(s string) string { |
| 82 | s = reMatchNewlines.ReplaceAllString(s, "\n\n") |
no test coverage detected