view mrjunejune/template_renderer.h @ 267:a78f5986011f

discover bundled production runtimes Locate Bazel-packaged Copilot and Python binaries by stable suffix instead of hardcoding an external repository prefix. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Fri, 07 Aug 2026 12:58:55 -0700
parents 04fee26ecce0
children
line wrap: on
line source

#ifndef MJJ_TEMPLATE_RENDERER_H
#define MJJ_TEMPLATE_RENDERER_H

/*
 * template_renderer.h — site-owned HTML template renderer for mrjunejune.
 *
 * Expands {{/path}} include tokens by loading files relative to the
 * configured document root.  Provides overflow-safe output into a
 * caller-supplied buffer allocated from a Dowa_Arena.
 */

#include "dowa/dowa.h"

/*
 * Set the document root used for all subsequent renders.
 * Must be called once before the first render (not thread-safe vs
 * concurrent renders; fine to call before the server accepts requests).
 * Defaults to "mrjunejune/src" if never called.
 */
void Mjj_Template_Renderer_Init(const char *src_root);

/*
 * Render the NUL-terminated template string `tmpl` into `out[0..cap-1]`,
 * replacing every {{/path}} token with the contents of the file at
 * g_src_root + path.  `out` is always NUL-terminated on return.
 *
 * Returns TRUE  — all text fit; out contains the fully expanded page.
 * Returns FALSE — output exceeded cap, or tmpl is NULL.
 *   (out may contain a partial result; treat FALSE as a 500.)
 *
 * Missing includes are skipped silently; they never cause FALSE.
 * arena is used only for temporary include-name copies (not freed here).
 */
boolean Mjj_Template_Render(
    char *out, size_t cap, const char *tmpl, Dowa_Arena *arena);

/*
 * Load the file at g_src_root + path, then render its includes.
 * Returns FALSE if the file cannot be opened or if cap is exceeded.
 * Equivalent to loading the file and calling Mjj_Template_Render.
 */
boolean Mjj_Template_Render_File(
    char *out, size_t cap, const char *path, Dowa_Arena *arena);

#endif /* MJJ_TEMPLATE_RENDERER_H */