目录

MoonTemplate

A Handlebars-style template engine for MoonBit.

Installation

moon add JshsJ/moontemplate

Quick Start

let ctx = [("name", "MoonBit")]
let html = @moontemplate.render_template("Hello {{ name }}!", ctx)
// html == "Hello MoonBit!"

Features

  • Variable interpolation: {{ name }}
  • Raw/unescaped output: {{{ html }}}
  • Conditionals: {{#if show}}visible{{/if}}
  • If/Else: {{#if flag}}yes{{else}}no{{/if}}
  • Loops: {{#each items}}{{ this }}{{/each}}
  • Automatic HTML escaping (safe by default)

API

Function Description
render_template(template, ctx) Parse and render in one call
compile(template) -> AST Compile template to reusable AST
render(ast, ctx) -> String Render a compiled AST with context

Context is an Array[(String, String)] of variable name-value pairs.

License

MIT

关于
232.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号