Module restia.config
Loads configurations from files on demand.
Info:
- License: Unlicense
- Author: DarkWiiPlayer
loaders |
A list containing the default loaders. |
-
bind (dir, loaders)
-
Binds a table to a config directory.
The returned table maps keys to configurations, which are handled by different “loaders”. loaders are handlers that try loading a config entry in a certain format and are tried sequentially until one succeeds. If no loader matches, nil is returned.
Parameters:
- dir
string
Path to the directory to look in.
- loaders
table
A table of loaders to use when attempting to load a configuration entry.
Returns:
table
config A table that maps to the config directory
Usage:
local main_config = config.bind 'configurations'
main_config.foo.bar
-
loaders
-
A list containing the default loaders.
Each loader is also saved with a string key describing it;
this allows more easily copying a selection of default loaders
into a custom loader chain or wrap them in filters.
-
try_require (modname)
-
Tries requiring a module.
Returns the module if successful or nil otherwise.
Parameters:
- modname
string
The name of the module as would be passed to require
-
readfile (path)
-
Reads a file.
Returns the files contents if successful or nil otherwise.
Parameters:
- path
string
The path to the file to read
Functions that turn the entry name into a filename and attempt to load with some specific mechanism.
-
dir (name)
-
Binds a subdirectory
Parameters:
- name
string
Treated as a directory name as is
-
markdown ()
-
Loads a markdown file and converts it to HTML.
Repeatedly calling the function will just return the same exact string.
-
raw (name)
-
Loads a file as plain text.
Parameters:
- name
string
Used as is without extension.
-
loadlua (name)
-
Loads and runs a Lua file and returns its result.
Parameters:
- name
string
The extension
.lua
is added.
-
json (name)
-
Loads a JSON document and returns it as a table using cjson.
Parameters:
- name
string
The extension
.json
is added.
-
yaml (name)
-
Loads a YAML file and returns it as a table using lyaml.
Parameters:
- name
string
The extensions
.yaml
and .yml
are both tried.
-
cosmo (name)
-
Loads a cosmo template.
This returns the plain cosmo template, which has to be
manually printed to the client with
ngx.say
.
Parameters:
- name
string
The extension
.cosmo
is added.
-
lua_moonhtml_cosmo (name)
-
Multistage template for compiled moonhtml + cosmo.
Loads and renders a precompiled moonhtml template, then compiles the resulting string as a cosmo template.
The resulting template renders a string which has to manually be sent to the client with
ngx.say
.
Parameters:
- name
string
The extension
.cosmo.moonhtml.lua
is added.
-
moonhtml_cosmo (name)
-
Multistage template for uncompiled moonhtml + cosmo.
Loads and renders a moonhtml template, then compiles the resulting string as a cosmo template.
The resulting template renders a string which has to manually be sent to the client with
ngx.say
.
Parameters:
- name
string
The extension
.cosmo.moonhtml
is added.
-
lua_moonhtml (name)
-
Loads a preompiled moonhtml template.
Loads the file as a Lua file with the moonhtml environment using restia.template.
Parameters:
- name
string
The extension
.moonhtml.lua
is added.
-
moonhtml (name)
-
Loads a moonhtml template.
Loads the file as a Moonscript file with the moonhtml environment using restia.template.
Parameters:
- name
string
The extension
.moonhtml
is added.