Template definition
Template definition is YAML file located in /.scf/template.yaml
directory of template git repository. It contains template configuration, namely:
- template version - defines version of the template definition file
- template files matchers - identifies all temlate files inside your template git repository using Ant matching pattern
- directory expansions - describes how template directory will be expanded during template execution (e.g. to
_package_
template directory will be replaced withorg/mycompany/myproject
directory) - required templates - specifies on which other templates current template depends on
- variables - defines template variables, which are used in template files, their types and other parameters. Scaffander will use this information to render input form for the user to gather variable values prior to template execution
All sections and even template file itself are optional.
Template definition example
This is sample template.yaml file and its rendered output. All the file blocks will be explained in detail in next sections.
Given template definition will render following generator input form in Scaffander:
version
block
Specifies version
of template definition file. Only version 1.0 is currently supported. Parameter type is string.
templates
block
templates
block is list of Ant matching patterns which identifies all template files inside template directory structure starting from template root directory. Parameter type is list of strings.
The mapping matches files using the following rules:
?
matches one character*
matches zero or more characters**
matches zero or more directories in a path
Ant patern examples:
src/t?st.java
- matches src/test.java but also com/tast.java or com/txst.javasource/*.php
- matches all .php files in the source directorysource/**/test.rb
- matches all test.rb files underneath the source pathace/rimmer/**/*.jsp
- matches all .jsp files underneath the ace/rimmer pathrick/**/gets/schwifty.jsp
- matches rick/gets/schwifty.jsp but also rick/only/gets/schwifty.jsp and rick/and/morty/gets/schwifty.jsp
As an example, you can specify the templates like this:
directoryExpansion
block
This block defines which template directories to expand and how. Directory expansion is a process when given directory is transformed into specified directory path, for example template_directory
is transformed to org/mycompany/subfolder/anothersubfolder
during project generation. Directory expansion is the only block, which can reference variables from variables
block and therefore we can do something like this:
Here you have told Scaffander to use value of package
variable and replace all occurences of .
character in it with /
(directory separator). Then Scaffander looks for all directories named _package_
and expands them according to the resolved value. Let’s assume we have template directory src/main/java/_package_
and package
variable is set to org.quarkus.service
, then output directory will be src/main/java/org/quarkus/service
.
Type of directoryExpansion
block is list of name/value pairs, both name and value are of string type.
requires
block
Requires block defines list of templates on which current template depends. You can even reuse variables from referenced templates in the current template files.
The syntax is following ([]
marks optional blocks):
Example 1
For example, this way you can express that current template depends on maven and readme-md templates:
Example 2
This template depends on maven template, but I want also reference Maven variables in template files as $maven.*. (e.g. ${$maven.version}
expression will be replaced with selected Maven version in template files):
Example 3
You can tell Scaffander that your template requires at least one of the templates, either maven or gradle using pipe |
. Their variables will be referenced as $maven.*
and gradle.*
in the template files as specified below:
In this case Scaffander displays selection dialog when you try to add current template into generator to choose the dependency template.
Example 4
You can even use the same name for dependency template, which means variables of gradle and maven will be merged into single object buildSystem
. This is useful in rare cases when both gradle and maven share same variables, so expression (e. g. ${$buildSystem.version}
will be evaluated as Gradle version when you choose Gradle as build system or Maven version, when you choose Maven:
variables
block
Variables block defines list of variables to be used in template files. Scaffander will generate input form, to gather variable values from the user prior to code generation.
string
variable
Basic input variable, which renders input field for one-line string.
Property | Type | Required | Description |
---|---|---|---|
id |
string | yes | unique identifier of the variable, variable is referenced in template files by its id |
name |
string | yes | name of the variable, which will be rendered in template input form |
type |
string | yes | use string constant |
required |
boolean | no (default false ) |
set to true , when value is mandatory |
pattern |
string | no (empty by default) | regular expression to validate input value |
Example with validation pattern:
Rendered input component and validation example:
text
variable
Basic input variable, which renders textarea field for multi-line string.
Property | Type | Required | Description |
---|---|---|---|
id |
string | yes | unique identifier of the variable, variable is referenced in template files by its id |
name |
string | yes | name of the variable, which will be rendered in template input form |
type |
string | yes | use string constant |
required |
boolean | no (default false ) |
set to true , when value is mandatory |
Example:
Rendered input component with sample data:
choice
variable
Select variable renders group of radion buttons, which allows the user to select one of the values. If the number of options is higher, you can prefer select
variable which renders drop-down list.
Property | Type | Required | Description |
---|---|---|---|
id |
string | yes | unique identifier of the variable, variable is referenced in template files by its id |
name |
string | yes | name of the variable, which will be rendered in template input form |
type |
string | yes | use choice constant |
required |
boolean | no (default false ) |
set to true , when value is mandatory |
options |
choiceOption[] (choice option list) |
no (list is empty by default) | list of name value pairs (see table below) |
choiceOption
type:
Property | Type | Required | Description |
---|---|---|---|
name |
string | no (value is used if not specified) |
option display name |
value |
string | yes | value of the option |
Example usage:
select
variable
select
variable renders dropdown list, which allows the user to select one of the values. It is similar to choice
variable which renders group of radio buttons, but select
should be preferred when number of items is higher.
Property | Type | Required | Description |
---|---|---|---|
id |
string | yes | unique identifier of the variable, variable is referenced in template files by its id |
name |
string | yes | name of the variable, which will be rendered in template input form |
type |
string | yes | use select constant |
required |
boolean | no (default false ) |
set to true , when value is mandatory |
options |
selectOption[] (select option list) |
no (list is empty by default) | list of name value pairs (see table below) |
selectOption
type:
Property | Type | Required | Description |
---|---|---|---|
name |
string | no (value is used if not specified) |
option display name |
value |
string | yes | value of the option |
Example usage:
Scaffander renders this input:
list
variable
List variable allows user to select from multiple options (useful for listing dependecies, extensions etc. for the project). Scaffander renders selection dialog with search capabilities and item categorization to make the selection as easy as possible.
Property | Type | Required | Description |
---|---|---|---|
id |
string | yes | unique identifier of the variable, variable is referenced in template files by its id |
name |
string | yes | name of the variable, which will be rendered in template input form |
type |
string | yes | use list constant |
required |
boolean | no (default false ) |
set to true , when value is mandatory |
items |
listItem[] (list of items) |
no (list is empty by default) | list of listItems (see below) |
listItem
type:
Property | Type | Required | Description |
---|---|---|---|
id |
string | yes | unique identifier of the item |
name |
string | yes | display name of the item |
description |
no | yes | description of the item displayed in selection dialog |
group |
string | no | Specifies both group name and the group identifier. All items within the same group will be displayed under same category in selection dialog |
data |
object | yes | key value pairs, which holds the data of current item, both key and value have string type |
Example usage:
Rendered input (empty selection):
Selection dialog (opened by clicking on Add… button):
Selected values: