templateutils

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Funcs = template.FuncMap{
	"joinString": strings.Join,

	"json": func(v any) (string, error) {
		buf := new(bytes.Buffer)
		enc := json.NewEncoder(buf)
		if err := enc.Encode(v); err != nil {
			return "", err
		} else {
			return strings.TrimSpace(buf.String()), nil
		}
	},

	"jsonPretty": func(v any) (string, error) {
		buf := new(bytes.Buffer)
		enc := json.NewEncoder(buf)
		enc.SetIndent("", "    ")
		if err := enc.Encode(v); err != nil {
			return "", err
		} else {
			return strings.TrimSpace(buf.String()), nil
		}
	},

	"keyNames": func(keys []core.ResourceKey) (ns []string) {
		for _, k := range keys {
			ns = append(ns, k.Name)
		}
		return
	},

	"fileBase": func(path string) string {
		return filepath.Base(path)
	},

	"fileTrimExt": func(path string) string {
		return strings.TrimSuffix(path, filepath.Ext(path))
	},

	"fileSep": func() string {
		return string(filepath.Separator)
	},

	"replaceAll": func(s string, old string, new string) string {
		return strings.ReplaceAll(s, old, new)
	},
}

Functions

func MustTemplate

func MustTemplate(fs embed.FS, name string) *template.Template

Types

This section is empty.

Jump to

Keyboard shortcuts

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