Documentation
¶
Index ¶
- Variables
- func D2(parser Parser, cfg *Config) ([]byte, error)
- func NewTemplate(name, input string, funcs ...template.FuncMap) *template.Template
- func RenderClass(class *domain.Class) string
- func RenderContainer(container *Container) string
- func RenderRelation(relation *domain.Relation) string
- type Config
- type Container
- type ContainerParser
- type Containers
- type DirContainerParser
- type Format
- type Parser
Constants ¶
This section is empty.
Variables ¶
var ClassTemplate = NewTemplate("Class", `
"{{- $.Name }}": {
shape: class
{{- range $property := $.Properties }}
"{{ $property.Name }}": "{{ $property.Type }}"
{{- end }}
}`)
var ContainerTemplate = NewTemplate("Container", ` {{- if $.Name -}} "{{ $.Name }}": { {{- range $container := $.Containers -}} {{ $container.Render | indent 4 }} {{ end -}} {{- range $class := $.Classes }} {{ class $class | indent 4 }} {{ end -}} } {{- else -}} {{- range $container := $.Containers -}} {{ $container.Render }} {{ end -}} {{- range $class := $.Classes }} {{ class $class }} {{ end -}} {{- end }}`, template.FuncMap{ "class": RenderClass, "indent": func(amount int, input string) string { lines := strings.Split(input, "\n") var builder strings.Builder for i, line := range lines { builder.WriteString(strings.Repeat(" ", amount) + line) if i != len(lines)-1 { builder.WriteString("\n") } } return builder.String() }, })
var ErrNoClasses = errors.New("no classes parsed")
ErrNoClasses is returned when no Classes are parsed
var ErrParserFailure = errors.New("failed to parse classes or relations")
ErrParserFailure is returned when there is some failure by the parser
var ErrUnknownFormat = errors.New("unknown format")
ErrUnknownFormat is returned when the supplied format is not recognized
var RelationTemplate = NewTemplate("Relation", `
{{- $.From.Name }} -- {{ $.To.Name }}: "{{ $.Type | safe }}"`)
Functions ¶
func NewTemplate ¶
NewTemplate from name, input
func RenderContainer ¶
RenderContainer to string output
func RenderRelation ¶
RenderRelation to string output
Types ¶
type Config ¶
type Config struct {
// Format used when outputting diagram
Format Format
// Tool used to render svg (if SVG Format)
Tool string
// Args used by the tool
Args []string
// ContainerBasePath if set will wrap all domain.Class in containers based on the
// DirContainerParser
ContainerBasePath string
}
Config used when rendering D2
type Container ¶
type Container struct {
// Name of the container
Name string
// Classes in the container
Classes []*domain.Class
// Containers nested in this Container
Containers Containers
}
Container to put domain.Class in as a grouping
type ContainerParser ¶
ContainerParser derives the nesting of containers for a particular domain.Source e.g. if 'some,nested,value' is returned the eventual class is rendered inside a three layer deep Container
type Containers ¶
type Containers []*Container
Containers is a helper type to perform methods on a group of Container
type DirContainerParser ¶
type DirContainerParser struct {
// RootPath to remove from the domain.Source to determine directory containers
RootPath string
}
DirContainerParser uses a base directory to parse containers by stripping the RootPath from the domain.Source of the domain.Class and using the directory representation as containers
func (DirContainerParser) Containers ¶
func (d DirContainerParser) Containers(source domain.Source) []string
Containers separated by the filepath.Separator in the filesystem relative to some RootPath if the source contains the file:// protocol, it's removed automatically
type Format ¶
type Format string
Format of output string supported by D2
const Native Format = "d2"
Native D2 script format
const PNG Format = "png"
PNG format
const SVG Format = "svg"
SVG format
func FormatFromFile ¶
FormatFromFile parses the given path and determines the output format used by the D2 parser