Skip to content

Commit

Permalink
viewpoints data of tables in md
Browse files Browse the repository at this point in the history
  • Loading branch information
majimaccho committed Oct 26, 2023
1 parent 4235f6d commit af1e90b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
25 changes: 25 additions & 0 deletions output/md/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func (m *Md) OutputViewpoint(wr io.Writer, i int, v *schema.Viewpoint) error {

// Output generate markdown files.
func Output(s *schema.Schema, c *config.Config, force bool) (e error) {
s, err := s.SetViewpointsToTables()
if err != nil {
return errors.WithStack(err)
}

docPath := c.DocPath

fullPath, err := filepath.Abs(docPath)
Expand Down Expand Up @@ -588,6 +593,24 @@ func (m *Md) makeTableTemplateData(t *schema.Table) map[string]interface{} {
columnsData = append(columnsData, data)
}

// Viewpoints
viewpointsData := [][]string{
[]string{
m.config.MergedDict.Lookup("Name"),
m.config.MergedDict.Lookup("Definition"),
},
[]string{"----", "----------"},
}

for _, v := range t.Viewpoints {
data := []string{
fmt.Sprintf("[%s](viewpoint-%d.md)", v.Name, v.Index),
v.Desc,
}

viewpointsData = append(viewpointsData, data)
}

// Constraints
constraintsData := [][]string{
[]string{
Expand Down Expand Up @@ -698,6 +721,7 @@ func (m *Md) makeTableTemplateData(t *schema.Table) map[string]interface{} {
return map[string]interface{}{
"Table": t,
"Columns": adjustTable(columnsData),
"Viewpoints": adjustTable(viewpointsData),
"Constraints": adjustTable(constraintsData),
"Indexes": adjustTable(indexesData),
"Triggers": adjustTable(triggersData),
Expand All @@ -708,6 +732,7 @@ func (m *Md) makeTableTemplateData(t *schema.Table) map[string]interface{} {
return map[string]interface{}{
"Table": t,
"Columns": columnsData,
"Viewpoints": viewpointsData,
"Constraints": constraintsData,
"Indexes": indexesData,
"Triggers": triggersData,
Expand Down
9 changes: 8 additions & 1 deletion testdata/templates/table.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@
|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}
{{- end }}

{{ $len := len .Constraints }}{{ if ne $len 2 -}}
{{ $len := len .Viewpoints }}{{ if ne $len 2 -}}
## {{ "Viewpoints" | lookup }}
{{ range $l := .Viewpoints }}
|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}
{{- end }}

{{ end -}}
{{ $len := len .Constraints -}}{{ if ne $len 2 -}}
## {{ "Constraints" | lookup }}
{{ range $l := .Constraints }}
|{{ range $d := $l }} {{ $d | nl2br }} |{{ end }}
Expand Down

0 comments on commit af1e90b

Please sign in to comment.