template/render
src/template/render.tur
defn
render-ast
(render-ast [root : int env : int] :)
render a pre-parsed node chain against env.
Parameters
| root | node chain head from `parse` | |
| env | Env handle from `env-new` |
Returns
A heap-allocated cstr. Caller frees with `free`.
Example
(render-ast (parse (lex "<%= x %>")) e)
Since: 0.1.0
defn
render
(render [src : cstr env : int] :)
lex+parse+render-ast a template string against env.
Parameters
| src | template source (NUL-terminated cstr) | |
| env | Env handle |
Returns
A heap-allocated cstr containing the rendered output. Caller frees.
Example
(render "Hello, <%= name %>!" e)
Since: 0.1.0
defn
render-file
(render-file [path : cstr env : int] :)
read `path`, render the template body against env.
Parameters
| path | path to a template file | |
| env | Env handle |
Returns
result<:cstr> as a tagged struct: ok payload is a heap cstr that the caller frees; err payload is a heap cstr diagnostic.
Example
(let [r (render-file "page.html.tur" e)]
(if (ok? r) (println (ok-val r)) (println (err-val r))))
Since: 0.1.0
Internal definitions
__read-file-- read a file's contents into a fresh malloc'd cstr (0 on fail).__free-cstr-- free a heap cstr (used internally for file buffers).__cstr-from-int-- coerce an :int pointer back to :cstr for render.__cstr->int-- coerce a :cstr back to :int (heap pointer).__err-msg-- allocate a heap cstr containing an error message.__ok-result-- build an ok result wrapping a cstr-pointer payload.__err-result-- build an err result wrapping a cstr message.