templates

package
v0.0.0-...-fc4761b Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateFunctions = TemplateFuncs{
	"stringFuncs": func(funcName string) func(string) string {
		return templateStringMappers[funcName]
	},

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

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

	"titleCase": strmangle.TitleCase,
	"camelCase": strmangle.CamelCase,
	"snakeCase": strcase.ToSnake,
	"ignore":    strmangle.Ignore,

	"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,

	"parseEnumName":       strmangle.ParseEnumName,
	"parseEnumVals":       strmangle.ParseEnumVals,
	"isEnumNormal":        strmangle.IsEnumNormal,
	"stripWhitespace":     strmangle.StripWhitespace,
	"shouldTitleCaseEnum": strmangle.ShouldTitleCaseEnum,
	"onceNew":             newOnce,
	"oncePut":             Once.Put,
	"onceHas":             Once.Has,

	"makeStringMap": strmangle.MakeStringMap,

	"setInclude": strmangle.SetInclude,

	"whereClause": strmangle.WhereClause,

	"usesPrimitives": usesPrimitives,
	"isPrimitive":    isPrimitive,
	"isBuiltin":      isBuiltin,

	"filterColumnsByAuto":    database.FilterColumnsByAuto,
	"filterColumnsByDefault": database.FilterColumnsByDefault,
	"filterColumnsByEnum":    database.FilterColumnsByEnum,
	"sqlColDefinitions":      database.SQLColDefinitions,
	"columnNames":            database.ColumnNames,
	"columnDBTypes":          database.ColumnDBTypes,
	"getTable":               database.GetTable,

	"go":          ToGo,
	"goPrivate":   ToGoPrivate,
	"prefixLines": prefixLines,

	"modelTypeAsText": getModelTypeAsText,
}

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 DenormalizeSlashes

func DenormalizeSlashes(path string) string

DenormalizeSlashes takes any backslashes and converts them to linux style slashes

func FindTemplates

func FindTemplates(root, base string) (map[string]TemplateLoader, error)

FindTemplates uses a root path: (/home/user/gopath/src/../sqlboiler/) and a base path: /templates to create a bunch of file loaders of the form: templates/00_struct.tpl -> /absolute/path/to/that/file Note the missing leading slash, this is important for the --replace argument

func LcFirst

func LcFirst(s string) string

func NormalizeSlashes

func NormalizeSlashes(path string) string

NormalizeSlashes takes a path that was made on linux or windows and converts it to a native path.

func Render

func Render(opts Options) error

func RenderSingleton

func RenderSingleton(opts Options) error

func ToGo

func ToGo(name string) string

func ToGoPrivate

func ToGoPrivate(name string) string

func UcFirst

func UcFirst(s string) string

Types

type AssetLoader

type AssetLoader string

func (AssetLoader) Load

func (a AssetLoader) Load() ([]byte, error)

func (AssetLoader) MarshalText

func (a AssetLoader) MarshalText() ([]byte, error)

func (AssetLoader) String

func (a AssetLoader) String() string

type Base64Loader

type Base64Loader string

func (Base64Loader) Load

func (b Base64Loader) Load() ([]byte, error)

func (Base64Loader) MarshalText

func (b Base64Loader) MarshalText() ([]byte, error)

func (Base64Loader) String

func (b Base64Loader) String() string

type FileLoader

type FileLoader string

func (FileLoader) Load

func (f FileLoader) Load() ([]byte, error)

func (FileLoader) MarshalText

func (f FileLoader) MarshalText() ([]byte, error)

func (FileLoader) String

func (f FileLoader) String() string

type LazyTemplate

type LazyTemplate struct {
	Name   string         `json:"name"`
	Loader TemplateLoader `json:"loader"`
}

type LazyTemplates

type LazyTemplates []LazyTemplate

func LoadTemplates

func LoadTemplates(templateDir []string, assetPrefix string) (LazyTemplates, error)

func (*LazyTemplates) AppendBase64Templates

func (lt *LazyTemplates) AppendBase64Templates(base64Templates map[string]string)

func (LazyTemplates) Replacements

func (lt LazyTemplates) Replacements(replacements []string) error

type Once

type Once map[string]struct{}

set is to stop duplication from named enums, allowing a template loop to keep some state

func (Once) Has

func (o Once) Has(s string) bool

func (Once) Put

func (o Once) Put(s string) bool

type Options

type Options struct {
	Filename          string
	OutFolder         string
	NoGeneratedHeader bool
	PkgName           string
	Data              interface{}

	Wipe          bool
	Templates     []LazyTemplate
	TemplateFuncs TemplateFuncs

	ImportSet      importers.Set
	ImportNamedSet importers.Map

	IsTest      bool
	IsSingleton bool
}

type TemplateFuncs

type TemplateFuncs template.FuncMap

func (TemplateFuncs) Append

func (f TemplateFuncs) Append(funcMap template.FuncMap)

func (TemplateFuncs) AppendFunc

func (f TemplateFuncs) AppendFunc(name string, fn interface{})

type TemplateList

type TemplateList struct {
	*template.Template
}

func ParseTemplates

func ParseTemplates(lazyTemplates []LazyTemplate, testTemplates bool, funcMap TemplateFuncs) (*TemplateList, error)

func (TemplateList) Templates

func (t TemplateList) Templates() []string

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

type TemplateLoader

type TemplateLoader interface {
	encoding.TextMarshaler
	Load() ([]byte, error)
}

type TemplateLoaderMap

type TemplateLoaderMap map[string]TemplateLoader

Jump to

Keyboard shortcuts

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