diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2011-10-26 00:24:17 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2011-10-26 00:24:17 +0000 |
commit | 5f7d2719b23f30ebfcfc0fff13a3e87f6427c587 (patch) | |
tree | 0814a3492f95fc37de0223d6f7a088bfe7fdeba9 /libs/web/luasrc/dispatcher.lua | |
parent | 7b385564880cfb5e075d9d69f3b2a52d611c02ff (diff) |
libs/web: dispatcher add node_childs() and node_visible() helper functions for templates
Diffstat (limited to 'libs/web/luasrc/dispatcher.lua')
-rw-r--r-- | libs/web/luasrc/dispatcher.lua | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 5f893dad95..c1e8d990f7 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -73,6 +73,40 @@ function build_url(...) return table.concat(url, "") end +--- Check whether a dispatch node shall be visible +-- @param node Dispatch node +-- @return Boolean indicating whether the node should be visible +function node_visible(node) + if node then + return not ( + (not node.title or #node.title == 0) or + (not node.target or node.hidden == true) or + (type(node.target) == "table" and node.target.type == "firstchild" and + (type(node.nodes) ~= "table" or not next(node.nodes))) + ) + end + return false +end + +--- Return a sorted table of visible childs within a given node +-- @param node Dispatch node +-- @return Ordered table of child node names +function node_childs(node) + local rv = { } + local k, v + for k, v in util.spairs(node.nodes, + function(a, b) + return (node.nodes[a].order or 100) < (node.nodes[b].order or 100) + end) + do + if node_visible(v) then + rv[#rv+1] = k + end + end + return rv +end + + --- Send a 404 error code and render the "error404" template if available. -- @param message Custom error message (optional) -- @return false @@ -131,7 +165,7 @@ function httpdispatch(request, prefix) local r = {} context.request = r context.urltoken = {} - + local pathinfo = http.urldecode(request:getenv("PATH_INFO") or "", true) if prefix then @@ -487,7 +521,7 @@ function createindex_plain(path, suffixes) "The file '" .. c .. "' contains an invalid module line.\n" .. "Please verify whether the module name is set to '" .. modname .. "' - It must correspond to the file path!") - + local idx = mod.index assert(type(idx) == "function", "Invalid controller file found\n" .. |