From 522274519ea4e2f73a7b4dbfac5a58b43892b819 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 13 Mar 2025 09:36:19 +0800 Subject: [PATCH] Add documentation to the runtime library --- htmpl/README | 7 +++++++ htmpl/htmpl.ha | 6 ++---- diff --git a/htmpl/README b/htmpl/README new file mode 100644 index 0000000000000000000000000000000000000000..fbd13ece06a8bc8e46baf5efe8b012d22b9e4dee --- /dev/null +++ b/htmpl/README @@ -0,0 +1,7 @@ +The htmpl module provides runtime functions for the HTML template engine. + +Functions herein are expected to be used by code generated by the same version +of htmplgen. + +Many functions take an [[io::handle]], which represents the destination where +templates shall be rendered to. diff --git a/htmpl/htmpl.ha b/htmpl/htmpl.ha index 71ac4cc984c8b5d3793067f7dc8b36bcca315dcd..5a965702b4cd223a49181503c7bee96b49de3f19 100644 --- a/htmpl/htmpl.ha +++ b/htmpl/htmpl.ha @@ -2,14 +2,12 @@ use io; use memio; use strings; -// export type template = struct { -// writer: *fn(io::handle, const []u8) (size | io::error), -// }; - +// Writes a string to the destination. export fn write(h: io::handle, s: str) (size | io::error) = { return io::write(h, strings::toutf8(s))?; }; +// Writes a string to the destination after HTML-escaping it. export fn write_escape_html(h: io::handle, s: str) (size | io::error | nomem) = { let buf = memio::dynamic(); defer io::close(&buf)!; // TODO: Might not want to abort for syscall interruptions -- 2.48.1