Template Definitions

The following is an example of a template definition in Sombra Templates, which leverages YAML for flexibility and readability:

---
vars:
  # Define variables that will be used throughout the file
  - project

patterns:
  # A pattern is a set of settings and replacements that apply to all files matching the wildcard
  - pattern: "*"
    # Abstract pattern that defines global replacements but doesn't include files to be generated
    abstract: true
    # Use `default` property to define replacements that will be used for paths, file names, and content alike
    default:
      # A mapping is a key-value set used to search and replace before generating files.
      # The key is searched in the file path, name, or content and replaced with the value
      django-api-template: "{{ .project | kebabcase }}"  # Converts folder names to kebab-case

  # Files with matching patterns will be generated in the target repository
  - pattern: api/*

Template Patterns

Template patterns are structured settings that define how files in a template are transformed when generating new files in the target repository. Each pattern must include a mandatory field called pattern, which specifies a wildcard matching the files the settings will apply to. During file generation, all applicable patterns are combined into three categories:

  • Path: Defines settings for directory paths.
  • Name: Defines settings for filenames.
  • Content: Defines settings for file contents.

This ensures that the structure, naming, and content transformations are consistently applied based on the template definitions.

Pattern Structure

Below is the structure for defining a pattern in Sombra Templates:

The Pattern structure is a key component of Sombra Templates and is defined using YAML to dictate how files are processed during template generation. It includes several fields:

  • Pattern: A string that specifies the wildcard pattern used to match files, and it is required for each template definition.
  • Abstract: A boolean indicating if this pattern is abstract. Abstract patterns do not directly apply to file generation but define global settings or replacements.
  • Verbatim: A boolean indicating the content of any matching file can not be changed. This is useful in the case of legal documents such as licenses.
  • Default: This field contains general mappings used for search-and-replace operations applied across the path, name, and content.
  • Path: Defines specific mappings for directory paths, allowing for targeted changes in folder structures.
  • Name: Contains mappings for filenames, enabling dynamic adjustments during the file generation process.
  • Content: Specifies mappings for the actual content of files, allowing for text-based transformations based on the defined rules.
  • Except: A list of exceptions that specifies which files or patterns should be excluded from this particular pattern.