template

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFuncs = FuncMap{
	"toUpper": strings.ToUpper,
	"toLower": strings.ToLower,
	"title": func(text string) string {

		return cases.Title(language.AmericanEnglish).String(text)
	},
	"trimSpace": strings.TrimSpace,

	"join": func(sep string, s []string) string {
		return strings.Join(s, sep)
	},
	"match": regexp.MatchString,
	"reReplaceAll": func(pattern, repl, text string) string {
		re := regexp.MustCompile(pattern)
		return re.ReplaceAllString(text, repl)
	},
	"stringSlice": func(s ...string) []string {
		return s
	},

	"date": func(fmt string, t time.Time) string {
		return t.Format(fmt)
	},

	"tz": func(name string, t time.Time) (time.Time, error) {
		loc, err := time.LoadLocation(name)
		if err != nil {
			return time.Time{}, err
		}
		return t.In(loc), nil
	},
	"since": time.Since,
	"last": func(index int, slice interface{}) bool {
		v := reflect.ValueOf(slice)
		return index == v.Len()-1
	},
}

Functions

This section is empty.

Types

type FuncMap

type FuncMap map[string]any

type Option

type Option func(tmpl *template.Template)

type Template

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

func FromGlobs

func FromGlobs(paths []string, options ...Option) (*Template, error)

func (*Template) Execute

func (t *Template) Execute(name string, data interface{}) (string, error)

func (*Template) FromGlob

func (t *Template) FromGlob(path string) error

func (*Template) Parse

func (t *Template) Parse(r io.Reader) error

Jump to

Keyboard shortcuts

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