diff --git a/glass-dev-1.rockspec b/glass-dev-1.rockspec index 24a68ae..5da17b4 100644 --- a/glass-dev-1.rockspec +++ b/glass-dev-1.rockspec @@ -22,6 +22,7 @@ build = { ["glass.moonhtml_cosmo"] = "glass/moonhtml_cosmo.lua", ["glass.raw"] = "glass/raw.lua", ["glass.skooma"] = "glass/skooma.lua", + ["glass.table"] = "glass/table.lua", ["glass.yaml"] = "glass/yaml.lua" } } diff --git a/glass/table.lua b/glass/table.lua new file mode 100644 index 0000000..9fef0b1 --- /dev/null +++ b/glass/table.lua @@ -0,0 +1,12 @@ +--- Pseudo-loader for Lua tables +-- Can be used to "overlay" static values over or under other configuration sources. +-- @module glass.table + +--- Returns a (pseudo-)loader function from a given Table +-- @tparam table table The table in which to look up valuse +-- @treturn function A loader function to be used with `glass.bind` +return function(input) + return function(name) + return input[name:match("[^/].+$")] + end +end diff --git a/readme.md b/readme.md index 3fd0f57..7f07dd1 100644 --- a/readme.md +++ b/readme.md @@ -33,6 +33,7 @@ Glass offers the following loaders out of the box: * `moonhtml` loads a MoonHTML template and returns it as a function. * `readfile` loads a file as a string. * `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. \* 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.