Jump to content

Module:Icon/table

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 04:57, 29 August 2021 (sort codes in lexical order). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- 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