Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dict #30

Merged
merged 1 commit into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/elliotchance/orderedmap"
"github.com/goccy/go-yaml"
"github.com/k1LoW/tbls/dict"
)

const Sep = ":"
Expand Down Expand Up @@ -61,6 +62,7 @@ type Config struct {
Diagrams []*Diagram `yaml:"diagrams"`
Nodes []*Node `yaml:"nodes"`
Relations []*Relation `yaml:"relations,omitempty"`
Dict *dict.Dict `yaml:"dict,omitempty"`
rawRelations []*rawRelation
realNodes []*RealNode
layers []*Layer
Expand Down Expand Up @@ -91,6 +93,7 @@ func (g *Graph) Attrs() []*Attr {
func New() *Config {
return &Config{
Graph: &Graph{},
Dict: &dict.Dict{},
}
}

Expand Down
5 changes: 5 additions & 0 deletions config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/goccy/go-yaml"
"github.com/k1LoW/tbls/dict"
)

func (d *Config) UnmarshalYAML(data []byte) error {
Expand All @@ -23,6 +24,7 @@ func (d *Config) UnmarshalYAML(data []byte) error {
Nodes []*Node `yaml:"nodes"`
Networks []interface{} `yaml:"networks"`
Relations []interface{} `yaml:"relations"`
Dict *dict.Dict `yaml:"dict,omitempty"`
}{}

if err := yaml.Unmarshal(data, &raw); err != nil {
Expand All @@ -40,6 +42,9 @@ func (d *Config) UnmarshalYAML(data []byte) error {
d.HideRealNodes = raw.HideRealNodes
d.Diagrams = raw.Diagrams
d.Nodes = raw.Nodes
if raw.Dict != nil {
d.Dict = raw.Dict
}

for _, rel := range raw.Networks {
rel, err := parseRelation(RelationTypeNetwork, rel)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ require (
github.com/gobuffalo/packr/v2 v2.8.0
github.com/goccy/go-graphviz v0.0.8
github.com/goccy/go-yaml v1.8.1
github.com/k1LoW/tbls v1.43.1
github.com/spf13/cobra v1.0.1-0.20200909172742-8a63648dd905
)
577 changes: 577 additions & 0 deletions go.sum

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions output/dot/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (d *Dot) OutputDiagram(wr io.Writer, diag *config.Diagram) error {
if err != nil {
return err
}
tmpl := template.Must(template.New("diagram").Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New("diagram").Funcs(output.Funcs(d.config.Dict)).Parse(ts))

clusters, remain, nEdges, err := d.config.BuildNestedClusters(diag.Layers)
if err != nil {
Expand All @@ -54,7 +54,7 @@ func (d *Dot) OutputLayer(wr io.Writer, l *config.Layer) error {
if err != nil {
return err
}
tmpl := template.Must(template.New("diagram").Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New("diagram").Funcs(output.Funcs(d.config.Dict)).Parse(ts))

clusters, remain, nEdges, err := d.config.BuildNestedClusters([]string{l.Name})
if err != nil {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (d *Dot) OutputNode(wr io.Writer, n *config.Node) error {
if err != nil {
return err
}
tmpl := template.Must(template.New("diagram").Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New("diagram").Funcs(output.Funcs(d.config.Dict)).Parse(ts))

clusters := config.Clusters{}
cIds := orderedmap.NewOrderedMap() // map[string]*config.Cluster{}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (d *Dot) OutputTag(wr io.Writer, t *config.Tag) error {
if err != nil {
return err
}
tmpl := template.Must(template.New("diagram").Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New("diagram").Funcs(output.Funcs(d.config.Dict)).Parse(ts))

clusters := config.Clusters{}
cIds := orderedmap.NewOrderedMap()
Expand Down Expand Up @@ -225,7 +225,7 @@ func (d *Dot) OutputRelation(wr io.Writer, rel *config.Relation) error {
if err != nil {
return err
}
tmpl := template.Must(template.New("diagram").Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New("diagram").Funcs(output.Funcs(d.config.Dict)).Parse(ts))

clusters := config.Clusters{}
cIds := orderedmap.NewOrderedMap()
Expand Down
12 changes: 6 additions & 6 deletions output/md/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (m *Md) OutputDiagram(wr io.Writer, d *config.Diagram) error {
}
}

tmpl := template.Must(template.New(d.Name).Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New(d.Name).Funcs(output.Funcs(m.config.Dict)).Parse(ts))
tmplData := map[string]interface{}{
"Diagram": d,
"Format": m.config.Format(),
Expand Down Expand Up @@ -76,7 +76,7 @@ func (m *Md) OutputLayer(wr io.Writer, l *config.Layer) error {
return err
}

tmpl := template.Must(template.New(l.Name).Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New(l.Name).Funcs(output.Funcs(m.config.Dict)).Parse(ts))
tmplData := map[string]interface{}{
"Layer": l,
"Format": m.config.Format(),
Expand Down Expand Up @@ -119,7 +119,7 @@ func (m *Md) OutputNode(wr io.Writer, n *config.Node) error {
tags = append(tags, t.(*config.Tag))
}

tmpl := template.Must(template.New(n.Id()).Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New(n.Id()).Funcs(output.Funcs(m.config.Dict)).Parse(ts))
tmplData := map[string]interface{}{
"Node": n,
"Format": m.config.Format(),
Expand All @@ -146,7 +146,7 @@ func (m *Md) OutputTag(wr io.Writer, t *config.Tag) error {
return err
}

tmpl := template.Must(template.New(t.Id()).Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New(t.Id()).Funcs(output.Funcs(m.config.Dict)).Parse(ts))
tmplData := map[string]interface{}{
"Tag": t,
"Format": m.config.Format(),
Expand All @@ -171,7 +171,7 @@ func (m *Md) OutputRelation(wr io.Writer, rel *config.Relation) error {
return err
}

tmpl := template.Must(template.New(rel.Id()).Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New(rel.Id()).Funcs(output.Funcs(m.config.Dict)).Parse(ts))
tmplData := map[string]interface{}{
"Relation": rel,
"Format": m.config.Format(),
Expand All @@ -196,7 +196,7 @@ func (m *Md) OutputIndex(wr io.Writer) error {
return err
}

tmpl := template.Must(template.New("index").Funcs(output.FuncMap).Parse(ts))
tmpl := template.Must(template.New("index").Funcs(output.Funcs(m.config.Dict)).Parse(ts))
tmplData := map[string]interface{}{
"Config": m.config,
"Diagram": m.config.PrimaryDiagram(),
Expand Down
14 changes: 7 additions & 7 deletions output/md/templates/diagram.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
{{ .Diagram.Desc }}

<p align="right">
[ <a href="{{ .DescPath }}/{{ mdpath "_diagram" .Diagram.Layers }}">:pencil2: Edit description</a> ]
[ <a href="{{ .DescPath }}/{{ mdpath "_diagram" .Diagram.Layers }}">:pencil2: {{ "Edit description" | lookup }}</a> ]
<p>

{{ if not .HideLayers }}
## Layers
## {{ "Layers" | lookup }}

| Name | Description |
| {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $l := .Layers }}
| [{{ $l.Name }}]({{ mdpath "layer" $l.Name }}) | {{ if ne $l.Desc "" }}{{ $l.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_layer" $l.Name }}">:pencil2:</a>{{ end }} |
{{- end }}
{{- end }}

## Nodes
## {{ "Nodes" | lookup }}

| Name{{ if not .HideRealNodes }} (node count){{ end }} | Description |
| {{ "Name" | lookup }}{{ if not .HideRealNodes }} ({{ "node count" | lookup }}){{ end }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $n := .Nodes }}
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}){{ if not $.HideRealNodes }} ({{ len $n.RealNodes }}){{ end }} | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
{{- end }}
## Tag groups
## {{ "Tag groups" | lookup }}

| Name | Description |
| {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $t := .Tags }}
| [{{ $t | fullname }}]({{ mdpath "tag" ($t | id) }}) | {{ if ne $t.Desc "" }}{{ $t.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_tag" ($t | id)}}">:pencil2:</a>{{ end }} |
Expand Down
18 changes: 9 additions & 9 deletions output/md/templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@
{{ .Config.Desc }}

<p align="right">
[ <a href="{{ .DescPath }}/{{ mdpath "_index" "" }}">:pencil2: Edit description</a> ]
[ <a href="{{ .DescPath }}/{{ mdpath "_index" "" }}">:pencil2: {{ "Edit description" | lookup }}</a> ]
<p>

{{ if not .Config.HideDiagrams }}
## Diagrams
## {{ "Diagrams" | lookup }}

| Name | Description |
| {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $d := .Diagrams }}
| [{{ $d.Name }}]({{ mdpath "diagram" $d.Layers }}) | {{ if ne $d.Desc "" }}{{ $d.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_diagram" $d.Layers }}">:pencil2:</a>{{ end }} |
{{- end }}
{{- end }}

{{ if not .Config.HideLayers }}
## Layers
## {{ "Layers" | lookup }}

| Name | Description |
| {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $l := .Layers }}
| [{{ $l.Name }}]({{ mdpath "layer" $l.Name }}) | {{ if ne $l.Desc "" }}{{ $l.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_layer" $l.Name }}">:pencil2:</a>{{ end }} |
{{- end }}
{{- end }}

## Nodes
## {{ "Nodes" | lookup }}

| Name{{ if not .Config.HideRealNodes }} (node count){{ end }} | Description |
| {{ "Name" | lookup }}{{ if not .Config.HideRealNodes }} ({{ "node count" | lookup }}){{ end }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $n := .Nodes }}
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}){{ if not $.Config.HideRealNodes }} ({{ len $n.RealNodes }}){{ end }} | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
{{- end }}

## Tag groups
## {{ "Tag groups" | lookup }}

| Name | Description |
| {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $t := .Tags }}
| [{{ $t | fullname }}]({{ mdpath "tag" ($t | id) }}) | {{ if ne $t.Desc "" }}{{ $t.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_tag" ($t | id)}}">:pencil2:</a>{{ end }} |
Expand Down
12 changes: 6 additions & 6 deletions output/md/templates/layer.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{ .Layer.Desc }}

<p align="right">
[ <a href="{{ .DescPath }}/{{ mdpath "_layer" .Layer.Name }}">:pencil2: Edit description</a> ]
[ <a href="{{ .DescPath }}/{{ mdpath "_layer" .Layer.Name }}">:pencil2: {{ "Edit description" | lookup }}</a> ]
<p>

{{ range $i, $c := .Clusters }}
Expand All @@ -14,21 +14,21 @@
{{ $c.Desc }}

<p align="right">
[ <a href="{{ $.DescPath }}/{{ mdpath "_cluster" ($c | id) }}">:pencil2: Edit description</a> ]
[ <a href="{{ $.DescPath }}/{{ mdpath "_cluster" ($c | id) }}">:pencil2: {{ "Edit description" | lookup }}</a> ]
<p>

{{ if ne (len $c.Components) 0 }}
### Cluster components
### {{ "Cluster components" | lookup }}

| Name | Description |
| {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $cc := $c.Components }}
| {{ $cc | fullname }} | {{ if ne $cc.Desc "" }}{{ $cc.Desc | trim | nl2br }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_component" ($cc | id)}}">:pencil2:</a>{{ end }} |
{{- end -}}
{{- end }}
### Nodes
### {{ "Nodes" | lookup }}

| Name{{ if not $.HideRealNodes }} (node count){{ end }} | Description |
| {{ "Name" | lookup }}{{ if not $.HideRealNodes }} ({{ "node count" | lookup }}){{ end }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $n := $c.Nodes }}
| [{{ $n | fullname }}]({{ mdpath "node" ($n | id) }}){{ if not $.HideRealNodes }} ({{ len $n.RealNodes }}){{ end }} | {{ if ne $n.Desc "" }}{{ $n.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_node" ($n | id)}}">:pencil2:</a>{{ end }} |
Expand Down
12 changes: 6 additions & 6 deletions output/md/templates/node.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
{{ .Node.Desc }}

<p align="right">
[ <a href="{{ .DescPath }}/{{ mdpath "_node" (.Node | id) }}">:pencil2: Edit description</a> ]
[ <a href="{{ .DescPath }}/{{ mdpath "_node" (.Node | id) }}">:pencil2: {{ "Edit description" | lookup }}</a> ]
<p>

## Components
## {{ "Components" | lookup }}

| Name | Description | From (Relation) | To (Relation) |
| {{ "Name" | lookup }} | {{ "Description" | lookup }} | {{ "From" | lookup }} ({{ "Relation" | lookup }}) | {{ "To" | lookup }} ({{ "Relation" | lookup }}) |
| --- | --- | --- | --- |
{{- range $i, $c := .Components }}
| {{ $c | id }} | {{ $c.Desc | trim | nl2br }} <a href="{{ $.DescPath }}/{{ mdpath "_component" ($c | id) }}">:pencil2:</a> | {{ fromlinks $c.NEdges $c }} | {{ tolinks $c.NEdges $c }} |
{{- end }}
## Tag groups
## {{ "Tag groups" | lookup }}

| Name | Description |
| {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- |
{{- range $i, $t := .Tags }}
| [{{ $t | fullname }}]({{ mdpath "tag" ($t | id) }}) | {{ if ne $t.Desc "" }}{{ $t.Desc | summary }}{{ else }}<a href="{{ $.DescPath }}/{{ mdpath "_tag" ($t | id)}}">:pencil2:</a>{{ end }} |
{{- end }}
{{- if not .HideRealNodes }}
## Real nodes
## {{ "Real nodes" | lookup }}
{{ range $i, $rn := .RealNodes }}
- {{ $rn | fullname }}
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions output/md/templates/relation.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
{{ .Relation.Desc }}

<p align="right">
[ <a href="{{ .DescPath }}/{{ mdpath "_relation" (.Relation | id) }}">:pencil2: Edit description</a> ]
[ <a href="{{ .DescPath }}/{{ mdpath "_relation" (.Relation | id) }}">:pencil2: {{ "Edit description" | lookup }}</a> ]
<p>

## Components
## {{ "Components" | lookup }}

| # | Component | Component Description |
| # | {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- | --- |
{{- range $i, $c := .Relation.Components }}
| {{ $i }} | {{ $c | id }} | {{ $c.Desc | trim | nl2br }} <a href="{{ $.DescPath }}/{{ mdpath "_component" ($c | id) }}">:pencil2:</a> |
Expand Down
6 changes: 3 additions & 3 deletions output/md/templates/tag.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
{{ .Tag.Desc }}

<p align="right">
[ <a href="{{ .DescPath }}/{{ mdpath "_tag" (.Tag | id) }}">:pencil2: Edit description</a> ]
[ <a href="{{ .DescPath }}/{{ mdpath "_tag" (.Tag | id) }}">:pencil2: {{ "Edit description" | lookup }}</a> ]
<p>

## Components
## {{ "Components" | lookup }}

{{- range $j, $rel := .Tag.Relations }}
| # | Name | Description |
| # | {{ "Name" | lookup }} | {{ "Description" | lookup }} |
| --- | --- | --- |
{{- range $i, $c := $rel.Components }}
| {{ $i }} | {{ $c | id }} | {{ $c.Desc | trim | nl2br }} <a href="{{ $.DescPath }}/{{ mdpath "_component" ($c | id) }}">:pencil2:</a> |
Expand Down
Loading