Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAppFiltered ¶
NewAppFiltered 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 ImportSpec ¶
type ImportSpec struct {
Name, Path string
}
ImportSpec describes the name and path of an import The name is often omitted
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 SyntaxError ¶
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
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, prior to further action, to answer two questions: // a) that your TypeWriter will write for this Type; return false if your TypeWriter intends not to write a file for this Type at all. // b) that your TypeWriter considers the declaration (i.e., Tags) valid; return err if not. Validate(t Type) (bool, error) // WriteHeader writer to the top of the generated code, before the package declaration; intended for licenses or general documentation. WriteHeader(w io.Writer, t Type) // Imports is a slice of imports required for the type; each will be written into the imports declaration. Imports(t Type) []ImportSpec // WriteBody writes to the body of the generated code, following package declaration, headers and imports. This is the meat. WriteBody(w io.Writer, t Type) }