Module:Icon/table
Appearance
This module creates a test case template using data aggregated from Module:Icon/data and Module:Icon/data/sandbox. It is intended to be displayed at Template:Icon/testcases.
Usage
{{#invoke:icon/table|main}}
Output
Lua error in package.lua at line 80: module 'Module:No globals' not found.
-- Create a table of icons to display on the template test case page
require("Module:No globals")
local p = {}
local m_iconData = mw.loadData("Module:Icon/data")
local m_iconSandboxData = mw.loadData("Module:Icon/data/sandbox")
local function mergeTables(...)
local ret = {}
for _, t in ipairs{...} do
for k, v in pairs(t) do
ret[k] = v
end
end
return ret
end
local function makeTableData(iconDataCollection)
local ret = {}
for code, iconData in pairs(iconDataCollection) do
if code ~= '_DEFAULT' then
table.insert(ret, {code = code, description = iconData.tooltip})
end
end
table.sort(
ret,
function(t1, t2)
return t1.code < t2.code
end
)
return ret
end
function p.main(frame)
local tableData = makeTableData(mergeTables(m_iconData, m_iconSandboxData))
local ret = {
'{| class="wikitable sortable"',
'|+ style="padding-bottom: 0.3em; font-size: 150%; font-weight: normal" |',
'! Code',
'! [[Template:Icon|Template]]',
'! [[Template:Icon/sandbox|Sandbox]]',
'! Description',
}
for _, rowData in ipairs(tableData) do
table.insert(ret, '|- style="text-align: center;"')
table.insert(ret, '| <code>' .. mw.text.nowiki('{{icon|' .. rowData.code .. '}}') .. '</code>')
table.insert(ret, '| ' .. frame:expandTemplate{title = 'icon', args = {rowData.code}})
table.insert(ret, '| ' .. frame:expandTemplate{title = 'icon/sandbox', args = {rowData.code}})
table.insert(ret, "| '''" .. rowData.description .. "'''")
end
table.insert(ret, '|}')
return table.concat(ret, '\n')
end
return p