Add error pseudo-loader
This commit is contained in:
parent
7aee1aee97
commit
552556357e
3 changed files with 6 additions and 0 deletions
|
@ -17,6 +17,7 @@ build = {
|
||||||
["glass.cosmo"] = "glass/cosmo.lua",
|
["glass.cosmo"] = "glass/cosmo.lua",
|
||||||
["glass.discount"] = "glass/discount.lua",
|
["glass.discount"] = "glass/discount.lua",
|
||||||
["glass.environment"] = "glass/environment.lua",
|
["glass.environment"] = "glass/environment.lua",
|
||||||
|
["glass.error"] = "glass/error.lua",
|
||||||
["glass.json"] = "glass/json.lua",
|
["glass.json"] = "glass/json.lua",
|
||||||
["glass.lua"] = "glass/lua.lua",
|
["glass.lua"] = "glass/lua.lua",
|
||||||
["glass.moonhtml"] = "glass/moonhtml.lua",
|
["glass.moonhtml"] = "glass/moonhtml.lua",
|
||||||
|
|
3
glass/error.lua
Normal file
3
glass/error.lua
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
return function(name)
|
||||||
|
error("Could not load config "..name.." with any loader", 2)
|
||||||
|
end
|
|
@ -17,6 +17,7 @@ Assume the file `app/config/settings.json` exists in your project directory with
|
||||||
local glass = require 'glass'
|
local glass = require 'glass'
|
||||||
local config = glass.bind('app/config', {
|
local config = glass.bind('app/config', {
|
||||||
(require 'glass.json');
|
(require 'glass.json');
|
||||||
|
(require 'glass.error'); -- Throw error if nothing matches
|
||||||
})
|
})
|
||||||
print(config.settings.user.name) -- prints "User"
|
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.
|
* `skooma` loads a skooma template and returns it as a function.
|
||||||
* `table` looks up values in a Lua table
|
* `table` looks up values in a Lua table
|
||||||
* `yaml` loads a YAML file as a Lua table. (requires `lyaml`)
|
* `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.
|
\* 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.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue