chore: add CI config and prepare for release
- Add GitHub Actions CI workflow (check, test, build CLI)
- Update .gitignore: add _build/, *.wasm, *.core, *.mi
- Add CI status badge to README
- Add CLI tool usage section to README
- Ready for mooncakes.io publishing
Co-Authored-By: Claude noreply@anthropic.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
MoonTera — A Jinja2/Tera-inspired Template Engine for MoonBit
MoonTera is a fast, safe, and easy-to-use template rendering engine for MoonBit, inspired by Jinja2 and Tera.
Features
{{ user.name }}with dot access and index access{{ name | upper | trim }}with 13 built-in filters{% if %},{% elif %},{% else %},{% endif %}{% for x in items %}...{% endfor %}withloop.index,loop.first, etc.{% macro button(text, class) %}...{% endmacro %}{% include "partial.html" %}{% extends %},{% block %},{% endblock %}(planned)moonbitlang/coreQuick Start
Installation
Hello World
Complete Example
Syntax Guide
Variables
Output variables with
{{ }}:Filters
Apply filters with the pipe operator
|:Conditionals
Loops
loopbuiltin variables:loop.indexloop.index0loop.firsttrueon the first iterationloop.lasttrueon the last iterationloop.lengthMacros
Define reusable template fragments:
Includes
Include another template:
Templates are loaded via
TemplateLoader:Template Inheritance (planned)
Comments
Built-in Filters
upper"hello"→"HELLO"lower"HELLO"→"hello"capitalize"hello"→"Hello"trim" hi "→"hi"length"abc"→3reverse"abc"→"cba"first"abc"→"a"last"abc"→"c"join(sep)[a,b]→"a,b"replace(from, to)default(val)intstringCustom Filters
API Reference
Templateparse(source: String) → Result[Template, TemplateError]render(ctx: Context) → Result[String, TemplateError]render_with_loader(ctx: Context, loader: TemplateLoader) → Result[String, TemplateError]Contextnew()new_child(parent)set(name, value)get(name)register_macro(MacroDef)ValueNullBool(Bool)Int(Int64)Float(Double)Str(String)Array(Array[Value])Object(Map[String, Value])TemplateErrorUnified error type with source location:
CLI Tool
MoonTera includes a command-line tool for quick template rendering:
render "<tpl>" [--data '<json>']check "<tpl>"--version--helpThe
--dataargument accepts a JSON object whose top-level keys become template context variables.Project Structure
Examples
See the
examples/directory:hello.mbt— Minimal Hello Worldblog.mbt— Blog page with loops and conditionalsemail.mbt— Email template with macros and includesDevelopment
Running Tests
Project Status
License
MIT License. See LICENSE for details.