tmpl

package
v0.0.0-...-3948e75 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package tmpl provides code generation from pure Go templates.

Index

Constants

This section is empty.

Variables

View Source
var (
	FileSystemLoader = LoaderFunc(ioutil.ReadFile)
	Default          = Environment{Loader: FileSystemLoader}
)

Functions

This section is empty.

Types

type Environment

type Environment struct {
	Loader Loader
}

func (Environment) Load

func (e Environment) Load(name string) (*Template, error)

func (Environment) Package

func (e Environment) Package(names ...string) (*Package, error)

type Loader

type Loader interface {
	Load(name string) ([]byte, error)
}

Loader is a method of loading templates.

func NewBasePath

func NewBasePath(loader Loader, path string) Loader

NewBasePath restricts the given loader to a given path.

type LoaderFunc

type LoaderFunc func(name string) ([]byte, error)

LoaderFunc adapts a function to the Loader interface.

func (LoaderFunc) Load

func (l LoaderFunc) Load(name string) ([]byte, error)

Load calls l.

type Package

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

func NewPackage

func NewPackage() *Package

func (*Package) AddFile

func (p *Package) AddFile(name string, src []byte) error

func (*Package) Apply

func (p *Package) Apply(transforms ...Transform) error

Apply transforms to an entire package.

func (*Package) Template

func (p *Package) Template(name string) (*Template, bool)

Template returns a template for the named file.

func (*Package) Templates

func (p *Package) Templates() map[string]*Template

type Template

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

func ParseFile

func ParseFile(filename string, src []byte) (*Template, error)

func (*Template) Apply

func (t *Template) Apply(transforms ...Transform) error

func (*Template) Bytes

func (t *Template) Bytes() ([]byte, error)

func (*Template) Format

func (t *Template) Format(w io.Writer) error

func (*Template) Node

func (t *Template) Node() ast.Node

type Transform

type Transform interface {
	Transform(ast.Node) (ast.Node, error)
}

func CommentReplace

func CommentReplace(old, new string) Transform

func DefineBool

func DefineBool(name string, value bool) Transform

func DefineIntDecimal

func DefineIntDecimal(name string, value int) Transform

func DefineIntHex

func DefineIntHex(name string, value int) Transform

func DefineLiteral

func DefineLiteral(name string, kind token.Token, value string) Transform

func DefineLiteralf

func DefineLiteralf(name string, kind token.Token, format string, args ...interface{}) Transform

func DefineString

func DefineString(name, value string) Transform

func GeneratedBy

func GeneratedBy(by string) Transform

GeneratedBy replaces the string "CodeGenerationWarning" in comments with a standard code generation warning. This is a special case of the CommentReplace transform.

func Preprocessor

func Preprocessor() Transform

func Rename

func Rename(from, to string) Transform

func SetPackageName

func SetPackageName(name string) Transform

Jump to

Keyboard shortcuts

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