Documentation ¶
Overview ¶
Package render provides utilities for rendering code using templates.
Writing templates ¶
Codeform makes use of Go's text/template package, it is recommended that you become familiar with Go templates starting with the documentation at https://golang.org/pkg/text/template/.
Using template functions ¶
Template functions are helpers that solve common rendering problems, such as writing a function signature, or listing argument types, etc.
To use a template function, type its name following a pipe character after the item you wish to render. For example, the following template snippet will render all methods using the Signature helper:
{{- range .Methods }} {{ .Name }}Func func({{ . | Signature }} {{- end }}
Template functions ¶
To use the utility functions in the Go template packages, call Funcs passing in render.TemplateFuncs.
template.New("templatename").Funcs(render.TemplateFuncs)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TemplateFuncs = map[string]interface{}{ "ArgList": ArgList, "ArgListNames": ArgListNames, "ArgListTypes": ArgListTypes, "Signature": Signature, "Camel": Camel, }
TemplateFuncs represents codeform utilities for templates.
Functions ¶
func ArgList ¶
ArgList turns model.Args into a Go argument list.
name string, age int, ok bool
Anonymous variables are given a name.
func ArgListNames ¶
ArgListNames turns model.Args into a comma separated list of names.
name, age, ok
Anonymous variables are given a name.
func ArgListTypes ¶
ArgListTypes turns model.Args into a comma separated list of types.
(string, int, bool)
Parentheses will be added for multiple arguments.
Types ¶
This section is empty.