libs/web: dispatcher: implement a "firstchild()" target which simply redirects to the first child of a node, useful for menus that are empty by default and may gain arbritary childs

This commit is contained in:
Jo-Philipp Wich 2011-10-25 22:48:43 +00:00
parent d033763924
commit 6021cf3bdf

View file

@ -638,6 +638,35 @@ end
-- Subdispatchers -- -- Subdispatchers --
function _firstchild()
local path = { unpack(context.path) }
local name = table.concat(path, ".")
local node = context.treecache[name]
local lowest
if node and node.nodes and next(node.nodes) then
local k, v
for k, v in pairs(node.nodes) do
if not lowest or
(v.order or 100) < (node.nodes[lowest].order or 100)
then
lowest = k
end
end
end
assert(lowest ~= nil,
"The requested node contains no childs, unable to redispatch")
path[#path+1] = lowest
dispatch(path)
end
--- Alias the first (lowest order) page automatically
function firstchild()
return { type = "firstchild", target = _firstchild }
end
--- Create a redirect to another dispatching node. --- Create a redirect to another dispatching node.
-- @param ... Virtual path destination -- @param ... Virtual path destination
function alias(...) function alias(...)