diff --git a/glass-dev-1.rockspec b/glass-dev-1.rockspec index d0251f2..34135f6 100644 --- a/glass-dev-1.rockspec +++ b/glass-dev-1.rockspec @@ -22,8 +22,9 @@ build = { ["glass.lua"] = "glass/lua.lua", ["glass.moonhtml"] = "glass/moonhtml.lua", ["glass.raw"] = "glass/raw.lua", - ["glass.skooma"] = "glass/skooma.lua", + ["glass.skooma.html"] = "glass/skooma/html.lua", + ["glass.skooma.xml"] = "glass/skooma/xml.lua", ["glass.table"] = "glass/table.lua", - ["glass.yaml"] = "glass/yaml.lua" + ["glass.yaml"] = "glass/yaml.lua", } } diff --git a/glass/skooma.lua b/glass/skooma.lua deleted file mode 100644 index 8a75ea7..0000000 --- a/glass/skooma.lua +++ /dev/null @@ -1,18 +0,0 @@ ---- Loader for Skooma templates --- @module glass.skooma - -local skooma = require 'skooma' - ---- Loads a Lua file with the Skooma environment and runs it. --- Normally, the file should return a function --- to follow restia template semantics. --- @return The result of the template file. --- @function load -return function(name) - name = tostring(name)..'.skooma' - local template = loadfile(name, "tb", skooma.default) - template = template and template() - if template then - return template - end -end diff --git a/glass/skooma/html.lua b/glass/skooma/html.lua new file mode 100644 index 0000000..626ec5b --- /dev/null +++ b/glass/skooma/html.lua @@ -0,0 +1,25 @@ +--- Loader for Skooma templates +-- @module glass.skooma + +local html = require('skooma.env')('html') +local env = setmetatable({}, {__index = function(_, key) + if _G[key] ~= nil then + return _G[key] + else + return html[key] + end +end}) + +--- Loads a Lua file with the Skooma environment and runs it. +-- Normally, the file should return a function +-- to follow restia template semantics. +-- @return The result of the template file. +-- @function load +return function(name) + name = tostring(name)..'.html.skooma' + local template = loadfile(name, "t", env) + if setfenv then + setfenv(template, env) + end + return template +end diff --git a/glass/skooma/xml.lua b/glass/skooma/xml.lua new file mode 100644 index 0000000..78bbc4d --- /dev/null +++ b/glass/skooma/xml.lua @@ -0,0 +1,25 @@ +--- Loader for Skooma templates +-- @module glass.skooma + +local xml = require('skooma.env')('xml') +local env = setmetatable({}, {__index = function(_, key) + if _G[key] ~= nil then + return _G[key] + else + return xml[key] + end +end}) + +--- Loads a Lua file with the Skooma environment and runs it. +-- Normally, the file should return a function +-- to follow restia template semantics. +-- @return The result of the template file. +-- @function load +return function(name) + name = tostring(name)..'.xml.skooma' + local template = loadfile(name, "t", env) + if setfenv then + setfenv(template, env) + end + return template +end diff --git a/readme.md b/readme.md index 6bcfc8e..8a25d2a 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,8 @@ Glass offers the following loaders out of the box: * `lua` loads and executes a Lua file. * `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. +* `skooma.html` loads a `.html.skooma` template and returns it as a function. +* `skooma.xml` same as above for `.xml.skooma`. * `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.