render

package
v0.0.0-...-02fd228 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2017 License: GPL-3.0 Imports: 3 Imported by: 0

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

View Source
var TemplateFuncs = map[string]interface{}{
	"ArgList":      ArgList,
	"ArgListNames": ArgListNames,
	"ArgListTypes": ArgListTypes,
	"Signature":    Signature,
	"Camel":        Camel,
}

TemplateFuncs represents codeform utilities for templates.

Functions

func ArgList

func ArgList(args model.Args) string

ArgList turns model.Args into a Go argument list.

name string, age int, ok bool

Anonymous variables are given a name.

func ArgListNames

func ArgListNames(args model.Args) string

ArgListNames turns model.Args into a comma separated list of names.

name, age, ok

Anonymous variables are given a name.

func ArgListTypes

func ArgListTypes(args model.Args) string

ArgListTypes turns model.Args into a comma separated list of types.

(string, int, bool)

Parentheses will be added for multiple arguments.

func Camel

func Camel(s string) string

Camel turns a string into camel case.

func Signature

func Signature(fn model.Func) string

Signature gets the function arguments and return arguments as a string.

(name string, age int) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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