Module:Icon/keys
From ARC Raiders Wiki
More actions
Renders a reference table of all keys and icons for a named dataset. Used in template documentation pages to list the valid keys accepted by a wrapper template, alongside the icon each key resolves to and its source filename.
Template documentation pages invoke this module directly:
{{#invoke:Icon/keys|main|dataset=<dataset>}}
The output is a wikitable with three columns: the rendered icon, the key name, and the source filename. Keys are sorted alphabetically. Entries missing an icon field are silently skipped.
Arguments
dataset(required): name of the dataset atModule:Icon/data/<dataset>. Lowercased before resolution; callers may pass the name in any case.
Errors
Raises an error when:
- No
datasetis supplied. - The named dataset does not exist.
All errors are caught by Keys.main, rendered as an inline <span class="error">, and tracked via Category:Pages with icon errors.
See also
- Module:Icon: the icon engine; handles rendering and index resolution.
- Module:Icon/data: dataset documentation for the icon system.
- Module:Icon/index: maps icon filenames to their respective datasets.
--- Renders a reference table of keys and icons for a given dataset.
--- Used in template documentation pages to list all valid keys.
local Keys = {}
local DATA_PREFIX = 'Module:Icon/data/'
local DEFAULT_SIZE = 22
local ERROR_CATEGORY = 'Pages with icon errors'
local function renderError(message)
local span = tostring(mw.html.create('span')
:addClass('error')
:wikitext(message)
)
return span .. '[[Category:' .. ERROR_CATEGORY .. ']]'
end
local function normalizeArgs(rawArgs)
local dataset = rawArgs.dataset
if not dataset or mw.text.trim(dataset) == '' then
error('Module:Icon/keys: missing dataset', 0)
end
local trimmed = mw.text.trim(dataset)
return {
dataset = mw.ustring.lower(trimmed),
original = trimmed,
}
end
local function build(rawArgs)
local config = normalizeArgs(rawArgs)
local page = DATA_PREFIX .. config.dataset
local ok, data = pcall(mw.loadData, page)
if not ok then
error(string.format('Module:Icon/keys: dataset "%s" not found at %s', config.original, page), 0)
end
local t = mw.html.create('table'):addClass('wikitable')
local header = t:tag('tr')
header:tag('th'):wikitext('Icon')
header:tag('th'):wikitext('Key')
header:tag('th'):wikitext('File')
local keys = {}
for k in pairs(data) do
table.insert(keys, k)
end
table.sort(keys)
for _, key in ipairs(keys) do
local entry = data[key]
if type(entry) == 'table' and type(entry.icon) == 'string' then
local image = string.format('[[File:%s|%dpx|link=]]', entry.icon, DEFAULT_SIZE)
if entry.classes then
local span = mw.html.create('span')
for _, class in ipairs(entry.classes) do
span:addClass(class)
end
image = tostring(span:wikitext(image))
end
local row = t:tag('tr')
row:tag('td'):css('text-align', 'center'):wikitext(image)
row:tag('td'):tag('code'):wikitext(key)
row:tag('td'):tag('code'):wikitext(entry.icon)
end
end
return tostring(t)
end
function Keys.main(frame)
local args = frame.args
if not args.dataset or mw.text.trim(args.dataset) == '' then
local parent = frame:getParent()
args = parent and parent.args or args
end
local ok, result = pcall(build, args)
return ok and result or renderError(result)
end
return Keys