Jump to content

Module:Icon/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Hike395 (talk | contribs) at 17:44, 3 January 2022 (sandboxify, use standard modules). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- This module implements [[Template:Icon]].

require("Module:No globals")
local yesNo = require("Module:Yesno")
local getArgs = require("Module:Arguments").getArgs

local DATA_MODULE = 'Module:Icon/data/sandbox'
local p = {}

function p._main(args, data)
	local inSandbox = yesNo(args.sandbox)
	local data_module = 'Module:Icon/data'..(inSandbox and '/sandbox' or '')
	data = data or mw.loadData(data_module)
	local code = args.class or args[1]
	local iconData
	if code then
		code = code:match('^%s*(.-)%s*$'):lower() -- trim whitespace and put in lower case
		iconData = data[code]
	end
	if not iconData then
		iconData = data._DEFAULT
	end
	return string.format(
		'[[File:%s%s%s|%s|class=noviewer]]',
		iconData.image,
		iconData.tooltip and '|' .. iconData.tooltip or '',
		iconData.link == false and '|link=' or '',
		args.size or '16x16px'
	)
end

function p.main(frame)
	local args = getArgs(frame,{parentFirst=true})
	return p._main(args)
end

return p