MiniTPL is a lightweight MoonBit template toolkit for configuration generation,
document generation, and code snippet generation.
Besides basic variable replacement, it provides variable extraction, template
static checks, and missing-variable diagnostics so templates can be validated
early in CI or build workflows.
Features
Basic {{name}} variable replacement with render.
Trims whitespace around variable names, such as {{ name }}.
Leniently renders missing variables as an empty string.
Extracts template variables in source order with extract_vars.
Statically checks templates with lint.
Diagnoses empty variable names.
Diagnoses unclosed placeholders.
Diagnoses missing variables.
Has no external dependencies.
Installation And Running
Make sure MoonBit is installed and available in your terminal:
moon version
Format, check, test, and build the project:
moon fmt
moon check
moon test
moon build
Run the example command:
moon run cmd/main
Expected output:
Hello MiniTPL! You are 5 years old.
Run the English example:
moon run examples/english
Expected output:
Hello MoonBit developer, welcome to MiniTPL.
Run the Chinese example:
moon run examples/chinese
Expected output:
你好,MoonBit 开发者!欢迎使用 MiniTPL。
CI
GitHub Actions runs project checks, tests, and builds on push and pull request.
For local development, run moon fmt before committing MoonBit source changes.
MiniTPL
MiniTPL is a lightweight MoonBit template toolkit for configuration generation, document generation, and code snippet generation.
Besides basic variable replacement, it provides variable extraction, template static checks, and missing-variable diagnostics so templates can be validated early in CI or build workflows.
Features
{{name}}variable replacement withrender.{{ name }}.extract_vars.lint.Installation And Running
Make sure MoonBit is installed and available in your terminal:
Format, check, test, and build the project:
Run the example command:
Expected output:
Run the English example:
Expected output:
Run the Chinese example:
Expected output:
CI
GitHub Actions runs project checks, tests, and builds on push and pull request. For local development, run
moon fmtbefore committing MoonBit source changes.Publishing
MiniTPL is published to mooncakes.io as:
joanna/minitpl@0.1.2Package page:
https://mooncakes.io/docs/joanna/minitpl@0.1.2
API Example
Output:
Extract variables from a template:
The result is
["name", "age"]. Variable names are trimmed, order is preserved, and repeated variables are kept.Lint a template before rendering:
The result is
["missing variable: tool"].Missing Variables
If a variable name does not exist in the provided keys, MiniTPL renders that variable as an empty string.
For example,
Hello {{name}}!with nonamevalue becomesHello !.Current Limitations
{{name}}placeholder rendering is supported.if,each, filters, and nested data are not supported yet.Roadmap
License
This project is licensed under the Apache License 2.0. See LICENSE for details.