-- @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
+ local rv = { }
+ if node then
+ 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
+ end
+ return rv
end
assert(media, "No valid theme found")
end
+ local function _ifattr(cond, key, val)
+ if cond then
+ local env = getfenv(3)
+ local scope = (type(env.self) == "table") and env.self
+ return string.format(
+ ' %s="%s"', tostring(key),
+ luci.util.pcdata(tostring( val
+ or (type(env[key]) ~= "function" and env[key])
+ or (scope and type(scope[key]) ~= "function" and scope[key])
+ or "" ))
+ )
+ else
+ return ''
+ end
+ end
+
tpl.context.viewns = setmetatable({
write = luci.http.write;
include = function(name) tpl.Template(name):render(getfenv(2)) end;
pcdata = util.pcdata;
media = media;
theme = fs.basename(media);
- resource = luci.config.main.resourcebase
+ resource = luci.config.main.resourcebase;
+ ifattr = function(...) return _ifattr(...) end;
+ attr = function(...) return _ifattr(true, ...) end;
}, {__index=function(table, key)
if key == "controller" then
return build_url()
local function _call(self, ...)
+ local func = getfenv()[self.name]
+ assert(func ~= nil,
+ 'Cannot resolve function "' .. self.name .. '". Is it misspelled or local?')
+
+ assert(type(func) == "function",
+ 'The symbol "' .. self.name .. '" does not refer to a function but data ' ..
+ 'of type "' .. type(func) .. '".')
+
if #self.argv > 0 then
- return getfenv()[self.name](unpack(self.argv), ...)
+ return func(unpack(self.argv), ...)
else
- return getfenv()[self.name](...)
+ return func(...)
end
end