Documentation
¶
Index ¶
- type AssetProvider
- type Repository
- func (t *Repository) AddFile(name, data string) error
- func (t *Repository) DumpTemplates()
- func (t *Repository) Funcs() template.FuncMap
- func (t *Repository) Get(name string) (*template.Template, error)
- func (t *Repository) LoadContrib(name string, provider AssetProvider) error
- func (t *Repository) LoadDefaults(assets map[string][]byte) error
- func (t *Repository) LoadDir(templatePath string) error
- func (t *Repository) LoadPlugin(pluginPath string) error
- func (t *Repository) MustGet(name string) *template.Template
- func (t *Repository) SetAllowOverride(value bool)
- func (t *Repository) SetProtectedTemplates(m map[string]bool)
- func (t *Repository) ShallowClone() *Repository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssetProvider ¶
AssetProvider provides access to embedded template assets.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository is the repository for the generator templates.
func NewRepository ¶
func NewRepository(funcs template.FuncMap) *Repository
NewRepository creates a new template repository with the provided functions defined.
func (*Repository) AddFile ¶
func (t *Repository) AddFile(name, data string) error
AddFile adds a file to the repository. It will create a new template based on the filename. It trims the .gotmpl from the end and converts the name using swag.ToJSONName. This will strip directory separators and Camelcase the next letter. e.g validation/primitive.gotmpl will become validationPrimitive
If the file contains a definition for a template that is protected the whole file will not be added.
func (*Repository) DumpTemplates ¶
func (t *Repository) DumpTemplates()
DumpTemplates prints out a dump of all the defined templates, where they are defined and what their dependencies are.
func (*Repository) Funcs ¶
func (t *Repository) Funcs() template.FuncMap
Funcs returns the template function map, allowing callers to add or modify functions.
func (*Repository) Get ¶
func (t *Repository) Get(name string) (*template.Template, error)
Get will return the named template from the repository, ensuring that all dependent templates are loaded. It will return an error if a dependent template is not defined in the repository.
func (*Repository) LoadContrib ¶
func (t *Repository) LoadContrib(name string, provider AssetProvider) error
LoadContrib loads template from contrib directory using the given asset provider.
func (*Repository) LoadDefaults ¶
func (t *Repository) LoadDefaults(assets map[string][]byte) error
LoadDefaults loads templates from the given asset map.
func (*Repository) LoadDir ¶
func (t *Repository) LoadDir(templatePath string) error
LoadDir will walk the specified path and add each .gotmpl file it finds to the repository.
func (*Repository) LoadPlugin ¶
func (t *Repository) LoadPlugin(pluginPath string) error
LoadPlugin will load the named plugin and inject its functions into the funcMap
The plugin must implement a function matching the signature: `func AddFuncs(f template.FuncMap)` which can add any number of functions to the template repository funcMap. Any existing sprig or go-swagger templates with the same name will be overridden.
func (*Repository) MustGet ¶
func (t *Repository) MustGet(name string) *template.Template
MustGet a template by name, panics when fails.
func (*Repository) SetAllowOverride ¶
func (t *Repository) SetAllowOverride(value bool)
SetAllowOverride allows setting allowOverride after the Repository was initialized.
func (*Repository) SetProtectedTemplates ¶
func (t *Repository) SetProtectedTemplates(m map[string]bool)
SetProtectedTemplates sets the map of template names that cannot be overridden by user-provided templates.
func (*Repository) ShallowClone ¶
func (t *Repository) ShallowClone() *Repository
ShallowClone a repository.
Clones the maps of files and templates, so as to be able to use the cloned repo concurrently.