2021-10-16 03:58:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-10-16 14:21:05 +00:00
|
|
|
"path/filepath"
|
|
|
|
"go/ast"
|
2021-10-16 03:58:56 +00:00
|
|
|
"go/doc"
|
|
|
|
"go/parser"
|
|
|
|
"go/token"
|
2023-01-18 10:39:26 +00:00
|
|
|
"regexp"
|
2021-10-16 14:21:05 +00:00
|
|
|
"strings"
|
|
|
|
"os"
|
2022-12-15 04:00:54 +00:00
|
|
|
"sync"
|
2023-09-02 18:18:40 +00:00
|
|
|
|
|
|
|
md "github.com/atsushinee/go-markdown-generator/doc"
|
2021-10-16 03:58:56 +00:00
|
|
|
)
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
var header = `---
|
|
|
|
title: %s %s
|
|
|
|
description: %s
|
|
|
|
layout: doc
|
|
|
|
menu:
|
|
|
|
docs:
|
|
|
|
parent: "API"
|
|
|
|
---
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
type emmyPiece struct {
|
|
|
|
DocPiece *docPiece
|
|
|
|
Annotations []string
|
2022-02-25 22:00:18 +00:00
|
|
|
Params []string // we only need to know param name to put in function
|
2022-12-15 04:00:54 +00:00
|
|
|
FuncName string
|
|
|
|
}
|
|
|
|
|
|
|
|
type module struct {
|
2023-01-18 10:39:26 +00:00
|
|
|
Types []docPiece
|
2022-12-15 04:00:54 +00:00
|
|
|
Docs []docPiece
|
|
|
|
Fields []docPiece
|
|
|
|
Properties []docPiece
|
|
|
|
ShortDescription string
|
|
|
|
Description string
|
|
|
|
ParentModule string
|
|
|
|
HasInterfaces bool
|
2023-01-18 10:39:26 +00:00
|
|
|
HasTypes bool
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
|
2023-08-26 15:30:51 +00:00
|
|
|
type param struct{
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
Doc []string
|
|
|
|
}
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
type docPiece struct {
|
2022-02-25 22:00:18 +00:00
|
|
|
Doc []string
|
|
|
|
FuncSig string
|
|
|
|
FuncName string
|
2022-12-15 04:00:54 +00:00
|
|
|
Interfacing string
|
|
|
|
ParentModule string
|
|
|
|
GoFuncName string
|
|
|
|
IsInterface bool
|
|
|
|
IsMember bool
|
2023-01-18 10:39:26 +00:00
|
|
|
IsType bool
|
2022-12-15 04:00:54 +00:00
|
|
|
Fields []docPiece
|
|
|
|
Properties []docPiece
|
2023-08-26 15:30:51 +00:00
|
|
|
Params []param
|
2023-11-30 22:30:54 +00:00
|
|
|
Tags map[string][]tag
|
2022-12-15 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type tag struct {
|
|
|
|
id string
|
|
|
|
fields []string
|
2023-11-30 22:30:54 +00:00
|
|
|
startIdx int
|
2022-12-15 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var docs = make(map[string]module)
|
|
|
|
var interfaceDocs = make(map[string]module)
|
|
|
|
var emmyDocs = make(map[string][]emmyPiece)
|
2023-01-18 10:39:26 +00:00
|
|
|
var typeTable = make(map[string][]string) // [0] = parentMod, [1] = interfaces
|
2022-12-15 04:00:54 +00:00
|
|
|
var prefix = map[string]string{
|
|
|
|
"main": "hl",
|
|
|
|
"hilbish": "hl",
|
|
|
|
"fs": "f",
|
|
|
|
"commander": "c",
|
|
|
|
"bait": "b",
|
|
|
|
"terminal": "term",
|
|
|
|
}
|
|
|
|
|
|
|
|
func getTagsAndDocs(docs string) (map[string][]tag, []string) {
|
|
|
|
pts := strings.Split(docs, "\n")
|
|
|
|
parts := []string{}
|
|
|
|
tags := make(map[string][]tag)
|
|
|
|
|
2023-11-30 22:30:54 +00:00
|
|
|
for idx, part := range pts {
|
2022-12-15 04:00:54 +00:00
|
|
|
if strings.HasPrefix(part, "#") {
|
|
|
|
tagParts := strings.Split(strings.TrimPrefix(part, "#"), " ")
|
|
|
|
if tags[tagParts[0]] == nil {
|
|
|
|
var id string
|
|
|
|
if len(tagParts) > 1 {
|
|
|
|
id = tagParts[1]
|
|
|
|
}
|
|
|
|
tags[tagParts[0]] = []tag{
|
2023-11-30 22:30:54 +00:00
|
|
|
{id: id, startIdx: idx},
|
2022-12-15 04:00:54 +00:00
|
|
|
}
|
|
|
|
if len(tagParts) >= 2 {
|
|
|
|
tags[tagParts[0]][0].fields = tagParts[2:]
|
|
|
|
}
|
|
|
|
} else {
|
2023-11-30 22:30:54 +00:00
|
|
|
if tagParts[0] == "example" {
|
|
|
|
exampleIdx := tags["example"][0].startIdx
|
|
|
|
exampleCode := pts[exampleIdx+1:idx]
|
|
|
|
|
|
|
|
tags["example"][0].fields = exampleCode
|
|
|
|
parts = strings.Split(strings.Replace(strings.Join(parts, "\n"), strings.TrimPrefix(strings.Join(exampleCode, "\n"), "#example\n"), "", -1), "\n")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
fleds := []string{}
|
|
|
|
if len(tagParts) >= 2 {
|
|
|
|
fleds = tagParts[2:]
|
|
|
|
}
|
|
|
|
tags[tagParts[0]] = append(tags[tagParts[0]], tag{
|
|
|
|
id: tagParts[1],
|
|
|
|
fields: fleds,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parts = append(parts, part)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tags, parts
|
|
|
|
}
|
|
|
|
|
|
|
|
func docPieceTag(tagName string, tags map[string][]tag) []docPiece {
|
|
|
|
dps := []docPiece{}
|
|
|
|
for _, tag := range tags[tagName] {
|
|
|
|
dps = append(dps, docPiece{
|
|
|
|
FuncName: tag.id,
|
|
|
|
Doc: tag.fields,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return dps
|
|
|
|
}
|
|
|
|
|
2023-01-18 10:39:26 +00:00
|
|
|
func setupDocType(mod string, typ *doc.Type) *docPiece {
|
|
|
|
docs := strings.TrimSpace(typ.Doc)
|
2023-02-07 19:39:22 +00:00
|
|
|
tags, doc := getTagsAndDocs(docs)
|
|
|
|
|
|
|
|
if tags["type"] == nil {
|
2023-01-18 10:39:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-02-07 19:39:22 +00:00
|
|
|
inInterface := tags["interface"] != nil
|
2023-01-18 10:39:26 +00:00
|
|
|
|
|
|
|
var interfaces string
|
|
|
|
typeName := strings.ToUpper(string(typ.Name[0])) + typ.Name[1:]
|
|
|
|
typeDoc := []string{}
|
|
|
|
|
|
|
|
if inInterface {
|
|
|
|
interfaces = tags["interface"][0].id
|
|
|
|
}
|
|
|
|
|
|
|
|
fields := docPieceTag("field", tags)
|
|
|
|
properties := docPieceTag("property", tags)
|
|
|
|
|
|
|
|
for _, d := range doc {
|
|
|
|
if strings.HasPrefix(d, "---") {
|
|
|
|
// TODO: document types in lua
|
|
|
|
/*
|
|
|
|
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
|
|
|
emmyLinePieces := strings.Split(emmyLine, " ")
|
|
|
|
emmyType := emmyLinePieces[0]
|
|
|
|
if emmyType == "@param" {
|
|
|
|
em.Params = append(em.Params, emmyLinePieces[1])
|
|
|
|
}
|
|
|
|
if emmyType == "@vararg" {
|
|
|
|
em.Params = append(em.Params, "...") // add vararg
|
|
|
|
}
|
|
|
|
em.Annotations = append(em.Annotations, d)
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
typeDoc = append(typeDoc, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var isMember bool
|
|
|
|
if tags["member"] != nil {
|
|
|
|
isMember = true
|
|
|
|
}
|
2023-02-07 19:39:22 +00:00
|
|
|
parentMod := mod
|
2023-01-18 10:39:26 +00:00
|
|
|
dps := &docPiece{
|
|
|
|
Doc: typeDoc,
|
|
|
|
FuncName: typeName,
|
|
|
|
Interfacing: interfaces,
|
|
|
|
IsInterface: inInterface,
|
|
|
|
IsMember: isMember,
|
|
|
|
IsType: true,
|
|
|
|
ParentModule: parentMod,
|
|
|
|
Fields: fields,
|
|
|
|
Properties: properties,
|
2023-11-30 22:30:54 +00:00
|
|
|
Tags: tags,
|
2023-01-18 10:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typeTable[strings.ToLower(typeName)] = []string{parentMod, interfaces}
|
|
|
|
|
|
|
|
return dps
|
|
|
|
}
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
func setupDoc(mod string, fun *doc.Func) *docPiece {
|
|
|
|
docs := strings.TrimSpace(fun.Doc)
|
2023-02-07 19:39:22 +00:00
|
|
|
tags, parts := getTagsAndDocs(docs)
|
|
|
|
|
|
|
|
// i couldnt fit this into the condition below for some reason so here's a goto!
|
|
|
|
if tags["member"] != nil {
|
|
|
|
goto start
|
2022-12-15 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
2023-02-07 19:39:22 +00:00
|
|
|
if (!strings.HasPrefix(fun.Name, prefix[mod]) && tags["interface"] == nil) || (strings.ToLower(fun.Name) == "loader" && tags["interface"] == nil) {
|
|
|
|
return nil
|
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
|
2023-02-07 19:39:22 +00:00
|
|
|
start:
|
|
|
|
inInterface := tags["interface"] != nil
|
2022-12-15 04:00:54 +00:00
|
|
|
var interfaces string
|
|
|
|
funcsig := parts[0]
|
|
|
|
doc := parts[1:]
|
|
|
|
funcName := strings.TrimPrefix(fun.Name, prefix[mod])
|
|
|
|
funcdoc := []string{}
|
|
|
|
|
|
|
|
if inInterface {
|
|
|
|
interfaces = tags["interface"][0].id
|
|
|
|
funcName = interfaces + "." + strings.Split(funcsig, "(")[0]
|
|
|
|
}
|
|
|
|
em := emmyPiece{FuncName: funcName}
|
|
|
|
|
|
|
|
fields := docPieceTag("field", tags)
|
|
|
|
properties := docPieceTag("property", tags)
|
2023-08-26 15:30:51 +00:00
|
|
|
var params []param
|
|
|
|
if paramsRaw := tags["param"]; paramsRaw != nil {
|
|
|
|
params = make([]param, len(paramsRaw))
|
|
|
|
for i, p := range paramsRaw {
|
|
|
|
params[i] = param{
|
|
|
|
Name: p.id,
|
|
|
|
Type: p.fields[0],
|
|
|
|
Doc: p.fields[1:],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
for _, d := range doc {
|
|
|
|
if strings.HasPrefix(d, "---") {
|
|
|
|
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
|
|
|
emmyLinePieces := strings.Split(emmyLine, " ")
|
|
|
|
emmyType := emmyLinePieces[0]
|
|
|
|
if emmyType == "@param" {
|
|
|
|
em.Params = append(em.Params, emmyLinePieces[1])
|
|
|
|
}
|
|
|
|
if emmyType == "@vararg" {
|
|
|
|
em.Params = append(em.Params, "...") // add vararg
|
|
|
|
}
|
|
|
|
em.Annotations = append(em.Annotations, d)
|
|
|
|
} else {
|
|
|
|
funcdoc = append(funcdoc, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var isMember bool
|
|
|
|
if tags["member"] != nil {
|
|
|
|
isMember = true
|
|
|
|
}
|
|
|
|
var parentMod string
|
|
|
|
if inInterface {
|
|
|
|
parentMod = mod
|
|
|
|
}
|
|
|
|
dps := &docPiece{
|
|
|
|
Doc: funcdoc,
|
|
|
|
FuncSig: funcsig,
|
|
|
|
FuncName: funcName,
|
|
|
|
Interfacing: interfaces,
|
|
|
|
GoFuncName: strings.ToLower(fun.Name),
|
|
|
|
IsInterface: inInterface,
|
|
|
|
IsMember: isMember,
|
|
|
|
ParentModule: parentMod,
|
|
|
|
Fields: fields,
|
|
|
|
Properties: properties,
|
2023-08-26 15:30:51 +00:00
|
|
|
Params: params,
|
2023-11-30 22:30:54 +00:00
|
|
|
Tags: tags,
|
2022-12-15 04:00:54 +00:00
|
|
|
}
|
|
|
|
if strings.HasSuffix(dps.GoFuncName, strings.ToLower("loader")) {
|
|
|
|
dps.Doc = parts
|
|
|
|
}
|
|
|
|
em.DocPiece = dps
|
|
|
|
|
|
|
|
emmyDocs[mod] = append(emmyDocs[mod], em)
|
|
|
|
return dps
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 03:58:56 +00:00
|
|
|
func main() {
|
|
|
|
fset := token.NewFileSet()
|
2022-02-25 22:00:18 +00:00
|
|
|
os.Mkdir("docs", 0777)
|
2022-12-15 04:00:54 +00:00
|
|
|
os.Mkdir("docs/api", 0777)
|
2022-02-25 22:00:18 +00:00
|
|
|
os.Mkdir("emmyLuaDocs", 0777)
|
2021-10-16 03:58:56 +00:00
|
|
|
|
2021-10-16 14:21:05 +00:00
|
|
|
dirs := []string{"./"}
|
|
|
|
filepath.Walk("golibs/", func (path string, info os.FileInfo, err error) error {
|
|
|
|
if !info.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
dirs = append(dirs, "./" + path)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
pkgs := make(map[string]*ast.Package)
|
|
|
|
for _, path := range dirs {
|
|
|
|
d, err := parser.ParseDir(fset, path, nil, parser.ParseComments)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for k, v := range d {
|
|
|
|
pkgs[k] = v
|
|
|
|
}
|
2021-10-16 03:58:56 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
interfaceModules := make(map[string]*module)
|
2021-10-16 14:21:05 +00:00
|
|
|
for l, f := range pkgs {
|
|
|
|
p := doc.New(f, "./", doc.AllDecls)
|
2022-12-15 04:00:54 +00:00
|
|
|
pieces := []docPiece{}
|
2023-01-18 10:39:26 +00:00
|
|
|
typePieces := []docPiece{}
|
2022-12-15 04:00:54 +00:00
|
|
|
mod := l
|
|
|
|
if mod == "main" {
|
|
|
|
mod = "hilbish"
|
|
|
|
}
|
|
|
|
var hasInterfaces bool
|
2021-10-16 03:58:56 +00:00
|
|
|
for _, t := range p.Funcs {
|
2022-12-15 04:00:54 +00:00
|
|
|
piece := setupDoc(mod, t)
|
|
|
|
if piece == nil {
|
|
|
|
continue
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
pieces = append(pieces, *piece)
|
|
|
|
if piece.IsInterface {
|
|
|
|
hasInterfaces = true
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2021-10-16 14:21:05 +00:00
|
|
|
}
|
|
|
|
for _, t := range p.Types {
|
2023-01-18 10:39:26 +00:00
|
|
|
typePiece := setupDocType(mod, t)
|
|
|
|
if typePiece != nil {
|
|
|
|
typePieces = append(typePieces, *typePiece)
|
|
|
|
if typePiece.IsInterface {
|
|
|
|
hasInterfaces = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-16 14:21:05 +00:00
|
|
|
for _, m := range t.Methods {
|
2022-12-15 04:00:54 +00:00
|
|
|
piece := setupDoc(mod, m)
|
|
|
|
if piece == nil {
|
|
|
|
continue
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
pieces = append(pieces, *piece)
|
|
|
|
if piece.IsInterface {
|
|
|
|
hasInterfaces = true
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tags, descParts := getTagsAndDocs(strings.TrimSpace(p.Doc))
|
|
|
|
shortDesc := descParts[0]
|
|
|
|
desc := descParts[1:]
|
|
|
|
filteredPieces := []docPiece{}
|
2023-01-18 10:39:26 +00:00
|
|
|
filteredTypePieces := []docPiece{}
|
2022-12-15 04:00:54 +00:00
|
|
|
for _, piece := range pieces {
|
|
|
|
if !piece.IsInterface {
|
|
|
|
filteredPieces = append(filteredPieces, piece)
|
|
|
|
continue
|
|
|
|
}
|
2021-10-16 14:21:05 +00:00
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
modname := piece.ParentModule + "." + piece.Interfacing
|
|
|
|
if interfaceModules[modname] == nil {
|
|
|
|
interfaceModules[modname] = &module{
|
|
|
|
ParentModule: piece.ParentModule,
|
|
|
|
}
|
2021-10-16 14:21:05 +00:00
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
if strings.HasSuffix(piece.GoFuncName, strings.ToLower("loader")) {
|
|
|
|
shortDesc := piece.Doc[0]
|
|
|
|
desc := piece.Doc[1:]
|
|
|
|
interfaceModules[modname].ShortDescription = shortDesc
|
|
|
|
interfaceModules[modname].Description = strings.Join(desc, "\n")
|
|
|
|
interfaceModules[modname].Fields = piece.Fields
|
|
|
|
interfaceModules[modname].Properties = piece.Properties
|
|
|
|
continue
|
|
|
|
}
|
2023-01-18 10:39:26 +00:00
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
interfaceModules[modname].Docs = append(interfaceModules[modname].Docs, piece)
|
|
|
|
}
|
|
|
|
|
2023-01-18 10:39:26 +00:00
|
|
|
for _, piece := range typePieces {
|
|
|
|
if !piece.IsInterface {
|
|
|
|
filteredTypePieces = append(filteredTypePieces, piece)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
modname := piece.ParentModule + "." + piece.Interfacing
|
|
|
|
if interfaceModules[modname] == nil {
|
|
|
|
interfaceModules[modname] = &module{
|
|
|
|
ParentModule: piece.ParentModule,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interfaceModules[modname].Types = append(interfaceModules[modname].Types, piece)
|
|
|
|
}
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
docs[mod] = module{
|
2023-01-18 10:39:26 +00:00
|
|
|
Types: filteredTypePieces,
|
2022-12-15 04:00:54 +00:00
|
|
|
Docs: filteredPieces,
|
|
|
|
ShortDescription: shortDesc,
|
|
|
|
Description: strings.Join(desc, "\n"),
|
|
|
|
HasInterfaces: hasInterfaces,
|
|
|
|
Properties: docPieceTag("property", tags),
|
|
|
|
Fields: docPieceTag("field", tags),
|
2021-10-16 03:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-16 16:38:46 +00:00
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
for key, mod := range interfaceModules {
|
|
|
|
docs[key] = *mod
|
|
|
|
}
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(len(docs) * 2)
|
|
|
|
|
2021-10-16 16:38:46 +00:00
|
|
|
for mod, v := range docs {
|
2022-12-15 04:00:54 +00:00
|
|
|
docPath := "docs/api/" + mod + ".md"
|
|
|
|
if v.HasInterfaces {
|
|
|
|
os.Mkdir("docs/api/" + mod, 0777)
|
|
|
|
os.Remove(docPath) // remove old doc path if it exists
|
|
|
|
docPath = "docs/api/" + mod + "/_index.md"
|
|
|
|
}
|
|
|
|
if v.ParentModule != "" {
|
|
|
|
docPath = "docs/api/" + v.ParentModule + "/" + mod + ".md"
|
|
|
|
}
|
|
|
|
|
|
|
|
go func(modname, docPath string, modu module) {
|
|
|
|
defer wg.Done()
|
|
|
|
modOrIface := "Module"
|
|
|
|
if modu.ParentModule != "" {
|
2023-08-26 15:30:51 +00:00
|
|
|
modOrIface = "Module"
|
2022-12-15 04:00:54 +00:00
|
|
|
}
|
2023-09-09 17:38:54 +00:00
|
|
|
lastHeader := ""
|
2022-12-15 04:00:54 +00:00
|
|
|
|
|
|
|
f, _ := os.Create(docPath)
|
|
|
|
f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription))
|
2023-11-12 00:39:31 +00:00
|
|
|
typeTag, _ := regexp.Compile(`\B@\w+`)
|
2023-09-02 16:57:13 +00:00
|
|
|
modDescription := typeTag.ReplaceAllStringFunc(strings.Replace(strings.Replace(modu.Description, "<", `\<`, -1), "{{\\<", "{{<", -1), func(typ string) string {
|
2023-01-20 23:07:42 +00:00
|
|
|
typName := typ[1:]
|
|
|
|
typLookup := typeTable[strings.ToLower(typName)]
|
2023-02-07 19:39:22 +00:00
|
|
|
ifaces := typLookup[0] + "." + typLookup[1] + "/"
|
|
|
|
if typLookup[1] == "" {
|
|
|
|
ifaces = ""
|
|
|
|
}
|
|
|
|
linkedTyp := fmt.Sprintf("/Hilbish/docs/api/%s/%s#%s", typLookup[0], ifaces, strings.ToLower(typName))
|
2023-01-20 23:07:42 +00:00
|
|
|
return fmt.Sprintf(`<a href="%s" style="text-decoration: none;">%s</a>`, linkedTyp, typName)
|
|
|
|
})
|
|
|
|
f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n", modDescription))
|
2023-09-02 18:18:40 +00:00
|
|
|
if len(modu.Docs) != 0 {
|
|
|
|
funcCount := 0
|
|
|
|
for _, dps := range modu.Docs {
|
|
|
|
if dps.IsMember {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
funcCount++
|
|
|
|
}
|
|
|
|
|
|
|
|
f.WriteString("## Functions\n")
|
2023-09-09 17:38:54 +00:00
|
|
|
lastHeader = "functions"
|
2023-09-02 18:18:40 +00:00
|
|
|
|
|
|
|
mdTable := md.NewTable(funcCount, 2)
|
|
|
|
mdTable.SetTitle(0, "")
|
|
|
|
mdTable.SetTitle(1, "")
|
|
|
|
|
|
|
|
diff := 0
|
|
|
|
for i, dps := range modu.Docs {
|
|
|
|
if dps.IsMember {
|
|
|
|
diff++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
mdTable.SetContent(i - diff, 0, fmt.Sprintf(`<a href="#%s">%s</a>`, dps.FuncName, dps.FuncSig))
|
|
|
|
mdTable.SetContent(i - diff, 1, dps.Doc[0])
|
|
|
|
}
|
|
|
|
f.WriteString(mdTable.String())
|
|
|
|
f.WriteString("\n")
|
|
|
|
}
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
if len(modu.Fields) != 0 {
|
2023-09-02 20:11:57 +00:00
|
|
|
f.WriteString("## Static module fields\n")
|
2023-09-02 20:01:57 +00:00
|
|
|
|
|
|
|
mdTable := md.NewTable(len(modu.Fields), 2)
|
|
|
|
mdTable.SetTitle(0, "")
|
|
|
|
mdTable.SetTitle(1, "")
|
|
|
|
|
|
|
|
|
|
|
|
for i, dps := range modu.Fields {
|
|
|
|
mdTable.SetContent(i, 0, dps.FuncName)
|
|
|
|
mdTable.SetContent(i, 1, strings.Join(dps.Doc, " "))
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2023-09-02 20:01:57 +00:00
|
|
|
f.WriteString(mdTable.String())
|
2022-12-15 04:00:54 +00:00
|
|
|
f.WriteString("\n")
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
if len(modu.Properties) != 0 {
|
|
|
|
f.WriteString("## Object properties\n")
|
2023-09-02 20:11:57 +00:00
|
|
|
|
|
|
|
mdTable := md.NewTable(len(modu.Fields), 2)
|
|
|
|
mdTable.SetTitle(0, "")
|
|
|
|
mdTable.SetTitle(1, "")
|
|
|
|
|
|
|
|
|
|
|
|
for i, dps := range modu.Properties {
|
|
|
|
mdTable.SetContent(i, 0, dps.FuncName)
|
|
|
|
mdTable.SetContent(i, 1, strings.Join(dps.Doc, " "))
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2023-09-02 20:11:57 +00:00
|
|
|
f.WriteString(mdTable.String())
|
2022-12-15 04:00:54 +00:00
|
|
|
f.WriteString("\n")
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2023-01-18 10:39:26 +00:00
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
if len(modu.Docs) != 0 {
|
2023-09-09 17:38:54 +00:00
|
|
|
if lastHeader != "functions" {
|
|
|
|
f.WriteString("## Functions\n")
|
|
|
|
}
|
2023-01-18 10:39:26 +00:00
|
|
|
for _, dps := range modu.Docs {
|
|
|
|
if dps.IsMember {
|
|
|
|
continue
|
|
|
|
}
|
2023-09-02 20:01:57 +00:00
|
|
|
f.WriteString(fmt.Sprintf("<hr><div id='%s'>", dps.FuncName))
|
2023-08-26 15:30:51 +00:00
|
|
|
htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(modname + "." + dps.FuncSig, "<", `\<`, -1), func(typ string) string {
|
2023-01-18 10:39:26 +00:00
|
|
|
typName := typ[1:]
|
|
|
|
typLookup := typeTable[strings.ToLower(typName)]
|
2023-02-07 19:39:22 +00:00
|
|
|
ifaces := typLookup[0] + "." + typLookup[1] + "/"
|
|
|
|
if typLookup[1] == "" {
|
|
|
|
ifaces = ""
|
|
|
|
}
|
|
|
|
linkedTyp := fmt.Sprintf("/Hilbish/docs/api/%s/%s#%s", typLookup[0], ifaces, strings.ToLower(typName))
|
2023-08-26 15:30:51 +00:00
|
|
|
return fmt.Sprintf(`<a href="%s" style="text-decoration: none;" id="lol">%s</a>`, linkedTyp, typName)
|
2023-01-18 10:39:26 +00:00
|
|
|
})
|
2023-09-02 18:18:40 +00:00
|
|
|
f.WriteString(fmt.Sprintf(`
|
|
|
|
<h4 class='heading'>
|
|
|
|
%s
|
|
|
|
<a href="#%s" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
|
|
|
|
|
|
|
`, htmlSig, dps.FuncName))
|
2023-01-18 10:39:26 +00:00
|
|
|
for _, doc := range dps.Doc {
|
|
|
|
if !strings.HasPrefix(doc, "---") {
|
2023-12-02 12:22:40 +00:00
|
|
|
f.WriteString(doc + " \n")
|
2023-01-18 10:39:26 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-26 15:30:51 +00:00
|
|
|
f.WriteString("#### Parameters\n")
|
|
|
|
if len(dps.Params) == 0 {
|
|
|
|
f.WriteString("This function has no parameters. \n")
|
|
|
|
}
|
|
|
|
for _, p := range dps.Params {
|
|
|
|
isVariadic := false
|
|
|
|
typ := p.Type
|
|
|
|
if strings.HasPrefix(p.Type, "...") {
|
|
|
|
isVariadic = true
|
|
|
|
typ = p.Type[3:]
|
|
|
|
}
|
|
|
|
|
|
|
|
f.WriteString(fmt.Sprintf("`%s` **`%s`**", typ, p.Name))
|
|
|
|
if isVariadic {
|
|
|
|
f.WriteString(" (This type is variadic. You can pass an infinite amount of parameters with this type.)")
|
|
|
|
}
|
|
|
|
f.WriteString(" \n")
|
|
|
|
f.WriteString(strings.Join(p.Doc, " "))
|
|
|
|
f.WriteString("\n\n")
|
|
|
|
}
|
2023-11-30 22:30:54 +00:00
|
|
|
if codeExample := dps.Tags["example"]; codeExample != nil {
|
|
|
|
f.WriteString("#### Example\n")
|
|
|
|
f.WriteString(fmt.Sprintf("```lua\n%s\n````\n", strings.Join(codeExample[0].fields, "\n")))
|
|
|
|
}
|
2023-09-02 18:18:40 +00:00
|
|
|
f.WriteString("</div>")
|
2023-09-02 20:01:57 +00:00
|
|
|
f.WriteString("\n\n")
|
2023-01-18 10:39:26 +00:00
|
|
|
}
|
2022-02-25 22:00:18 +00:00
|
|
|
}
|
2023-01-18 10:39:26 +00:00
|
|
|
|
|
|
|
if len(modu.Types) != 0 {
|
|
|
|
f.WriteString("## Types\n")
|
|
|
|
for _, dps := range modu.Types {
|
2023-09-02 20:11:57 +00:00
|
|
|
f.WriteString("<hr>\n\n")
|
2023-01-18 10:39:26 +00:00
|
|
|
f.WriteString(fmt.Sprintf("## %s\n", dps.FuncName))
|
|
|
|
for _, doc := range dps.Doc {
|
|
|
|
if !strings.HasPrefix(doc, "---") {
|
|
|
|
f.WriteString(doc + "\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(dps.Properties) != 0 {
|
2023-09-02 20:11:57 +00:00
|
|
|
f.WriteString("## Object properties\n")
|
|
|
|
|
|
|
|
mdTable := md.NewTable(len(dps.Properties), 2)
|
|
|
|
mdTable.SetTitle(0, "")
|
|
|
|
mdTable.SetTitle(1, "")
|
|
|
|
|
|
|
|
for i, d := range dps.Properties {
|
|
|
|
mdTable.SetContent(i, 0, d.FuncName)
|
|
|
|
mdTable.SetContent(i, 1, strings.Join(d.Doc, " "))
|
2023-01-18 10:39:26 +00:00
|
|
|
}
|
2023-09-02 20:11:57 +00:00
|
|
|
f.WriteString(mdTable.String())
|
|
|
|
f.WriteString("\n")
|
2023-01-18 10:39:26 +00:00
|
|
|
}
|
|
|
|
f.WriteString("\n")
|
|
|
|
f.WriteString("### Methods\n")
|
|
|
|
for _, dps := range modu.Docs {
|
|
|
|
if !dps.IsMember {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(dps.FuncSig, "<", `\<`, -1), func(typ string) string {
|
2023-02-07 19:39:22 +00:00
|
|
|
typName := regexp.MustCompile(`\w+`).FindString(typ[1:])
|
|
|
|
typLookup := typeTable[strings.ToLower(typName)]
|
|
|
|
fmt.Printf("%+q, \n", typLookup)
|
|
|
|
linkedTyp := fmt.Sprintf("/Hilbish/docs/api/%s/%s/#%s", typLookup[0], typLookup[0] + "." + typLookup[1], strings.ToLower(typName))
|
2023-01-18 10:39:26 +00:00
|
|
|
return fmt.Sprintf(`<a href="#%s" style="text-decoration: none;">%s</a>`, linkedTyp, typName)
|
|
|
|
})
|
|
|
|
f.WriteString(fmt.Sprintf("#### %s\n", htmlSig))
|
|
|
|
for _, doc := range dps.Doc {
|
|
|
|
if !strings.HasPrefix(doc, "---") {
|
|
|
|
f.WriteString(doc + "\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f.WriteString("\n")
|
2022-12-15 04:00:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}(mod, docPath, v)
|
|
|
|
|
|
|
|
go func(md, modname string, modu module) {
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
if modu.ParentModule != "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ff, _ := os.Create("emmyLuaDocs/" + modname + ".lua")
|
|
|
|
ff.WriteString("--- @meta\n\nlocal " + modname + " = {}\n\n")
|
|
|
|
for _, em := range emmyDocs[modname] {
|
|
|
|
if strings.HasSuffix(em.DocPiece.GoFuncName, strings.ToLower("loader")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
dps := em.DocPiece
|
|
|
|
funcdocs := dps.Doc
|
|
|
|
ff.WriteString("--- " + strings.Join(funcdocs, "\n--- ") + "\n")
|
|
|
|
if len(em.Annotations) != 0 {
|
|
|
|
ff.WriteString(strings.Join(em.Annotations, "\n") + "\n")
|
|
|
|
}
|
|
|
|
accessor := "."
|
|
|
|
if dps.IsMember {
|
|
|
|
accessor = ":"
|
|
|
|
}
|
|
|
|
signature := strings.Split(dps.FuncSig, " ->")[0]
|
|
|
|
var intrface string
|
|
|
|
if dps.IsInterface {
|
|
|
|
intrface = "." + dps.Interfacing
|
|
|
|
}
|
|
|
|
ff.WriteString("function " + modname + intrface + accessor + signature + " end\n\n")
|
|
|
|
}
|
|
|
|
ff.WriteString("return " + modname + "\n")
|
|
|
|
}(mod, mod, v)
|
2021-10-16 16:38:46 +00:00
|
|
|
}
|
2022-12-15 04:00:54 +00:00
|
|
|
wg.Wait()
|
2021-10-16 03:58:56 +00:00
|
|
|
}
|