Module:Rank

local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local string, table, yesno = loader.require('String', 'Table', 'Yesno')

local rankData, rankAliases = loader.loadData('Rank/Data', 'Rank/Aliases')

local p = {}

-- Template:Rank Access Point function p.serverRank(frame) local args = getArgs(frame) local name = args[1] or args.rank local opts = { size = args.size and args.size..'px' or nil, bracket = yesno(args.brackets) or yesno(args.bracket) or yesno(args.br), }	return p._serverRank(name, opts) end

function p._serverRank(name, opts) local function colorize(text, c)		return string.wrapHtml(text, 'span', { class = ('format-%s'):format(c) }) end local function typeHandler(d) if type(d) == 'table' then d = table.deepCopy(d, true) d = #d < 2 and table.concat(d) or d		end return d	end local rank = rankData[rankAliases[string.upper(name)] or string.upper(name)] local bracket = opts.bracket or true local rankdisp, colorcode = typeHandler(rank.display), typeHandler(rank.colorcode) if type(colorcode) == 'table' then if type(rankdisp) == 'table' then rankdisp = table.concat(table.map(rankdisp, function(v, i)				return colorize(v, colorcode[i]) end)) else local r, s = string.match(rankdisp, '(%w+)(%++)') if r and s then rankdisp = ('%s%s'):format(colorize(r, colorcode[1]), colorize(s, colorcode[2])) else rankdisp = colorize(rankdisp, colorcode[1]) end end else if bracket and not rank.bracketcolor then rankdisp = colorize(('[%s]'):format(rankdisp), not bracket and (rank.bracketcolor or colorcode) or colorcode) bracket = false -- Done else rankdisp = colorize(rankdisp, not bracket and (rank.bracketcolor or colorcode) or colorcode) end end local text if bracket then local col = rank.bracketcolor or (type(colorcode) == 'table' and colorcode[1] or colorcode) text = ('%s%s%s'):format(			colorize('[', col),			rankdisp,			colorize(']', col)			) else text = rankdisp end local ret = ('%s'):format(		rank.index,		rank.link,		string.wrapHtml(text, 'span', { class = 'mcui-text', style = { display = 'inline', ['flex-wrap'] = 'wrap', ['font-size'] = opts.size, }		})	)	return mw.getCurrentFrame:preprocess(ret) end

return p