Creating Templates
Learn how to build powerful Skela templates
Creating Templates
A Template in Skela is a directory that contains:
- A
skela.yamlconfiguration file. - Source files to be copied and rendered.
# Structure
my-template/
├── skela.yaml
├── README.md
├── .gitignore
└── src/
└── main.go
# The Scaffold File
The skela.yaml file is the heart of your template. It defines:
- Metadata: Name of the template.
- Target: Where the project should be generated.
- Variables: Inputs to collect from the user.
- Steps: Actions to run after file generation.
Example:
name: Go CLI Tool
target: "{{ projectPath }}"
variables:
- name: moduleName
kind: go-module
prompt: Module name?
steps:
- kind: go-tidy
# Templating Engine
Skela processes all files in the template directory (except skela.yaml) using the Pongo2 engine (Django-like syntax). This means you can use the variables you defined in skela.yaml directly in your code.
# Using Variables
If you defined a variable named moduleName, you can use it like this:
package main
import "fmt"
func main() {
fmt.Println("Hello from {{ moduleName }}!")
}
# File Names
You can also use variables in file and directory names. For example, a file named cmd/{{ binaryName }}/main.go will be renamed based on the user's input.