Add MoonTera template engine
MoonTera — a MoonBit template rendering engine inspired by Jinja2 and Tera.
Features:
- Variable output with chained filters (13 built-in)
- Conditionals (if/elif/else) with short-circuit evaluation
- For loops with loop.index/first/last/length
- Template inheritance (extends/block, multi-level)
- Macro definitions and calls
- Template includes with context sharing
- Pratt expression parsing (7 precedence levels)
- Unified error types with source location tracking
198 tests, all passing.
Co-Authored-By: Claude noreply@anthropic.com
MoonTera 计划将 Rust 生态的 Tera 模板引擎核心能力移植到 MoonBit 生态,为 Web 后端、静态站点生成器、代码生成器、配置文件渲染等场景提供类型安全、高性能的模板渲染能力。项目基于 MoonBit 的结构化并发与原生性能优势,打造一个语法兼容 Jinja2 风格、功能完整、错误友好的现代化模板引擎。
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
MoonTera — A MoonBit Template Engine
MoonTera is a MoonBit template rendering engine inspired by Jinja2 (Python) and Tera (Rust). It compiles templates into an AST and renders them with a context—fast, safe, and extensible.
Features
{{ name }},{{ user.profile.email }}upper,lower,trim,length,join,replace,default, …{{ text | trim | upper }}{% if %},{% elif %},{% else %},{% endif %}{% for item in list %}withloop.index,loop.first,loop.last{% extends %},{% block %}{% macro name(args) %}...{% endmacro %},{{ name(...) }}{% include "partial.html" %}Quick Start
Installation
Hello World
Using TemplateLoader (with inheritance)
Syntax Guide
Variable Output
Filters
Filters transform values with the
|operator. Chain multiple filters left-to-right.Conditionals
For Loops
Loop variables:
loop.index(1-based),loop.index0(0-based),loop.first,loop.last,loop.length.Template Inheritance
Base (
layout.html):Child:
Macros
Includes
The included template shares the current context.
Comments
Built-in Filters
upper"hi"→"HI"lower"HI"→"hi"capitalize"hi"→"Hi"trim" hi "→"hi"length"abc"→3reverse"abc"→"cba"first"hi"→"h"last"hi"→"i"joinsep[a,b]→"a,b"replacefrom,to"aba"→"axa"defaultval""→"N/A"int"42"→42string42→"42"API Reference
Template
TemplateLoader
Context
Value
Project Structure
Development
License
MIT — see LICENSE