Restructure skooma template loading for skooma 0.2
This commit is contained in:
parent
552556357e
commit
bf53b1f333
5 changed files with 55 additions and 21 deletions
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
25
glass/skooma/html.lua
Normal file
25
glass/skooma/html.lua
Normal file
|
@ -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
|
25
glass/skooma/xml.lua
Normal file
25
glass/skooma/xml.lua
Normal file
|
@ -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
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue