Improved API documentation

This commit is contained in:
2018-04-12 23:05:24 +02:00
parent c60c171a2f
commit ea2e08d88d
3 changed files with 25 additions and 11 deletions

View File

@ -1,22 +1,37 @@
package apiview
import (
"path"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/arn/autodocs"
"github.com/animenotifier/notify.moe/components"
"github.com/fatih/color"
)
// Get api page.
func Get(ctx *aero.Context) string {
types := []string{}
types := []*autodocs.Type{}
for typeName := range arn.DB.Types() {
types = append(types, typeName)
if typeName == "Session" {
continue
}
typ, err := autodocs.GetTypeDocumentation(typeName, path.Join(arn.Root, "..", "arn", typeName+".go"))
types = append(types, typ)
if err != nil {
color.Red(err.Error())
continue
}
}
sort.Strings(types)
sort.Slice(types, func(i, j int) bool {
return types[i].Name < types[j].Name
})
return ctx.HTML(components.API(types))
}