From de52cca2bb58417d81f7bd2e9a570a9c98a0b5fa Mon Sep 17 00:00:00 2001 From: Mikko Ahlroth Date: Mon, 27 Feb 2023 19:17:22 +0200 Subject: [PATCH] More docs --- README.md | 4 ++++ src/glemplate/renderer.gleam | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 22b4a4f..ec22442 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ Glemplate does not offer any tooling for reading templates currently. You will n whatever method appropriate for your situation: reading from files, compiling the strings in the app, reading from a database… +When stored in files, it's suggested that templates use the file naming style +`name..glemp`, where `` signifies the type of content rendered from the template. E.g. +`user.html.glemp`. + ## Limitations - Static values in templates in place of variables aren't supported. diff --git a/src/glemplate/renderer.gleam b/src/glemplate/renderer.gleam index 36bfc35..28da6af 100644 --- a/src/glemplate/renderer.gleam +++ b/src/glemplate/renderer.gleam @@ -20,12 +20,16 @@ pub type RenderError { /// A referenced assign could not be stringified. AssignNotStringifiable(assign: ast.Var, assigns: Assigns) + /// A referenced assign didn't have the requested field. AssignFieldNotFound(assign: ast.Var, field: String, assigns: Assigns) + /// A referenced assign couldn't be accessed with field access. AssignNotFieldAccessible(assign: ast.Var, assigns: Assigns) + /// A referenced assign didn't have the requested index. AssignIndexOutOfBounds(assign: ast.Var, index: Int, assigns: Assigns) + /// A referenced assign couldn't be accessed with index access. AssignNotIndexable(assign: ast.Var, assigns: Assigns) /// A referenced child template was not found in the template cache. @@ -51,6 +55,12 @@ pub type EncoderFn = pub type TemplateCache = Map(ast.TemplateName, ast.Template) +/// Rendering options: +/// +/// - `encoder`: Encoder function to use, it should encode dynamic content in a +/// safe way for this template type. +/// - `template_cache`: A cache of templates that child templates are looked up +/// from, when using Render nodes. pub type RenderOptions { RenderOptions(encoder: EncoderFn, template_cache: TemplateCache) }