gen

package
v0.0.0-...-98c8ee3 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateFunctions = template.FuncMap{

	"quoteWrap": func(s string) string { return fmt.Sprintf(`"%s"`, s) },
	"id":        strmangle.Identifier,

	"singular": strmangle.Singular,
	"plural":   strmangle.Plural,

	"titleCase":           strmangle.TitleCase,
	"titleCaseIdentifier": strmangle.TitleCaseIdentifier,
	"camelCase":           strmangle.CamelCase,

	"join":               func(sep string, slice []string) string { return strings.Join(slice, sep) },
	"joinSlices":         strmangle.JoinSlices,
	"stringMap":          strmangle.StringMap,
	"prefixStringSlice":  strmangle.PrefixStringSlice,
	"containsAny":        strmangle.ContainsAny,
	"generateTags":       strmangle.GenerateTags,
	"generateIgnoreTags": strmangle.GenerateIgnoreTags,

	"makeStringMap": strmangle.MakeStringMap,

	"import":  templateImport,
	"goType":  templateGoType,
	"typesGo": templateTypesGo,

	"setInclude":    strmangle.SetInclude,
	"setComplement": strmangle.SetComplement,

	"whereClause": strmangle.WhereClause,

	"sqlColDefinitions": schema.SQLColDefinitions,
	"columnNames":       schema.ColumnNames,
	"getModel":          schema.GetModel,

	"quotes": func(s string) string {
		d := Config.Dialect
		lq := strmangle.QuoteCharacter(d.LQ)
		rq := strmangle.QuoteCharacter(d.RQ)

		return fmt.Sprintf("%s%s%s", lq, s, rq)
	},
	"schemaModel": func(model string) string {
		d := Config.Dialect
		lq := strmangle.QuoteCharacter(d.LQ)
		rq := strmangle.QuoteCharacter(d.RQ)
		return strmangle.SchemaModel(lq, rq, model)
	},
	"hook": hook,
}

TemplateFunctions is a map of all the functions that get passed into the templates. If you wish to pass a new function into your own template, add a function pointer here.

Functions

func AddCommand

func AddCommand(cmds ...*cobra.Command)

func BaseTemplateData

func BaseTemplateData() map[string]interface{}

func OnGen

func OnGen(f func())

func OnHook

func OnHook(name string, f HookFunc)

func Run

func Run(items []ConfigItem)

func WriteFile

func WriteFile(outFolder string, fileName string, code []byte)

WriteFile writes to the given folder and filename, formatting the buffer given.

func WriteFileDisclaimer

func WriteFileDisclaimer(out *bytes.Buffer)

WriteFileDisclaimer writes the disclaimer at the top with a trailing newline so the package name doesn't get attached to it.

func WriteImports

func WriteImports(out *bytes.Buffer, imports map[string]string)

WriteImports writes the import list, ignores errors since it's to the concrete buffer type which produces none

func WritePackageName

func WritePackageName(out *bytes.Buffer, pkgName string)

WritePackageName writes the package name correctly, ignores errors since it's to the concrete buffer type which produces none

Types

type ConfigItem

type ConfigItem interface {
	IsConfigItem()
}

type ConfigStruct

type ConfigStruct struct {
	Items  []ConfigItem
	Schema *schema.Schema

	Dialect queries.Dialect

	OutputPath        string
	ModelsPackageName string
}
var Config *ConfigStruct

func (*ConfigStruct) ModelsOutputPath

func (c *ConfigStruct) ModelsOutputPath() string

type HookFunc

type HookFunc func(buf *bytes.Buffer, data map[string]interface{}, args ...interface{})

type Plugin

type Plugin interface {
	IsConfigItem()
	BunnyPlugin()
}

type TemplateList

type TemplateList struct {
	*template.Template
}

func LoadTemplate

func LoadTemplate(pkg string, path string) (*TemplateList, error)

LoadTemplate loads a single template file

func LoadTemplates

func LoadTemplates(pkg string, path string) (*TemplateList, error)

LoadTemplates loads all of the template files in the specified directory.

func MustLoadTemplate

func MustLoadTemplate(pkg string, path string) *TemplateList

func MustLoadTemplates

func MustLoadTemplates(pkg string, path string) *TemplateList

func (*TemplateList) Execute

func (t *TemplateList) Execute(data map[string]interface{}, filename string)

func (*TemplateList) ExecuteBuf

func (t *TemplateList) ExecuteBuf(data map[string]interface{}, buf *bytes.Buffer)

func (*TemplateList) ExecuteSingleton

func (t *TemplateList) ExecuteSingleton(data map[string]interface{})

func (TemplateList) Templates

func (t TemplateList) Templates() []string

Templates returns the name of all the templates defined in the template list

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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