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:45, 29 August 2021 (add the code column output). 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

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

function p.main(frame)
	local iconDataCollection = 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]]',
		'! Type',
	}
	for code, iconData in pairs(iconDataCollection) do
		if code ~= "_DEFAULT" then
			table.insert(ret, '|- style="text-align: center;"')
			table.insert(ret, '| <code>' .. mw.text.nowiki('{{icon|' .. code .. '}}') .. '</code>')
			table.insert(ret, '| ' .. frame:expandTemplate{title = 'icon', args = {code}})
			table.insert(ret, '| ' .. frame:expandTemplate{title = 'icon/sandbox', args = {code}})
			table.insert(ret, "| '''" .. iconData.tooltip .. "'''")
		end
	end
	table.insert(ret, '|}')
	return table.concat(ret, '\n')
end

return p