From 552556357ea9833996b01b6265ba834babcd6569 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Sun, 25 Dec 2022 11:52:08 +0100 Subject: [PATCH] Add error pseudo-loader --- glass-dev-1.rockspec | 1 + glass/error.lua | 3 +++ readme.md | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 glass/error.lua diff --git a/glass-dev-1.rockspec b/glass-dev-1.rockspec index d613b9e..d0251f2 100644 --- a/glass-dev-1.rockspec +++ b/glass-dev-1.rockspec @@ -17,6 +17,7 @@ build = { ["glass.cosmo"] = "glass/cosmo.lua", ["glass.discount"] = "glass/discount.lua", ["glass.environment"] = "glass/environment.lua", + ["glass.error"] = "glass/error.lua", ["glass.json"] = "glass/json.lua", ["glass.lua"] = "glass/lua.lua", ["glass.moonhtml"] = "glass/moonhtml.lua", diff --git a/glass/error.lua b/glass/error.lua new file mode 100644 index 0000000..3834846 --- /dev/null +++ b/glass/error.lua @@ -0,0 +1,3 @@ +return function(name) + error("Could not load config "..name.." with any loader", 2) +end diff --git a/readme.md b/readme.md index c50a48b..6bcfc8e 100644 --- a/readme.md +++ b/readme.md @@ -17,6 +17,7 @@ Assume the file `app/config/settings.json` exists in your project directory with local glass = require 'glass' local config = glass.bind('app/config', { (require 'glass.json'); + (require 'glass.error'); -- Throw error if nothing matches }) print(config.settings.user.name) -- prints "User" ``` @@ -36,6 +37,7 @@ Glass offers the following loaders out of the box: * `skooma` loads a skooma template and returns it as a function. * `table` looks up values in a Lua table * `yaml` loads a YAML file as a Lua table. (requires `lyaml`) +* `error` pseudo-loader that throws an error. \* 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.