88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
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"
|
||
)
|
||
|
||
func Documentation() {
|
||
if !AppConfig.IsHtml {
|
||
AppConfig.IsMarkdown = true
|
||
}
|
||
// Генерация общей схемы БД
|
||
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])
|
||
}*/
|
||
// TODO
|
||
}
|
||
|
||
// Генерирования списка таблиц
|
||
/*func listTablesDocGen() string {
|
||
// TODO
|
||
}
|
||
|
||
// Генерирование полей таблицы
|
||
func tableDocGen(table structs.Table) string {
|
||
// TODO
|
||
}*/
|
||
|
||
// Генерация общей схемы БД
|
||
func fullDocDBGen() {
|
||
// TODO
|
||
if tmpl, err := templ.ReadTmplFile("tmpl/docs/db/full-schema.tmpl"); err != nil {
|
||
panic(err)
|
||
} else {
|
||
if buff, err := templ.ExecuteTmplFile(tmpl, Project.DB); err != nil {
|
||
panic(err)
|
||
} else {
|
||
//fmt.Println(string(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+"/full-schemadb.svg", []byte(result))
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
// Генерация отдельной таблицы с прилегающими ближайшими таблицами
|
||
func docDBGen(table structs.Table) {
|
||
// TODO
|
||
}
|