catalog

package
v0.0.0-...-59132f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Overview

diagram-creation.go: all the methods attached to the generator object to be used in templating

generator.go: struct for converting sysl modules to documentation (Generator)

server.go: implements http handler interface so that Generator struct can be used directly as a handler

markdown-template.go: the markdown template used to template the sysl module

util.go: misc functions to convert/send http requests/sort maps

Index

Constants

View Source
const AllInOneTemplate = `` /* 5558-byte string literal not displayed */
View Source
const EndTags = `</div>
</body>
</html>`
View Source
const Favicon = `` /* 22612-byte string literal not displayed */
View Source
const Header = `` /* 171-byte string literal not displayed */
View Source
const MacroPackageProject = `` /* 439-byte string literal not displayed */
View Source
const NewPackageTemplate = `` /* 5751-byte string literal not displayed */
View Source
const ProjectTemplate = `` /* 501-byte string literal not displayed */
View Source
const RedocPage = `` /* 639-byte string literal not displayed */
View Source
const Style = `` /* 3020-byte string literal not displayed */

Variables

This section is empty.

Functions

func AppendVersion

func AppendVersion(remoteFilePath string, version string) string

AppendVersion takes in a remote file import path and a version, and appends the version tag to the repo name separated by the '@' char e.g for an input - remoteFilePath github.com/anz-bank/sysl-examples/demos/grocerystore/grocerystore.sysl - version v0.0.0-c63b9e92813a it returns /github.com/anz-bank/sysl-examples@v0.0.0-c63b9e92813a/demos/grocerystore/grocerystore.sysl

func AsSet

func AsSet(in []string) map[string]struct{}

func Attribute

func Attribute(a Attr, query string) string

func BuildGithubBlobURL

func BuildGithubBlobURL(repoURL string) string

BuildGithubBlobURL creates a root URL for github blob it will not work for non github links.

func BuildGithubRawURL

func BuildGithubRawURL(repoURL string) (gitURL string)

BuildGithubRawURL gets the base URL for raw content hosted on github.com or Github Enterprise For github.com it takes in https://github.com/joshcarp/sysl-catalog-wasm and returns https://raw.githubusercontent.com/joshcarp/sysl-catalog-wasm/master/ For Github Enterprise it takes in https://github.myorg.com/joshcarp/sysl-catalog-wasm and returns https://github.myorg.com/raw/joshcarp/sysl-catalog-wasm/master/

func BuildRedoc

func BuildRedoc(specURL string) []byte

BuildRedoc generates a slice of bytes containing the HTML contents of a redoc page It takes in the url where the spec is located

func BuildSpecURL

func BuildSpecURL(filePath string, version string) string

BuildSpecURL takes a filepath and version and builds a URL to the cached spec file It also trims . prefixes and adds a / so that the URL is relative

func CopySyslModCache

func CopySyslModCache(targetDir string) error

CopySyslModCache copies ALL the contents of the sysl module cache directory (typically found in ~/.sysl/github.com) and outputs it to the specified folder

func CreateFileName

func CreateFileName(dir string, elems ...string) (string, string)

CreateFileName returns the absolute and relative filepaths

func CreateSequenceDiagram

func CreateSequenceDiagram(m *sysl.Module, call string) (string, error)

CreateSequenceDiagram creates an sequence diagram and returns the sequence diagram string and any errors

func FieldType

func FieldType(t *sysl.Type) string

func Fields

func Fields(t *sysl.Type) map[string]*sysl.Type

func Filter

func Filter(vs []string, f func(string) bool) []string

Map applies a function to every element in a string slice

func GenerateAndWriteRedoc

func GenerateAndWriteRedoc(fs afero.Fs, fileName string, specURL string) error

GenerateRedoc creates a redoc html file

func GenerateCatalog

func GenerateCatalog(module []byte, templ, plantuml string) (string, error)

func GetAppPackageName

func GetAppPackageName(a Namer) (string, string)

GetAppPackageName returns the package and app name of any sysl application

func GetAppTypeName

func GetAppTypeName(param Typer) (appName string, typeName string)

GetAppTypeName takes a Sysl Type and returns the appName and typeName of a param If the type is a primitive, the appName returned is "primitive"

func GetImportPathAndVersion

func GetImportPathAndVersion(app *sysl.Application) (importPath string, version string, err error)

func GetPackageName

func GetPackageName(m *sysl.Module, a Namer) string

func GetRemoteFromGit

func GetRemoteFromGit() (string, error)

GetRemoteFromGit gets the URL to the git remote e.g github.com/myorg/somerepo/

func HttpToFile

func HttpToFile(fs afero.Fs, fileName, url string) error

func IsOpenAPIFile

func IsOpenAPIFile(filePath string) bool

func Last

func Last(i interface{}, ind int) bool

func Map

func Map(vs []string, funcs ...func(string) string) []string

Map applies a function to every element in a string slice

func ModulePackageName

func ModulePackageName(m *sysl.Module) string

func NewTypeRef

func NewTypeRef(appName, typeName string) *sysl.Type

NewTypeRef returns a type reference, needed to correctly generate data model diagrams

func PlantUMLJava

func PlantUMLJava(service, out string) error

func PlantUMLNailGun

func PlantUMLNailGun(contents string) ([]byte, error)

func PlantUMLURL

func PlantUMLURL(plantumlService, contents string) (string, error)

PlantUMLURL returns a PlantUML url

func Remove

func Remove(s string, old ...string) string

func RetryHTTPRequest

func RetryHTTPRequest(url string) ([]byte, error)

RetryHTTPRequest retries the given request

func SanitiseOutputName

func SanitiseOutputName(s string) string

SanitiseOutputName removes characters so that the string can be used as a hyperlink.

func ServiceMetadata

func ServiceMetadata(a Attr) string

func SortedKeys

func SortedKeys(m interface{}) []string

func StripExtension

func StripExtension(input string) string

StripExtension removes spaces and suffixes

func TernaryOperator

func TernaryOperator(condition bool, i ...interface{}) interface{}

TernaryOperator returns the first element if bool is true and the second element is false

func UnmarshallJson

func UnmarshallJson(b []byte, m *sysl.Module) error

Unmarshall Json unmarshalls json bytes into a sysl module

Types

type Attr

type Attr interface {
	GetAttrs() map[string]*sysl.Attribute
}

type Generator

type Generator struct {
	RootModule           *sysl.Module
	FilesToCreate        map[string]string
	MermaidFilesToCreate map[string]string
	RedocFilesToCreate   map[string]string
	GeneratedFiles       map[string][]byte
	GeneratedFilesMutex  *sync.RWMutex
	SourceFileName       string
	ProjectTitle         string
	ImageDest            string // Output all images into this folder is set
	Format               string // "html" or "markdown" or "" if custom
	Ext                  string
	OutputFileName       string
	PlantumlService      string
	Templates            []*template.Template
	StartTemplateIndex   int
	FilterPackage        []string // Filter these regex terms out of packagenames

	CustomTemplate    bool
	LiveReload        bool // Add live reload javascript to html
	ImageTags         bool // embedded plantuml img tags, or generated svgs
	DisableCss        bool // used for rendering raw markdown
	DisableImages     bool // used for omitting image creation
	Mermaid           bool
	Redoc             bool // used for generating redoc for openapi specs
	CopySpecsToOutput bool

	Log *logrus.Logger
	Fs  afero.Fs

	// All of these are used in markdown generation
	Module     *sysl.Module
	CurrentDir string
	TempDir    string
	Title      string
	OutputDir  string
	Links      map[string]string
	Server     bool

	BasePath string // for using on another endpoint that isn't '/'
	// contains filtered or unexported fields
}

Generator is the contextual object that is used in the markdown generation

func NewProject

func NewProject(
	titleAndFileName, plantumlService, outputType string,
	logger *logrus.Logger,
	module *sysl.Module,
	fs afero.Fs, outputDir string) *Generator

NewProject generates a Generator object, fs and outputDir are optional if being used for a web server.

func NewProjectFromJson

func NewProjectFromJson(
	titleAndFileName, plantumlService, outputType string,
	logger *logrus.Logger,
	module []byte,
	fs afero.Fs, outputDir string) *Generator

NewProjectFromJson generates a generator object with a json byte input (of a sysl module) instead of a sysl module

func (*Generator) CreateAliasedTypeDiagram

func (p *Generator) CreateAliasedTypeDiagram(appName, typeName, typeAlias string, t *sysl.Type, recursive bool) string

func (*Generator) CreateAliasedTypeDiagramMermaid

func (p *Generator) CreateAliasedTypeDiagramMermaid(appName string, typeName string, typeAlias string, recursive bool) string

func (*Generator) CreateFile

func (p *Generator) CreateFile(contents string, diagramType int, elems ...string) string

CreateFile registers a file that needs to be created in p, or returns the embedded img tag if in server mode

func (*Generator) CreateIntegrationDiagram

func (p *Generator) CreateIntegrationDiagram(m *sysl.Module, title string, EPA bool) string

func (*Generator) CreateIntegrationDiagramMermaid

func (p *Generator) CreateIntegrationDiagramMermaid(m *sysl.Module, title string, EPA bool) string

func (*Generator) CreateIntegrationDiagramPlantuml

func (p *Generator) CreateIntegrationDiagramPlantuml(m *sysl.Module, title string, EPA bool) string

CreateIntegrationDiagram creates an integration diagram and returns the filename

func (*Generator) CreateMarkdown

func (p *Generator) CreateMarkdown(t *template.Template, outputFileName string, i interface{}) error

CreateMarkdown is a wrapper function that also converts output markdown to html if in server mode

func (*Generator) CreateParamDataModel

func (p *Generator) CreateParamDataModel(app *sysl.Application, param Param) string

CreateParamDataModel creates a parameter data model and returns a filename

func (*Generator) CreateRedoc

func (p *Generator) CreateRedoc(app *sysl.Application, appName string) string

CreateRedoc registers a file that needs to be created when either: - The @redoc-spec attribute has been set - The source context has an extension suggesting it is an OpenAPI file

func (*Generator) CreateReturnDataModel

func (p *Generator) CreateReturnDataModel(appname string, stmnt *sysl.Statement, endpoint *sysl.Endpoint) string

CreateReturnDataModel creates a return data model and returns a filename, or empty string if it wasn't a return statement.

func (*Generator) CreateSequenceDiagram

func (p *Generator) CreateSequenceDiagram(appName string, endpoint *sysl.Endpoint) string

func (*Generator) CreateSequenceDiagramMermaid

func (p *Generator) CreateSequenceDiagramMermaid(appName string, endpoint *sysl.Endpoint) string

func (*Generator) CreateSequenceDiagramPlantuml

func (p *Generator) CreateSequenceDiagramPlantuml(appName string, endpoint *sysl.Endpoint) string

CreateSequenceDiagram creates an sequence diagram and returns the filename

func (*Generator) CreateTypeDiagram

func (p *Generator) CreateTypeDiagram(appName string, typeName string, t *sysl.Type, recursive bool) string

CreateTypeDiagram creates a data model diagram and returns the filename It handles recursively getting the related types, or for primitives, just returns the

func (*Generator) GenerateDataModel

func (p *Generator) GenerateDataModel(app *sysl.Application) string

GenerateDataModel generates a data model for all of the types in app

func (*Generator) GetFuncMap

func (p *Generator) GetFuncMap() template.FuncMap

GetFuncMap returns the funcs that are used in diagram generation.

func (*Generator) GetParamType

func (p *Generator) GetParamType(app *sysl.Application, param *sysl.Param) *sysl.Type

GetReturnType converts an application and a param into a type, useful for getting attributes.

func (*Generator) GetReturnType

func (p *Generator) GetReturnType(endpoint *sysl.Endpoint, stmnt *sysl.Statement) *sysl.Type

GetReturnType converts an endpoint and a statement into a type, useful for getting attributes.

func (*Generator) MacroPackages

func (p *Generator) MacroPackages(module *sysl.Module) []string

MacroPackages executes the markdown for a MacroPackage and returns a slice of the rows

func (*Generator) ModuleAsMacroPackage

func (p *Generator) ModuleAsMacroPackage(m *sysl.Module) map[string]*sysl.Module

func (*Generator) ModuleAsPackages

func (p *Generator) ModuleAsPackages(m *sysl.Module) map[string]*sysl.Module

ModuleAsPackages returns a map of [packagename]*sysl.Module

func (*Generator) PUMLFile

func (p *Generator) PUMLFile(fs afero.Fs, fileName, contents string) error

func (*Generator) Packages

func (p *Generator) Packages(m *sysl.Module) []string

Packages executes the markdown for a package and returns a slice of the rows

func (*Generator) Run

func (p *Generator) Run()

Run Executes a project and generates markdown and diagrams to a given filesystem.

func (*Generator) ServeHTTP

func (p *Generator) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is implements the handler interface

func (*Generator) ServerSettings

func (p *Generator) ServerSettings(disableCSS, liveReload, imageTags bool) *Generator

ServerSettings sets the server settings, this should be set before using as http handler

func (*Generator) SetOptions

func (p *Generator) SetOptions(
	disableCss, disableImages, imageTags, redoc, mermaidEnabled bool,
	readmeName, ImageDest string) *Generator

func (*Generator) SourcePath

func (p *Generator) SourcePath(a SourceCoder) string

RootPath appends CurrentDir to output

func (*Generator) Update

func (p *Generator) Update(m *sysl.Module, errs ...error) *Generator

Update loads another Sysl module into a project and runs

func (*Generator) WithTemplateFs

func (p *Generator) WithTemplateFs(fs afero.Fs, fileNames ...string) *Generator

func (*Generator) WithTemplateString

func (p *Generator) WithTemplateString(tmpls ...string) *Generator

WithTemplateFileNames loads template strings into project and package of p respectively

type MermaidGenerator

type MermaidGenerator struct {
	// contains filtered or unexported fields
}

func MakeMermaidGenerator

func MakeMermaidGenerator() MermaidGenerator

func (MermaidGenerator) GenerateAndWriteMermaidDiagram

func (m MermaidGenerator) GenerateAndWriteMermaidDiagram(fs afero.Fs, fileName string, data string) error

GenerateAndWriteMermaidDiagram writes a mermaid svg to file

type Namer

type Namer interface {
	Attr
	GetName() *sysl.AppName
}

type Param

type Param interface {
	Typer
	GetName() string
}

type Redoc

type Redoc struct {
	SpecURL string
}

Redoc is the struct passed to the string template RedocPage

type SourceCoder

type SourceCoder interface {
	Attr
	GetSourceContext() *sysl.SourceContext
}

type Typer

type Typer interface {
	GetType() *sysl.Type
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL