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(args[1] or args.rank, opts) end

function p._serverRank(name, opts) local function colorize(text, c)		return string.wrapHtml(text, 'span', { class = ('format-%s'):format(c) }) end local name = rankAliases[string.upper(name)] local rank = rankData[name] local rankdisp, colorcode = rank.display, rank.colorcode -- Table handler if type(colorcode) == 'table' then colorcode = table.deepCopy(colorcode, true) colorcode = #colorcode < 2 and table.concat(colorcode) or colorcode end -- Second check after table handling 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(table.concat(rankdisp), colorcode[1]) end end else rankdisp = colorize(			type(rankdisp) == 'table' and table.concat(rankdisp) or rankdisp,			not opts.bracket and (rank.bracketcolor or colorcode) or colorcode		) end local text if opts.bracket then if rank.bracketcolor then text = ('%s%s%s'):format(				colorize('[', rank.bracketcolor),				rankdisp,				colorize(']', rank.bracketcolor)				) else text = ('[%s]'):format(rankdisp) end 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