Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Size

From Kerbal Space Program 2 Wiki
Revision as of 17:23, 6 December 2024 by KiwiShark (talk | contribs) (New module to handle size tag display instead of parser function spaghetti in the template)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This module is used by Template:Size to match the supplied argument to the formatted size tag string.

The main function getSize accepts the first argument passed to Template:Size and returns the formatted size tag.


local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.getSize(frame)
	-- Get arguments from the invoke
	-- frameOnly is used to ignore additional arguments passed when 
	-- Template:Size is called from an infobox, for example
	local args = getArgs(frame, {frameOnly = true}) 
	-- Pass arguments to the helper function
	size = p._getData(args)
	return size
end

function p._getSize(args)
	-- Take the arg as the size tag label
	sizeTag = args[1]
	size = ""
	
	-- Match the tag to the proper formatted string to display
	if sizeTag == "XS" then size = "<code><b><font color=#E04949>XS</font></b></code>" end
	if sizeTag == "SM" then size = "<code><b><font color=#E0A400>SM</font></b></code>" end
	if sizeTag == "MD" then size = "<code><b><font color=#93E000>MD</font></b></code>" end
	if sizeTag == "LG" then size = "<code><b><font color=#00E0A8>LG</font></b></code>" end
	if sizeTag == "XL" then size = "<code><b><font color=#49ABE0>XL</font></b></code>" end
	if sizeTag == "2X" then size = "<code><b><font color=#A978DA>2X</font></b></code>" end
	
	return size
end

return p
MediaWiki Appliance - Powered by TurnKey Linux