{{range .Preamble}}
{{. | markupPipeWords}}
{{end}}
{{range .Sections}}
{{if not .IsPrivate}}
{{if .Anchor}}{{end}}
{{range .Decls}}
{{if .Anchor}}- {{.Name}}
{{end}}
{{end}}
{{end}}
{{end}}
{{range .Sections}}
{{if not .IsPrivate}}
{{if .Preamble}}
{{range .Preamble}}
{{. | markupPipeWords}}
{{end}}
{{end}}
{{range .Decls}}
{{range .Comment}}
{{. | markupPipeWords | newlinesToBR | markupFirstWord}}
{{end}}
{{.Decl}}
{{end}}
{{end}}
{{end}}
`)
if err != nil {
return nil, err
}
headerDescriptions := make(map[string]string)
var headers []*HeaderFile
for _, section := range config.Sections {
for _, headerPath := range section.Headers {
header, err := config.parseHeader(headerPath)
if err != nil {
return nil, errors.New("while parsing " + headerPath + ": " + err.Error())
}
headerDescriptions[header.Name] = firstSentence(header.Preamble)
headers = append(headers, header)
for name, anchor := range header.AllDecls {
allDecls[name] = fmt.Sprintf("%s#%s", header.Name+".html", anchor)
}
}
}
for _, header := range headers {
filename := filepath.Join(outPath, header.Name+".html")
file, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
if err != nil {
panic(err)
}
defer file.Close()
if err := headerTmpl.Execute(file, header); err != nil {
return nil, err
}
}
return headerDescriptions, nil
}
func generateIndex(outPath string, config *Config, headerDescriptions map[string]string) error {
indexTmpl := template.New("indexTmpl")
indexTmpl.Funcs(template.FuncMap{
"baseName": filepath.Base,
"headerDescription": func(header string) string {
return headerDescriptions[header]
},
})
indexTmpl, err := indexTmpl.Parse(`