Code templates overview

Template is basically a recipe which uses template files and template parameters as ingredients to define how the final file and folder structure will look like once the template is executed. Template is physically a Git repository linked with Scaffander, which consists of:

  • template definition file (optional) - defines template parameters like input variables or directory expansions located in /.scf/template.yaml
  • template files and folders - can be either static files or files containing FreeMarker markup (tags, directives, interpolations) to parametrize generated files

According to this definition, any Git repository can become a template. But if the template contains only static files without template definition file, the file and folder structure will be used “as is” during generator execution, which is useful only in specific cases. Scaffander allows you to completely parametrize file contents to generate final project structure according your needs. I will explain the details in further chapters.

Simple template structure can look like this:

Template simple scheme

From generator perspective, templates are their basic building blocks. Generators can reuse and combine templates into meaningful technology stack. A good example of such technology stack is company specific Spring project generator, which can consist of Spring project template, Maven Wrapper, Readme.md template and Dockerfile template.

How to create new template

You can create new template if a few step:

  1. Create a new Git repository in your favorite Git provider like GitHub, Bitbucket, etc.
  2. Add template contents - prepare template file and folder structure and the template definition file.
  3. Commit and push the template. If you are using non-versioned template, just commit your changes into master branch. For versioned templates create new version tag.
  4. Add repository URL into add template form. If you want to add a private repository, you must set-up Git provider integration in settings.

Template add form

How to edit template

Updating template is quite simple:

  1. Update template’s Git repository.
  2. Commit and push your changes, for versioned-templates release and push new version tag
  3. Rebuild template in Scaffander - hit the cloud icon (Build icon) in templates overview page.

Scaffander also validates template definition in .scf/template.yaml file during build process (if it is present in the template repository). If template deinition cannot be parsed due to invalid syntax or contraint violation, you can find error details easily by clicking on Build icon message. Scaffander displays detailed error description and the position, where template definition parser stops:

Template loading error

Scaffander supports 2 types of templates:

  • simple templates - easy to use, but any changes in the the template cannot be propagated automatically into generated projects
  • versioned templates - tracks changes between versions, so you can reflect template changes into previously generated projects