Module:Icon/table
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
-- Create a table of icons to display on the template test case page
require('strict')
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 reconstituteAliases(iconDataCollection)
local ret = {}
for code, iconData in pairs(iconDataCollection) do
local outputData = ret[iconData.canonicalCode] or {
aliases = {},
image = iconData.image,
tooltip = iconData.tooltip,
link = iconData.link,
}
if code ~= iconData.canonicalCode then
table.insert(outputData.aliases, code)
end
ret[iconData.canonicalCode] = outputData
end
return ret
end
local function makeTableData(iconDataCollection)
local ret = {}
for code, iconData in pairs(reconstituteAliases(iconDataCollection)) do
if code ~= '_DEFAULT' then
table.insert(ret, {code = code, description = iconData.tooltip, aliases = iconData.aliases})
end
end
table.sort(
ret,
function(t1, t2)
return t1.code < t2.code
end
)
for _, t in ipairs(ret) do
table.sort(t.aliases)
end
return ret
end
function p.testcases(frame)
local tableData = makeTableData(mergeTables(m_iconData, m_iconSandboxData))
local ret = {
'{| class="wikitable sortable"',
'! Code',
'! [[Template:Icon|Template]]',
'! [[Template:Icon/sandbox|Sandbox]]',
'! Description',
}
local function addRow(code, description)
table.insert(ret, '|-')
table.insert(ret, '| <code>' .. mw.text.nowiki('{{icon|' .. code .. '}}') .. '</code>')
table.insert(ret, '| style="text-align: center" | ' .. frame:expandTemplate{title = 'icon', args = {code}})
table.insert(ret, '| style="text-align: center" | ' .. frame:expandTemplate{title = 'icon/sandbox', args = {code}})
table.insert(ret, '| ' .. description)
end
for _, rowData in ipairs(tableData) do
addRow(rowData.code, rowData.description)
for _, alias in ipairs(rowData.aliases) do
addRow(alias, rowData.description)
end
end
table.insert(ret, '|}')
return table.concat(ret, '\n')
end
function p.main(frame)
local tableData = makeTableData(m_iconData)
local ret = {
'{| class="wikitable sortable"',
'! Icon',
'! Description',
'! Code',
'! Aliases'
}
for _, rowData in ipairs(tableData) do
table.insert(ret, '|-')
table.insert(ret, '| style="text-align: center" | ' .. frame:expandTemplate{title = 'icon', args = {rowData.code}})
table.insert(ret, '| ' .. rowData.description)
table.insert(ret, '| <code>' .. mw.text.nowiki('{{icon|' .. rowData.code .. '}}') .. '</code>')
local aliasText = {}
for _, alias in ipairs(rowData.aliases) do
table.insert(aliasText, '<code>' .. alias .. '</code>')
end
table.insert(ret, '| ' .. table.concat(aliasText, ', '))
end
table.insert(ret, '|}')
return table.concat(ret, '\n')
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.