String renders the summary using the provided template.
(summaryTemplate string)
| 104 | |
| 105 | // String renders the summary using the provided template. |
| 106 | func (s summary) String(summaryTemplate string) (string, error) { |
| 107 | var tmpl *template.Template |
| 108 | var err error |
| 109 | |
| 110 | if summaryTemplate != "" { |
| 111 | tmpl, err = template. |
| 112 | New(filepath.Base(summaryTemplate)). |
| 113 | Funcs(TemplateFuncMap()). |
| 114 | Option("missingkey=error"). |
| 115 | ParseFiles(summaryTemplate) |
| 116 | } else { |
| 117 | tmpl, err = template. |
| 118 | New("summary.tmpl"). |
| 119 | Funcs(TemplateFuncMap()). |
| 120 | Option("missingkey=error"). |
| 121 | Parse(string(defaultTmpl)) |
| 122 | } |
| 123 | if err != nil { |
| 124 | return "", err |
| 125 | } |
| 126 | |
| 127 | buf := bytes.Buffer{} |
| 128 | if err := tmpl.Execute(&buf, s); err != nil { |
| 129 | return "", fmt.Errorf("failed executing template: %w", err) |
| 130 | } |
| 131 | |
| 132 | return buf.String(), nil |
| 133 | } |