diff options
Diffstat (limited to 'modules/luci-base')
-rw-r--r-- | modules/luci-base/luasrc/dispatcher.lua | 17 | ||||
-rw-r--r-- | modules/luci-base/luasrc/dispatcher.luadoc | 11 |
2 files changed, 27 insertions, 1 deletions
diff --git a/modules/luci-base/luasrc/dispatcher.lua b/modules/luci-base/luasrc/dispatcher.lua index c93fd78a1b..88f9440c5d 100644 --- a/modules/luci-base/luasrc/dispatcher.lua +++ b/modules/luci-base/luasrc/dispatcher.lua @@ -658,6 +658,23 @@ function node(...) return c end +function lookup(...) + local i, path = nil, {} + for i = 1, select('#', ...) do + local name, arg = nil, tostring(select(i, ...)) + for name in arg:gmatch("[^/]+") do + path[#path+1] = name + end + end + + for i = #path, 1, -1 do + local node = context.treecache[table.concat(path, ".", 1, i)] + if node and (i == #path or node.leaf) then + return node, build_url(unpack(path)) + end + end +end + function _create_node(path) if #path == 0 then return context.tree diff --git a/modules/luci-base/luasrc/dispatcher.luadoc b/modules/luci-base/luasrc/dispatcher.luadoc index 743463c74f..ddf534b3e1 100644 --- a/modules/luci-base/luasrc/dispatcher.luadoc +++ b/modules/luci-base/luasrc/dispatcher.luadoc @@ -116,8 +116,8 @@ Create a new dispatching node and define common parameters. ---[[ Fetch or create a dispatching node without setting the target module or - enabling the node. + @class function @name get @param ... Virtual path @@ -134,6 +134,15 @@ Fetch or create a new dispatching node. ]] ---[[ +Lookup node in dispatching tree. + +@class function +@name lookup +@param ... Virtual path +@return Node object, canonical url or nil if the path was not found. +]] + +---[[ Alias the first (lowest order) page automatically |