Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAppFiltered ¶
NewAppNewAppFiltered parses the current directory, collecting Types and their related information. Pass a filter to limit which files are operated on.
func Register ¶
func Register(tw TypeWriter) error
Register allows template packages to make themselves known to a 'parent' package, usually in the init() func. Comparable to the approach taken by builtin image package for registration of image types (eg image/png). Your program will do something like:
import ( "github.com/clipperhouse/gen/typewriter" _ "github.com/clipperhouse/gen/typewriters/container" )
Types ¶
type Package ¶
func NewPackage ¶
type Pointer ¶
type Pointer bool
Pointer exists as a type to allow simple use as bool or as String, which returns *
type Tag ¶
type Tag struct { Name string Items []string Negated bool // contains filtered or unexported fields }
+gen methods:"Where"
type Tags ¶
type Tags []Tag
Tags is a slice of type Tag, for use with gen methods below. Use this type where you would use []Tag. (This is required because slices cannot be method receivers.)
type Template ¶
type Template struct { Text string RequiresNumeric bool // A comparable type is one that supports the == operator. Map keys must be comparable, for example. RequiresComparable bool // An ordered type is one where greater-than and less-than are supported RequiresOrdered bool }
Template includes the text of a template as well as requirements for the types to which it can be applied.
func (Template) ApplicableTo ¶
type TemplateSet ¶
TemplateSet is a map of string names to Template.
func (TemplateSet) Contains ¶
func (ts TemplateSet) Contains(name string) bool
Contains returns true if the TemplateSet includes a template of a given name.
func (TemplateSet) Get ¶
func (ts TemplateSet) Get(name string) (t *template.Template, err error)
Get attempts to 1) locate a tempalte of that name and 2) parse the template Returns an error if the template is not found, and panics if the template can not be parsed (per text/template.Must)
func (TemplateSet) GetAllKeys ¶
func (ts TemplateSet) GetAllKeys() (result []string)
GetAllKeys returns a slice of all 'exported' key names of templates in the TemplateSet
type Type ¶
type Type struct { Package *Package Pointer Pointer Name string Tags Tags types.Type // contains filtered or unexported fields }
func (*Type) Comparable ¶
type TypeWriter ¶
type TypeWriter interface { Name() string // Validate is called for every Type to a) indicate that it will write for this Type and b) ensure that the TypeWriter considers it valid Validate(t Type) (bool, error) // WriteHeader writer to the top of the generated code, befoe the package declaration; intended for licenses. WriteHeader(w io.Writer, t Type) // Imports is a slice of import paths required for the type. Imports(t Type) []string // Write writes to the body of the generated code. This is the meat. Write(w io.Writer, t Type) }