kdlet
v0.3.1
Published
A small template language written in KDL: data, repetition and named conditions, with renderers that bring their own words
Downloads
634
Maintainers
Readme
Templates that read like Pug, for any tree, written in KDL.
kdlet is a small template language. A file says what a tree looks like once data is put into it: where values go, what repeats, and what appears only under a named condition. It has no elements of its own; a renderer brings its words.
This package is the language. It reads a file and evaluates it into a plain tree. To get HTML out, add kdlet-html.
npm install kdlet kdlet-htmlul.posts {
each post in=(input)posts key=slug { li (post)title }
else { li "No posts yet." }
}import { evaluate, read } from 'kdlet';
import { render, vocabulary } from 'kdlet-html';
const document = read(text); // document.problems: every problem, with line and column
const { tree, problems } = evaluate(document, { vocabulary, inputs: { posts } });
const html = render(tree);What it exports
| Export | What it does |
|---|---|
| read(text, options?) | KDL text to a document, with every problem found and its line and column |
| evaluate(document, options) | A document, inputs, the host's guards and definitions, and a vocabulary, to a plain tree in which every node has an identity |
| defineVocabulary(vocabulary) | Registers a renderer's words, and refuses a collision with the language's |
Node 20 or later, ESM only.
Read next
- The manual: the syntax and every rule, with worked examples.
- The repository: the vision, the principles and the source.
License
MIT.
