local data = mw.loadData("Module:API_info/navbox/data")
local m = {}
local meta = {
api = {
label = "API",
link = "API %s",
},
widget = {
label = "Widgets",
link = "API %s %s",
linkfunc = function(link, name)
local widget, method = name:match("(%a+):(%a+)")
return link:format(widget, method)
end,
},
script = {
label = "Scripts",
link = "UIHANDLER %s",
},
event = {
label = "Events",
link = "%s",
},
cvar = {
label = "CVars",
link = "CVar %s",
},
enum = {
label = "Enums",
link = "%s",
},
}
local order = {
"api",
"widget",
"script",
"event",
"cvar",
"enum",
}
local function FormatLink(info, name)
local page
if info.linkfunc then
page = info.linkfunc(info.link, name)
else
page = info.link:format(name)
end
local link
if name:find("%.") then -- omit namespace
local displayName = name:match("%.(%w+)")
link = string.format('.[[%s|%s]]', page, displayName)
else
link = string.format("[[%s|%s]]", page, name)
end
return link
end
local function GetChildNavbox(f, systemInfo, apiType)
local meta_info = meta[apiType]
local cat_info = systemInfo[apiType]
local template = {
title = 'Navbox',
args = {
"child",
state = "uncollapsed",
above = cat_info.above,
abovestyle = "text-align: left",
liststyle = "text-align: left",
groupwidth = "width: 8.5em", -- this is actually a min-width
}
}
if systemInfo.hasCategories then
template.args.title = meta_info.label
local t = {}
for cat_idx, cat_item in ipairs(cat_info) do
if type(cat_item) == "table" then
local r = {}
for _, item in ipairs(cat_item) do
table.insert(r, "* "..FormatLink(meta_info, item))
end
template.args["group"..cat_idx] = cat_item.category or string.rep(" ", 27)
template.args["list"..cat_idx] = table.concat(r, "\n")
elseif type(cat_item) == "string" then
table.insert(t, "* "..FormatLink(meta_info, cat_item))
end
end
if next(t) then
template.args.group1 = string.rep(" ", 27)
template.args.list1 = table.concat(t, "\n")
end
else
local t = {}
for cat_idx, cat_item in ipairs(cat_info) do
table.insert(t, "* "..FormatLink(meta_info, cat_item))
end
template.args.group1 = meta_info.label
template.args.list1 = table.concat(t, "\n")
end
return f:expandTemplate(template)
end
-- https://wowpedia.fandom.com/wiki/Template:Navbox
-- https://en.wikipedia.org/wiki/Template:Navbox
local function GetNavbox(f, systemInfo, systemName)
local template = {
title = "Navbox",
args = {
title = systemName,
navbar = "plain", -- hide V • T • E links
listclass = "hlist", -- render lists horizontally
}
}
if systemInfo.hasCategories then
template.args.state = "collapsed"
if systemInfo.api and systemInfo.api[1][1]:find(systemName..".") then
template.args.title = "[[:Category:API namespaces/"..systemName.."|"..systemName.."]]"
end
else
if systemInfo.api and systemInfo.api[1]:find(systemName..".") then
template.args.title = "[[:Category:API namespaces/"..systemName.."|"..systemName.."]]"
end
end
for metaIdx, apiType in pairs(order) do
if systemInfo[apiType] then
template.args["list"..metaIdx] = GetChildNavbox(f, systemInfo, apiType)
end
end
return f:expandTemplate(template)
end
function m.main(f)
local systemName = f.args[1]
local systemInfo = data[systemName]
return GetNavbox(f, systemInfo, systemName)
end
return m