templating

package
v0.2.62 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 16 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateFuncs = template.FuncMap{

	"trim":                    strings.TrimSpace,
	"trimRightSpace":          trimRightSpace,
	"trimTrailingWhitespaces": trimRightSpace,
	"rpad":                    rpad,
	"quote":                   quote,
	"stripNewlines":           stripNewlines,
	"quoteNewlines":           quoteNewlines,

	"toUpper": strings.ToUpper,
	"toLower": strings.ToLower,

	"replaceRegexp": replaceRegexp,

	"add": add,
	"sub": sub,
	"div": div,
	"mul": mul,

	"parseFloat": parseFloat,
	"parseInt":   parseInt,

	"currency": currency,

	"padLeft":   padLeft,
	"padRight":  padRight,
	"padCenter": padCenter,

	"bold":          bold,
	"underline":     underline,
	"italic":        italic,
	"strikethrough": strikethrough,
	"code":          code,
	"codeBlock":     codeBlock,

	"toYaml":      toYaml,
	"indentBlock": indentBlock,

	"styleBold": styleBold,
}

TemplateFuncs provides helpers for the standard cobra usage and help templates

Functions

func CreateHTMLTemplate

func CreateHTMLTemplate(name string) *html.Template

func CreateTemplate

func CreateTemplate(name string) *template.Template

func ParseFS

func ParseFS(t *template.Template, f fs.FS, patterns ...string) error

ParseFS will recursively glob for all the files matching the given patterns, and load them into one big template (with sub-templates). The globs use bmatcuk/doublestar and support ** notation for recursive globbing.

func ParseHTMLFS

func ParseHTMLFS(t *html.Template, f fs.FS, pattern string, baseDir string) error

ParseHTMLFS will recursively glob for all the files matching the given patterns, and load them into one big template (with sub-templates). It is the html.Template equivalent of ParseFS.

The globs use bmatcuk/doublestar and support ** notation for recursive globbing.

func RenderHtmlTemplateString

func RenderHtmlTemplateString(tmpl string, data interface{}) (string, error)

func RenderTemplate

func RenderTemplate(tmpl TemplateExecute, data interface{}) (string, error)

func RenderTemplateFile

func RenderTemplateFile(filename string, data interface{}) (string, error)

func RenderTemplateString

func RenderTemplateString(tmpl string, data interface{}) (string, error)

Types

type TemplateExecute

type TemplateExecute interface {
	Execute(wr io.Writer, data any) error
}

Jump to

Keyboard shortcuts

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