Package renderer

import "gitlab.com/zoralab/godocgen/internal/renderer"

Package renderer is the internal package to render the output from doc data.

renderer holds all terminal, text/template, and html/template packages styling and documentation rendering.

This package is an internal package which is exclusive only for Godocgen to import from. External third-party importing is prohibited by Go build system.

Constants

Template data labels are the string labels for mapping data in the Go template module.

const (
	// NameLabel is the template data label for Name. To use it,
	// simply set {{ .Name }}
	NameLabel = "Name"


	// HeaderLabel is the template data label for Header. To use
	// it, simply set {{ .Header }}
	HeaderLabel = "Header"


	// SynopsisLabel is the template data label for Synopsis. To
	// use it, simply set {{ .Synopsis }}
	SynopsisLabel = "Synopsis"


	// ValueLabel is the template data label for Value. To use
	// it, simply set {{ .Value }}
	ValueLabel = "Value"


	// CodesLabel is the template data label for code blocks. To
	// use it, simply loop over {{ .Codes }} and print out
	// individual lines.
	CodesLabel = "Codes"


	// HasReceiverLabel is the template data label for
	// HasReceiver. To use it, simply set {{ .HasReceiver }}
	HasReceiverLabel = "HasReceiver"


	// HugoTimestampLabel is the template data label for Hugo
	// compatible / RFC3339 timestamp format. To use it, simply
	// set {{ .HugoTimestamp }}
	HugoTimestampLabel = "HugoTimestamp"


	// TimestampLabel is the template data label for RFC1123Z
	// formatted datetime. To use it, simply set {{ .Timestamp }}
	TimestampLabel = "Timestamp"
)

Template names are the string labels for mapping rendering template fragments.

const (
	// TemplateHead is the front matter of the document
	// rendering template
	TemplateHead = "Head"


	// TemplateTitle is the head of the document rendering
	// template
	TemplateTitle = "Title"


	// TemplateHeader is the section header rendering template
	TemplateHeader = "Header"


	// TemplateSynopsis is the synopsis contents rendering
	// template
	TemplateSynopsis = "Synopsis"


	// TemplateDeclGroup is the declaration group opener
	// rendering template
	TemplateDeclGroup = "DeclGroup"


	// TemplateDeclElements is the declration group elements
	// rendering template
	TemplateDeclElements = "DeclElements"


	// TemplateEndDeclGroup is the declration group closer
	// rendering template
	TemplateEndDeclGroup = "EndDeclGroup"


	// TemplateFunction is the function rendering template
	TemplateFunction = "Function"


	// TemplateCode is the code blocks rendering template
	TemplateCode = "Code"


	// TemplateNewLine is the new line rendering template
	TemplateNewLine = "NewLine"


	// TemplateImportPath is the import path rendering template
	TemplateImportPath = "ImportPath"


	// TemplateExample is the example rendering template
	TemplateExample = "Example"
)

DocType constants are the string labels for document format types.

const (
	// DocTypeNone is the string label for no extension file
	// output
	DocTypeNone = ""


	// DocTypeTerminal is the string label for markdown file
	// output
	DocTypeMarkdown = "md"


	// DocTypeTerminal is the string label for text file output
	DocTypeText = "txt"


	// DocTypeTerminal is the string label for terminal output
	DocTypeTerminal = "terminal"
)

Functions

Func IsSupportedFormat(path string) (docType string)

IsSupportedFormat is to check requested document format is supported.

This is used for checking the request before creating the os.file for Canva to write.

Canva

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

Canva is the renderer data structure that holds the renderer's engine.

It has private variables that require initialization and uses certain inputs to configure its engine. Hence, please strictly use renderer.New() to create a new Canva structure object.

Func New(writer io.Writer, templatePath string, docType string, width uint) (*Canva, error)

New is to create a new Canva object.

The function returns either the Canva object or error object. The error is caused by incompatible values received from the parameters.

Func (c *Canva) BeginDeclGroup(name string)

BeginDeclGroup is to render the starting indicator for a declarations group.

This is commonly used in constant and variable groups.

Func (c *Canva) EndDeclGroup()

EndDeclGroup is to render the ending indicator for a declarations group.

This is commonly used in constant and variable groups.

Func (c *Canva) ParseCode(codes []string)

ParseCode is to render a given code block.

This is commonly used for type rendering (e.g. struct codes).

Func (c *Canva) ParseDeclElements(header string, value string)

PraseDeclElements is to render each elements in a declarations group.

This is commonly used in constant and variable groups.

Func (c *Canva) ParseExample(name string, suffix string, doc string, codes []string, output string)

ParseExample is to render example function.

This is commonly used for displaying example codes for various entities like package examples, function examples, type examples, and method examples.

Func (c *Canva) ParseFunction(header string, receiver string, value string)

ParseFunction is to render a function.

This is commonly used in rendering generic function or type associated function.

Func (c *Canva) ParseHead(name string, synopsis string, relativeName string)

PraseHead is to render the package front-matter information.

It is used to render the front-matter leading information for the documentation.

Func (c *Canva) ParseHeader(name string)

ParseHeader is to render the header section of a content.

It is used to render the section's title.

Func (c *Canva) ParseImportPath(path string)

ParseImportPath is the render import path statement.

This is commonly used for stating the Go's import instruction to use the Go package module.

Func (c *Canva) ParseNewLine()

ParseNewLine is to render a new line.

This is commonly used for separator.

Func (c *Canva) ParseSynopsis(synopsis string)

ParseSynopsis is to render the document body of a content.

It is used to render the section body's articles.

Func (c *Canva) ParseTitle(pkg string, name string)

ParseTitle is to render the package title for the documentation.

It is used to render the document's title.