From 55665ad013bfc19f18315911b9a1affc10b20905 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Sat, 27 Aug 2022 07:50:48 +0200 Subject: [PATCH] Add explanation about custom loaders --- readme.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/readme.md b/readme.md index af4e57c..3fd0f57 100644 --- a/readme.md +++ b/readme.md @@ -36,3 +36,15 @@ Glass offers the following loaders out of the box: * `yaml` loads a YAML file as a Lua table. \* For easier interoperability with other template loaders, the `discount` loader returns a static function which can be called to return the generated HTML. The markdown file is only parsed the first time. + +### Custom Loaders + +A glass loader is simply a Lua function that takes as its argument a path to a +file and attempts to load it into a Lua value. + +Loaders will typically add an extension to the given file name before checking +whether that file exists and can be loaded. + +When a loader cannot find the expected file, it should return `nil` to let glass +continue the loader chain. When a loader returns a truthy value, this will be +used and no further loaders will be tried.