mirror of https://github.com/Hilbis/Hilbish
docs: add ability to document properties (and document hilbish.userDir)
parent
bb8045dd38
commit
9e2d77d138
5
api.go
5
api.go
|
@ -114,10 +114,7 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
util.Document(fakeMod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")
|
util.Document(fakeMod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")
|
||||||
|
|
||||||
// hilbish.userDir table
|
// hilbish.userDir table
|
||||||
hshuser := rt.NewTable()
|
hshuser := userDirLoader(rtm)
|
||||||
|
|
||||||
util.SetField(rtm, hshuser, "config", rt.StringValue(confDir), "User's config directory")
|
|
||||||
util.SetField(rtm, hshuser, "data", rt.StringValue(userDataDir), "XDG data directory")
|
|
||||||
util.Document(hshuser, "User directories to store configs and/or modules.")
|
util.Document(hshuser, "User directories to store configs and/or modules.")
|
||||||
mod.Set(rt.StringValue("userDir"), rt.TableValue(hshuser))
|
mod.Set(rt.StringValue("userDir"), rt.TableValue(hshuser))
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ type emmyPiece struct {
|
||||||
|
|
||||||
type module struct {
|
type module struct {
|
||||||
Docs []docPiece
|
Docs []docPiece
|
||||||
|
Properties []docPiece
|
||||||
ShortDescription string
|
ShortDescription string
|
||||||
Description string
|
Description string
|
||||||
ParentModule string
|
ParentModule string
|
||||||
|
@ -44,6 +45,12 @@ type docPiece struct {
|
||||||
GoFuncName string
|
GoFuncName string
|
||||||
IsInterface bool
|
IsInterface bool
|
||||||
IsMember bool
|
IsMember bool
|
||||||
|
Properties []docPiece
|
||||||
|
}
|
||||||
|
|
||||||
|
type tag struct {
|
||||||
|
id string
|
||||||
|
fields []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var docs = make(map[string]module)
|
var docs = make(map[string]module)
|
||||||
|
@ -67,11 +74,31 @@ func setupDoc(mod string, fun *doc.Func) *docPiece {
|
||||||
|
|
||||||
pts := strings.Split(docs, "\n")
|
pts := strings.Split(docs, "\n")
|
||||||
parts := []string{}
|
parts := []string{}
|
||||||
tags := make(map[string][]string)
|
tags := make(map[string][]tag)
|
||||||
for _, part := range pts {
|
for _, part := range pts {
|
||||||
if strings.HasPrefix(part, "#") {
|
if strings.HasPrefix(part, "#") {
|
||||||
tagParts := strings.Split(strings.TrimPrefix(part, "#"), " ")
|
tagParts := strings.Split(strings.TrimPrefix(part, "#"), " ")
|
||||||
tags[tagParts[0]] = tagParts[1:]
|
if tags[tagParts[0]] == nil {
|
||||||
|
var id string
|
||||||
|
if len(tagParts) > 1 {
|
||||||
|
id = tagParts[1]
|
||||||
|
}
|
||||||
|
tags[tagParts[0]] = []tag{
|
||||||
|
{id: id},
|
||||||
|
}
|
||||||
|
if len(tagParts) >= 2 {
|
||||||
|
tags[tagParts[0]][0].fields = tagParts[2:]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fleds := []string{}
|
||||||
|
if len(tagParts) >= 2 {
|
||||||
|
fleds = tagParts[2:]
|
||||||
|
}
|
||||||
|
tags[tagParts[0]] = append(tags[tagParts[0]], tag{
|
||||||
|
id: tagParts[1],
|
||||||
|
fields: fleds,
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
parts = append(parts, part)
|
parts = append(parts, part)
|
||||||
}
|
}
|
||||||
|
@ -84,11 +111,20 @@ func setupDoc(mod string, fun *doc.Func) *docPiece {
|
||||||
funcdoc := []string{}
|
funcdoc := []string{}
|
||||||
|
|
||||||
if inInterface {
|
if inInterface {
|
||||||
interfaces = tags["interface"][0]
|
interfaces = tags["interface"][0].id
|
||||||
funcName = interfaces + "." + strings.Split(funcsig, "(")[0]
|
funcName = interfaces + "." + strings.Split(funcsig, "(")[0]
|
||||||
}
|
}
|
||||||
em := emmyPiece{FuncName: funcName}
|
em := emmyPiece{FuncName: funcName}
|
||||||
|
|
||||||
|
// manage properties
|
||||||
|
properties := []docPiece{}
|
||||||
|
for _, tag := range tags["property"] {
|
||||||
|
properties = append(properties, docPiece{
|
||||||
|
FuncName: tag.id,
|
||||||
|
Doc: tag.fields,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
for _, d := range doc {
|
for _, d := range doc {
|
||||||
if strings.HasPrefix(d, "---") {
|
if strings.HasPrefix(d, "---") {
|
||||||
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
||||||
|
@ -123,6 +159,7 @@ func setupDoc(mod string, fun *doc.Func) *docPiece {
|
||||||
IsInterface: inInterface,
|
IsInterface: inInterface,
|
||||||
IsMember: isMember,
|
IsMember: isMember,
|
||||||
ParentModule: parentMod,
|
ParentModule: parentMod,
|
||||||
|
Properties: properties,
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(dps.GoFuncName, strings.ToLower("loader")) {
|
if strings.HasSuffix(dps.GoFuncName, strings.ToLower("loader")) {
|
||||||
dps.Doc = parts
|
dps.Doc = parts
|
||||||
|
@ -216,6 +253,7 @@ func main() {
|
||||||
desc := piece.Doc[1:]
|
desc := piece.Doc[1:]
|
||||||
interfaceModules[modname].ShortDescription = shortDesc
|
interfaceModules[modname].ShortDescription = shortDesc
|
||||||
interfaceModules[modname].Description = strings.Join(desc, "\n")
|
interfaceModules[modname].Description = strings.Join(desc, "\n")
|
||||||
|
interfaceModules[modname].Properties = piece.Properties
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
interfaceModules[modname].Docs = append(interfaceModules[modname].Docs, piece)
|
interfaceModules[modname].Docs = append(interfaceModules[modname].Docs, piece)
|
||||||
|
@ -256,7 +294,18 @@ func main() {
|
||||||
|
|
||||||
f, _ := os.Create(docPath)
|
f, _ := os.Create(docPath)
|
||||||
f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription))
|
f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription))
|
||||||
f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n## Functions\n", modu.Description))
|
f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n", modu.Description))
|
||||||
|
if len(modu.Properties) != 0 {
|
||||||
|
f.WriteString("## Properties\n")
|
||||||
|
for _, dps := range modu.Properties {
|
||||||
|
f.WriteString(fmt.Sprintf("- `%s`: ", dps.FuncName))
|
||||||
|
f.WriteString(strings.Join(dps.Doc, " "))
|
||||||
|
f.WriteString("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(modu.Docs) != 0 {
|
||||||
|
f.WriteString("## Functions\n")
|
||||||
|
}
|
||||||
for _, dps := range modu.Docs {
|
for _, dps := range modu.Docs {
|
||||||
f.WriteString(fmt.Sprintf("### %s\n", dps.FuncSig))
|
f.WriteString(fmt.Sprintf("### %s\n", dps.FuncSig))
|
||||||
for _, doc := range dps.Doc {
|
for _, doc := range dps.Doc {
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"hilbish/util"
|
||||||
|
|
||||||
|
rt "github.com/arnodel/golua/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// #interface userDir
|
||||||
|
// user-related directories
|
||||||
|
// This interface just contains properties to know about certain user directories.
|
||||||
|
// It is equivalent to XDG on Linux and gets the user's preferred directories
|
||||||
|
// for configs and data.
|
||||||
|
// #property config The user's config directory
|
||||||
|
// #property data The user's directory for program data
|
||||||
|
func userDirLoader(rtm *rt.Runtime) *rt.Table {
|
||||||
|
mod := rt.NewTable()
|
||||||
|
|
||||||
|
util.SetField(rtm, mod, "config", rt.StringValue(confDir), "User's config directory")
|
||||||
|
util.SetField(rtm, mod, "data", rt.StringValue(userDataDir), "XDG data directory")
|
||||||
|
|
||||||
|
return mod
|
||||||
|
}
|
Loading…
Reference in New Issue