template
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package template provides templating functionality.
Usage
import ( "fmt" gotemplate "text/template" "github.com/terraform-docs/terraform-docs/print" "github.com/terraform-docs/terraform-docs/template" "github.com/terraform-docs/terraform-docs/terraform")const mainTpl =`{{- if .Config.Sections.Header -}} {{- with .Module.Header -}} {{ colorize "\033[90m" . }} {{ end -}} {{- printf "\n\n" -}}{{ end -}}`func render(config *print.Config, module *terraform.Module) (string, error) { tt := template.New(config, &template.Item{ Name: "main", Text: mainTpl, TrimSpace: true, }) tt := template.New(config, items...) tt.CustomFunc(gotemplate.FuncMap{ "colorize": func(color string, s string) string { reset := "\033[0m" if !config.Settings.Color { color = "" reset = "" } return fmt.Sprintf("%s%s%s", color, s, reset) }, }) return tt.Render("main", module)}
Index¶
- func ConvertMultiLineText(s string, isTable bool, isHeader bool, showHTML bool) string
- func ConvertOneLineCodeBlock(s string) string
- func CreateAnchorAsciidoc(prefix string, value string, anchor bool, escape bool) string
- func CreateAnchorMarkdown(prefix string, value string, anchor bool, escape bool) string
- func EscapeCharacters(s string, escape bool, escapePipe bool) string
- func GenerateIndentation(base int, extra int, char string) string
- func NormalizeURLs(s string, escape bool) string
- func SanitizeAsciidocTable(s string, escape bool, html bool) string
- func SanitizeDocument(s string, escape bool, html bool) string
- func SanitizeMarkdownTable(s string, escape bool, html bool) string
- func SanitizeName(name string, escape bool) string
- func SanitizeSection(s string, escape bool, html bool) string
- type Item
- type Template
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcConvertMultiLineText¶
ConvertMultiLineText converts a multi-line text into a suitable Markdown representation.
funcConvertOneLineCodeBlock¶
ConvertOneLineCodeBlock converts a multi-line code block into a one-liner.Line breaks are replaced with single space.
funcCreateAnchorAsciidoc¶
CreateAnchorAsciidoc creates HTML anchor for AsciiDoc format.
funcCreateAnchorMarkdown¶
CreateAnchorMarkdown creates HTML anchor for Markdown format.
funcEscapeCharacters¶
EscapeCharacters escapes characters which have special meaning in Markdown intotheir corresponding literal.
funcGenerateIndentation¶
GenerateIndentation generates indentation of Markdown and AsciiDoc headerswith base level of provided 'settings.IndentLevel' plus any extra level neededfor subsection (e.g. 'Required Inputs' which is a subsection of 'Inputs' section)
funcNormalizeURLs¶
NormalizeURLs runs after escape function and normalizes URL back to the originalstate. For example any underscore in the URL which got escaped by 'EscapeCharacters'will be reverted back.
funcSanitizeAsciidocTable¶
SanitizeAsciidocTable converts passed 'string' to suitable AsciiDoc representationfor a table. (including line-break, illegal characters, code blocks etc).
funcSanitizeDocument¶
SanitizeDocument converts passed 'string' to suitable Markdown or AsciiDocrepresentation for a document. (including line-break, illegal characters,code blocks etc).
funcSanitizeMarkdownTable¶
SanitizeMarkdownTable converts passed 'string' to suitable Markdown representationfor a table. (including line-break, illegal characters, code blocks etc).
funcSanitizeName¶
SanitizeName escapes underscore character which have special meaning inMarkdown.
funcSanitizeSection¶
SanitizeSection converts passed 'string' to suitable Markdown or AsciiDocrepresentation for a document. (including line-break, illegal characters,code blocks etc). This is in particular being used for header and footer.
IMPORTANT: SanitizeSection will never change the line-endings and preservethem as they are provided by the users.
Types¶
typeTemplate¶
type Template struct {// contains filtered or unexported fields}
Template represents a new Template with given name and content to be renderedwith provided settings with use of built-in and custom functions.
func (*Template)CustomFunc¶
func (t *Template) CustomFunc(funcsgotemplate.FuncMap)
CustomFunc adds new custom functions to the template if functions with the samenames didn't exist.
func (Template)Funcs¶
func (tTemplate) Funcs()gotemplate.FuncMap
Funcs return available template out of the box and custom functions.