templatex

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: MIT Imports: 9 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTemplateFuncMap = template.FuncMap{
	"toCamel":              str.ToCamel,
	"toLowerCamel":         str.ToLowerCamel,
	"toSnake":              str.ToSnake,
	"toKebab":              str.ToKebab,
	"toScreamingKebab":     str.ToScreamingKebab,
	"toDelimited":          str.ToDelimited,
	"toScreamingDelimited": str.ToScreamingDelimited,
	"toSnakeWithIgnore":    str.ToSnakeWithIgnore,
	"lower":                strings.ToLower,
	"upper":                strings.ToUpper,
	"replace":              strings.ReplaceAll,
	"hasPrefix":            strings.HasPrefix,
	"hasSuffix":            strings.HasSuffix,
	"split":                strings.Split,
	"toString":             str.ToString,
	"join":                 strings.Join,
	"quote":                strconv.Quote,
	"ucFirst":              str.UcFirst,
	"lcFirst":              str.LcFirst,
	"trim":                 strings.Trim,
	"trimLeft":             strings.TrimLeft,
	"trimRight":            strings.TrimRight,
	"trimSpace":            strings.TrimSpace,
	"trimPrefix":           strings.TrimPrefix,
	"trimSuffix":           strings.TrimSuffix,
	"contains":             strings.Contains,
}

Functions

This section is empty.

Types

type Template

type Template struct {
	*template.Template
	FuncMap template.FuncMap
}

func Must

func Must(t *Template, err error) *Template

func New

func New(name string) *Template

New returns a new template with the functions in the FuncMap.

func (*Template) AddParseTree

func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error)

AddParseTree adds the argument parsetree to the template definition

func (*Template) ExecuteTemplateToFile

func (t *Template) ExecuteTemplateToFile(name string, file string, overwrite bool, data any) error

ExecuteTemplateToFile executes a template with the given name and writes the output to a file. if Overwrite is true, the file will be overwritten if it exists.

func (*Template) ExecuteToFile

func (t *Template) ExecuteToFile(file string, overwrite bool, data any) error

ExecuteToFile executes the template to file, if overwrite is true, the file will be overwritten if it exists.

func (*Template) Funcs

func (t *Template) Funcs(funcMap template.FuncMap) *Template

Funcs adds the elements of the argument map to the template's functionx map.

func (*Template) Parse

func (t *Template) Parse(text string) (*Template, error)

Parse parses text as a template body for t.

func (*Template) ParseFS

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

ParseFS parses the files in the embedded filesystem. returns an error if any of the files fail to parse.

func (*Template) ParseFiles

func (t *Template) ParseFiles(filenames ...string) (*Template, error)

ParseFiles creates a new Template and parses the template definitions from the named files. if any file contains an error, the first such error is returned and the rest are ignored.

func (*Template) ParseGlob

func (t *Template) ParseGlob(pattern string) (*Template, error)

ParseGlob parses the template definitions in the files identified by pattern

func (*Template) ParseReader

func (t *Template) ParseReader(r io.Reader) (*Template, error)

ParseReader parses text read from reader and adds the results to the template.

Jump to

Keyboard shortcuts

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