Описание таблиц без ссылок в едином файле

This commit is contained in:
ymnuk 2023-11-07 19:59:05 +03:00
parent c5572183fe
commit d1bfaccc64
12 changed files with 99 additions and 4 deletions

5
.vscode/launch.json vendored
View File

@ -62,7 +62,10 @@
"--metafile",
"/home/ymnuk/projects/zmap/zmap.yml",
"--outdir-doc",
"../zmap/docs"
"../zmap/docs",
"--single-doc",
"--format-markdown",
"--format-html"
]
}
]

3
go.mod
View File

@ -5,12 +5,13 @@ go 1.21
require (
github.com/alexflint/go-arg v1.4.3
github.com/creasty/defaults v1.7.0
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386
github.com/satori/go.uuid v1.2.0
github.com/yuzutech/kroki-go v0.8.1
gopkg.in/yaml.v3 v3.0.1
)
require (
github.com/alexflint/go-scalar v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/yuzutech/kroki-go v0.8.1 // indirect
)

2
go.sum
View File

@ -8,6 +8,8 @@ github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdB
github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386 h1:EcQR3gusLHN46TAD+G+EbaaqJArt5vHhNpXAa12PQf4=
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

View File

@ -1,6 +1,8 @@
package lib
import (
"text/template"
"git.ymnuktech.ru/ymnuk/yt-gen-app/lib/templ"
"git.ymnuktech.ru/ymnuk/yt-gen-app/structs"
"github.com/yuzutech/kroki-go"
@ -12,6 +14,33 @@ func Documentation() {
}
// Генерация общей схемы БД
fullDocDBGen()
var err error
var tmpl *template.Template
var out []byte
if AppConfig.IsSingleDoc {
if tmpl, err = templ.ReadTmplFile("tmpl/docs/single-index.tmpl"); err != nil {
panic(err)
}
if out, err = templ.ExecuteTmplFile(tmpl, Project); err != nil {
panic(err)
}
if AppConfig.IsMarkdown {
if err = templ.WriteFile(AppConfig.OutdirDoc+"/index.md", out); err != nil {
panic(err)
}
}
if AppConfig.IsHtml {
var buff []byte
if buff, err = templ.Content.ReadFile("tmpl/docs/styles.tmpl"); err != nil {
panic(err)
}
//{{ includeTemplPart "tmpl/docs/styles.tmpl" nil }}
out = append(buff, out...)
if err = templ.WriteFile(AppConfig.OutdirDoc+"/index.html", mdToHTML(out)); err != nil {
panic(err)
}
}
}
// Генерация каждой таблицы по отдельности с прилегающими ближайшими таблицами
/*for i := range Project.DB.Tables {
docDBGen(Project.DB.Tables[i])
@ -39,13 +68,13 @@ func fullDocDBGen() {
panic(err)
} else {
//fmt.Println(string(buff))
templ.WriteFile(AppConfig.OutdirDoc+"/test.txt", buff)
//templ.WriteFile(AppConfig.OutdirDoc+"/test.txt", buff)
client := NewKrokiClient()
if result, err := client.FromString(string(buff), "dbml", kroki.SVG); err != nil {
panic(err)
} else {
//fmt.Println(result)
templ.WriteFile(AppConfig.OutdirDoc+"/test.svg", []byte(result))
templ.WriteFile(AppConfig.OutdirDoc+"/full-schemadb.svg", []byte(result))
}
}

21
lib/md2html.go Normal file
View File

@ -0,0 +1,21 @@
package lib
import (
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
)
func mdToHTML(md []byte) []byte {
// create markdown parser with extensions
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
p := parser.NewWithExtensions(extensions)
doc := p.Parse(md)
// create HTML renderer with extensions
htmlFlags := html.CommonFlags | html.HrefTargetBlank
opts := html.RendererOptions{Flags: htmlFlags}
renderer := html.NewRenderer(opts)
return markdown.Render(doc, renderer)
}

View File

@ -84,6 +84,9 @@ func prepareDB(project *structs.Project) *structs.Project {
TypeParentTable: project.DB.Tables[i].FKs[j].Type, //project.DB.Tables[i].Pk,
Description: fmt.Sprintf("Foreign key for \\\"%s\\\" table", project.DB.Tables[i].FKs[j].TableName),
}
if project.DB.Tables[i].FKs[j].Description != "" {
fkTmp.Description = project.DB.Tables[i].FKs[j].Description
}
if strings.ToLower(project.DB.Tables[i].FKs[j].TableName) == "user" {
fkTmp.TypeParentTable = "uuid"
}

View File

@ -0,0 +1,14 @@
### Поля
|Поле|Тип|Описание|
|:---|:--|:-------|
|id|{{ fieldTypeDBStr .Pk nil }}|Первичный ключ|
{{ range $index, $field := .Fields }}|{{ fieldNameLowerPrepare $field.Name }}|{{ fieldTypeDB $field }}|{{ $field.Description }}|
{{ end }}
### Внешние ключи
|Ключ|Тип|Талица|Описание|
|:---|:--|:-----|:-------|
{{ range $index, $field := .FkFields }}|{{ fieldNameLowerPrepare $field.Name }}_id|{{ fieldNameLowerPrepare $field.TypeParentTable }}|{{ $tableNameVar := "" }}{{ if eq $field.Name "Parent" }}{{ $tableNameVar = fieldNamePrepare $.Name }}{{ else }}{{ $tableNameVar = fieldType $field }}{{ end }}{{ fieldNameLowerPrepare $tableNameVar }}|{{ $field.Description }}|
{{ end }}

View File

@ -0,0 +1,4 @@
|Название|Описание|
|:-------|:-------|
{{ range $index, $table := .Tables }}|{{ $varNameField := fieldNamePrepare $table.Name }}{{ fieldNameLowerPrepare $varNameField }}|{{ $table.Description }}|
{{end}}

View File

View File

@ -0,0 +1,12 @@
# База данных
{{ includeTemplPart "tmpl/docs/db/table-list-single.tmpl" .DB }}
![Полная структура БД](full-schemadb.svg "Полная структура БД")
{{ range $index, $table := .DB.Tables }}
{{ $varNameField := fieldNamePrepare .Name }}
## Таблица {{ fieldNameLowerPrepare $varNameField }}
{{ includeTemplPart "tmpl/docs/db/entity-table-no-href.tmpl" $table }}
{{ end }}

View File

@ -0,0 +1,6 @@
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>