templateutil

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFuncMap = template.FuncMap{
	"base64": func(in string) string {
		return base64.StdEncoding.EncodeToString([]byte(in))
	},
	"prefixContinuationLinesWith": bytesutil.PrefixContinuationLinesWith,
	"lowerFirst": func(s string) string {
		return string(unicode.ToLower(rune(s[0]))) + s[1:]
	},
	"pretty": func(data any) string {
		return pretty.Sprintf("%# v", data)
	},
	"prettyLazy": func(data any) string {
		return pretty.LazySprintf("%# v", data)
	},
	"quote": func(data any) string {
		return pretty.Sprintf("%q", data)
	},
}

DefaultFuncMap holds common template functions.

Functions

func MergeFuncMaps

func MergeFuncMaps(a template.FuncMap, b template.FuncMap) template.FuncMap

MergeFuncMaps returns all functions of "a" and all functions of "b" in a new function mapping. For entries that are defined in both maps the entry defined in b is chosen.

func RewriteFileAsTemplate

func RewriteFileAsTemplate(filePath string, funcMap template.FuncMap, data any) (err error)

RewriteFileAsTemplate read in a file, execute it as a template with the given data and save the result into the same file.

func WriteTemplateToFile

func WriteTemplateToFile(filePath string, tmpl Template, data any) error

WriteTemplateToFile executes a template with the given data and saves the result into a file.

Types

type Template added in v1.6.1

type Template interface {
	// Execute applies the template to the specified data object and writes the output to the writer.
	Execute(wr io.Writer, data any) (err error)
}

Jump to

Keyboard shortcuts

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