Add error pseudo-loader

This commit is contained in:
Talia 2022-12-25 11:52:08 +01:00
parent 7aee1aee97
commit 552556357e
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E
3 changed files with 6 additions and 0 deletions

View file

@ -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",

3
glass/error.lua Normal file
View file

@ -0,0 +1,3 @@
return function(name)
error("Could not load config "..name.." with any loader", 2)
end

View file

@ -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.