kBars¶
kBars is a Kotlin Multiplatform template processor, in the tradition of
Mustache, Handlebars.js, and
Liquid. It compiles a template string once and renders it
against any number of contexts, combining Mustache/Handlebars-style tags ({{ }}, {{#each}},
{{#if}}, {{> partial }}) with a Liquid-style transform pipeline ({{ name | upcase }}).
Supports JVM, Android, iOS, Linux, JavaScript, and WebAssembly targets (see each module for its exact target list).
Modules¶
| Module | What it does | API Docs | Source |
|---|---|---|---|
kbars |
The template processor: parser, renderer, and ~40 built-in transforms. Depends only on kpointer-adapter — no JSON or YAML library required. |
API | Codeberg |
kbars-kxs |
KbEnvironment.from(json: String) — drive kBars from raw JSON text via kotlinx.serialization. |
API | Codeberg |
kbars-yamlkt |
KbEnvironment.fromYaml(yaml: String) — drive kBars from raw YAML text via YamlKt. |
API | Codeberg |
kbars-conformance |
Conformance fixture runner and test infrastructure (not published). | — | Codeberg |
cli |
Command-line tool (kbars binary) for rendering templates and running the conformance suite. |
— | Codeberg |
If you only have a KpaStruct context already in hand, depend on kbars alone. If you're starting
from JSON or YAML text, pick kbars-kxs or kbars-yamlkt — each pulls in kbars transitively.
A minimal example¶
val env = kbEnvironment.from("""{"name":"Alice"}""")
val template = kbTemplate.create("Hello {{ /name }}!")
println(template.render(env)) // "Hello Alice!"
Where to next¶
- Writing templates — the template language, start to finish, if you're authoring templates.
- Template basics — text, interpolation delimiters, comments, raw blocks, and whitespace trimming.
- Interpolation — dot-notation, RFC 6901
pointers,
this/./../, and@index/@key. - Blocks —
{{#if}},{{#unless}},{{#each}},{{#with}}, and theirelse/else ifarms. - Transforms — the pipeline and arguments.
- Getting started with the Kotlin API — dependency coordinates and the shape of a render call, if you're embedding kBars in a Kotlin app.
- Porting to another language — the language-agnostic conformance suite and how to build a workalike.
- The Bars Specification — the normative definition of the template language kBars implements.
- Playground — try kBars in the browser, no install; loads a ~5 MB WebAssembly bundle.
The full generated API documentation is in the API Reference.
License¶
kBars is licensed under the Apache License, Version 2.0.