Template Engine
Scaffold uses the Go template engine to generate files. The following variables are available to use in your templates at a top level:
Project- The name of the projectProjectKebab- The kebab case version of the project nameProjectSnake- The snake case version of the project nameProjectCamel- The camel case version of the project nameProjectPascal- The pascal case version of the project nameScaffold- a map of the scaffold questions and answersComputed- a map of computed values as defined in the scaffolds configuration
Template Function
The templates also make available the sprout library of functions. See the sprout documentation for more information.
We also provide the following functions that help with rendering templates:
wraptmpl
Wraps a string in {{ and }} so it can be used as a template. This can also be accomplished by escaping the template syntax. For example, {{ "{{ .Project }}" }} will render as {{ .Project }}.
`{{ wraptmpl "docker_dir" }}` -> `{{ "docker_dir" }}`
vs
`{{ "{{ docker_dir }}" }}` -> `{{ docker_dir }}`
isPlural
Returns a boolean, true if the input is plural, false otherwise.
`{{ isPlural "apple" }}` -> `false`
`{{ isPlural "apples" }}` -> `true`
isSingular
Returns a boolean, true if the input is singular, false otherwise.
`{{ isSingular "apple" }}` -> `true`
`{{ isSingular "apples" }}` -> `false`
toPlural
Converts a singular word to its plural form.
`{{ toPlural "apple" }}` -> `apples`
toSingular
Converts a plural word to its singular form.
`{{ toSingular "apples" }}` -> `apple`
Engine Rules
The template process also uses the following rules for rendering:
- Empty files are skipped.
- Template files that are empty after rendering are not included in the generated project.
- Empty directories not included in the generated project