templatex

package
v0.1.42 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommonInitialisms = map[string]bool{
	"ACL":   true,
	"API":   true,
	"ASCII": true,
	"CPU":   true,
	"CSS":   true,
	"CSV":   true,
	"DNS":   true,
	"EOF":   true,
	"GUID":  true,
	"HTML":  true,
	"HTTP":  true,
	"HTTPS": true,
	"ICMP":  true,
	"ID":    true,
	"IP":    true,
	"JSON":  true,
	"KVK":   true,
	"LHS":   true,
	"PDF":   true,
	"PGP":   true,
	"QPS":   true,
	"QR":    true,
	"RAM":   true,
	"RHS":   true,
	"RPC":   true,
	"SLA":   true,
	"SMTP":  true,
	"SQL":   true,
	"SSH":   true,
	"SVG":   true,
	"TCP":   true,
	"TLS":   true,
	"TTL":   true,
	"UDP":   true,
	"UI":    true,
	"UID":   true,
	"URI":   true,
	"URL":   true,
	"UTF8":  true,
	"UUID":  true,
	"VM":    true,
	"XML":   true,
	"XMPP":  true,
	"XSRF":  true,
	"XSS":   true,
}

CommonInitialisms is a set of common initialisms. Only add entries that are highly unlikely to be non-initialisms. For instance, "ID" is fine (Freudian code is rare), but "AND" is not.

View Source
var GetInitialisms = func() map[string]bool {
	return CommonInitialisms
}

GetInitialisms returns the initialisms to capitalize in Go names. If unchanged, default initialisms will be returned

Functions

func Call added in v0.1.12

func Call(p *types.Func) string

func Dump added in v0.1.12

func Dump(val interface{}) string

func Funcs added in v0.1.12

func Funcs() template.FuncMap

func GenericFuncMap

func GenericFuncMap() ttemplate.FuncMap

func HtmlFuncMap

func HtmlFuncMap() ttemplate.FuncMap

func LcFirst added in v0.1.12

func LcFirst(s string) string

func Render added in v0.1.12

func Render(opts ...Option) error

Render renders a gql plugin template from the given Options. Render is an abstraction of the text/template package that makes it easier to write gqlgen plugins. If Options.Template is empty, the Render function will look for `.gotpl` files inside the directory where you wrote the plugin.

func ToGo added in v0.1.12

func ToGo(name string) string

func ToGoModelName added in v0.1.12

func ToGoModelName(parts ...string) string

func ToGoPrivate added in v0.1.12

func ToGoPrivate(name string) string

func ToGoPrivateModelName added in v0.1.12

func ToGoPrivateModelName(parts ...string) string

func TxtFuncMap

func TxtFuncMap() ttemplate.FuncMap

func TypeIdentifier added in v0.1.12

func TypeIdentifier(t types.Type) string

func UcFirst added in v0.1.12

func UcFirst(s string) string

Types

type Import added in v0.1.12

type Import struct {
	Name  string
	Path  string
	Alias string
}

func (*Import) String added in v0.1.12

func (i *Import) String() string

type Imports added in v0.1.12

type Imports struct {
	// contains filtered or unexported fields
}
var CurrentImports *Imports

CurrentImports keeps track of all the import declarations that are needed during the execution of a plugin. this is done with a global because subtemplates currently get called in functions. Lets aim to remove this eventually.

func (*Imports) Lookup added in v0.1.12

func (s *Imports) Lookup(path string) string

func (*Imports) LookupType added in v0.1.12

func (s *Imports) LookupType(t types.Type) string

func (*Imports) Reserve added in v0.1.12

func (s *Imports) Reserve(path string, aliases ...string) (string, error)

func (*Imports) String added in v0.1.12

func (s *Imports) String() string

type Option added in v0.1.12

type Option func(*Options)

func WithAuthor added in v0.1.23

func WithAuthor(author string) Option

func WithData added in v0.1.23

func WithData(data interface{}) Option

func WithDefaultImports added in v0.1.26

func WithDefaultImports(path string, aliases ...string) Option

func WithFileNotice added in v0.1.23

func WithFileNotice(notice string) Option

func WithFilename added in v0.1.23

func WithFilename(filename string) Option

func WithFuncs added in v0.1.23

func WithFuncs(funcs template.FuncMap) Option

func WithGeneratedHeader added in v0.1.23

func WithGeneratedHeader(generatedHeader bool) Option

func WithPackageDoc added in v0.1.23

func WithPackageDoc(doc string) Option

func WithPackageName added in v0.1.23

func WithPackageName(name string) Option

func WithPackages added in v0.1.23

func WithPackages(pkgs *code.Packages) Option

func WithRegionTags added in v0.1.23

func WithRegionTags() Option

func WithTemplate added in v0.1.23

func WithTemplate(template string) Option

func WithTemplateFS added in v0.1.23

func WithTemplateFS(fs fs.FS) Option

func WithTemplatePatterns added in v0.1.23

func WithTemplatePatterns(patterns []string) Option

func WithTemplateSelector added in v0.1.24

func WithTemplateSelector(selector func(string) bool) Option

type Options added in v0.1.12

type Options struct {
	// PackageName is a helper that specifies the package header declaration.
	// In other words, when you write the template you don't need to specify `package X`
	// at the top of the file. By providing PackageName in the Options, the Render
	// function will do that for you.
	PackageName string
	// Template is a string of the entire template that
	// will be parsed and rendered. If it's empty,
	// the plugin processor will look for .gotpl files
	// in the same directory of where you wrote the plugin.
	Template string

	// Use the go:embed API to collect all the template files you want to pass into Render
	// this is an alternative to passing the Template option
	TemplateFS fs.FS

	// Filename is the name of the file that will be
	// written to the system disk once the template is rendered.
	Filename        string
	RegionTags      bool
	GeneratedHeader bool
	Author          string
	// PackageDoc is documentation written above the package line
	PackageDoc string
	// FileNotice is notice written below the package line
	FileNotice string
	// Data will be passed to the template execution.
	Data  interface{}
	Funcs template.FuncMap

	// TemplateSelector is a function that determines whether or not to render the template.
	TemplateSelector func(string) bool

	// Packages cache, you can find me on config.Config
	Packages *code.Packages

	TemplatePatterns []string

	DefaultImports []Import
}

Options specify various parameters to rendering a template.

Jump to

Keyboard shortcuts

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