template

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Funcs are the predefined template
	// functions used by the codegen.
	Funcs = template.FuncMap{
		"base":            filepath.Base,
		"dict":            dict,
		"toLower":         toLower,
		"toFirstCap":      toFirstCap,
		"toSnakeCase":     stringutil.ToSnakeCase,
		"stringReplace":   strings.Replace,
		"stringHasPrefix": strings.HasPrefix,
		"sub":             sub,
		"joinStrings":     joinStrings,
	}
)

Functions

func Dir

func Dir(s string) func(t TemplatePathFormat) string

Types

type FileTemplate

type FileTemplate[T any] struct {
	Name   string
	Format func(TemplatePathFormat) string
	Skip   func(*T) bool
}

type FuncMap

type FuncMap = template.FuncMap

type Template

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

func MustParse

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

一个辅助函数,用于封装对返回(*Template, error)的调用,如果err不为空,则panic

func NewTemplate

func NewTemplate(name string) *Template

func (*Template) AddParseTree

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

AddParseTree adds the given parse tree to the template.

func (*Template) Funcs

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

Funcs 把funcMap中的函数添加到模版中

func (*Template) ParseDir

func (t *Template) ParseDir(path string) (*Template, error)

ParseDir 解析目录下的所有文件

func (*Template) ParseFS

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

func (*Template) ParseFiles

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

ParseFiles 解析文件

func (*Template) ParseGlob

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

ParseGlob 解析glob模式下的文件

type TemplatePathFormat

type TemplatePathFormat interface {
	Dir() string
}

Jump to

Keyboard shortcuts

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