diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-19 08:01:11 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-19 08:01:11 +0200 |
| commit | eacb54ae44f655c010fdfc2b7292d24f06ffc445 (patch) | |
| tree | fdcae49d2be2630b559a3b21a131cf4194feeb5e /lib/render/template.mli | |
| parent | 7228d0634a960c38da96b80378ec617768dfedf7 (diff) | |
| download | colitur-eacb54ae44f655c010fdfc2b7292d24f06ffc445.tar.gz colitur-eacb54ae44f655c010fdfc2b7292d24f06ffc445.zip | |
feat(render): logic-less template parser
Placeholders, sections, inverted sections, comments. Nothing else: no
partials, no lambdas, no expression evaluation, no raw form. A template
is data, never a program, which is what keeps an untrusted template safe.
Errors rather than silence on a malformed template: an unterminated tag,
an unclosed section, a mismatched close and a partial all return Error.
Swallowing '{{name' as text is how a typo becomes invisible missing
output in a printed booklet.
Diffstat (limited to 'lib/render/template.mli')
| -rw-r--r-- | lib/render/template.mli | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/render/template.mli b/lib/render/template.mli new file mode 100644 index 0000000..3f9ef97 --- /dev/null +++ b/lib/render/template.mli @@ -0,0 +1,28 @@ +(** A deliberately logic-less template engine (spec section 5). + + A template is DATA, never a program: placeholders, sections, inverted + sections and comments, and nothing else. There are no partials, no lambdas, + no expression evaluation, no arithmetic, and no filesystem or process + access. There is deliberately no "raw" or triple-brace form -- a template + cannot opt out of its flavour's escaping. + + Anything a calendar needs that this cannot express (a month grid's leading + blanks, week bucketing) is computed in {!View} and handed in as data. That + division is the design, not a workaround. *) + +(** What a template can be rendered against. *) +type value = + | Str of string + | Bool of bool + | List of value list + | Obj of (string * value) list + +type node = + | Text of string + | Var of string list (** dotted path, e.g. ["name"; "la"] *) + | Section of string list * node list + | Inverted of string list * node list + +(** Never raises; a malformed template is an [Error] with a human-readable + reason, because the template is user input. *) +val parse : string -> (node list, string) result |
