Apex Legends Esports Wiki

READ MORE

Apex Legends Esports Wiki
Advertisement

To edit the documentation or categories for this module, click here.


local util_args = require('Module:ArgsUtil')

local classes = {
	header = {
		tab = 'tabheader-tab',
		active = 'tabheader-active',
		outer = 'tabheader-top'
	},
	title = {
		tab = 'titletabs-tab',
		active = 'titletabs-active',
		outer = 'titletabs-tabs'
	}
}

local p = {}

function p.fromArgs(frame)
	local args = util_args.merge(true)

	local output = {}
	local this = tonumber(args.This)
	local title = mw.title.getCurrentTitle().prefixedText
	local sep = '%s*' .. (args.sep or ',') .. '%s*'
	
	if args.links then
		names = args.names and mw.text.split(args.names,sep) or {}
		links = args.links:gsub('_',' ')
		for k, v in ipairs(mw.text.split(links,sep)) do
			output[k] = string.format('[[%s|%s]]',
				v,
				args['name' .. k] or names[k] or v
			)
			if v == title then
				this = k
			end
		end
	else
		local i = 1
		while args['link' .. i] do
			output[i] = string.format('[[%s|%s]]',
				args['link' .. i],
				args['name'.. i] or args['link' .. i]
			)
			i = i + 1
		end
	end
	
	return p.main(output, this, args)
end

function p.fromTables(names, links, this, settings)
	local output = {}
	for k, v in ipairs(links) do
		output[k] = string.format('[[%s|%s]]',
			v,
			names[k] or v
		)
	end
	return p.main(output, this, settings)
end

function p.main(links, this, settings)
	if not settings then settings = {} end
	local class = settings.tabstype or 'header'
	local tbl = p.initialize(settings, class)
	for k, v in ipairs(links) do
		p.makeTab(tbl, class, v, k == this)
	end
	local f = mw.getCurrentFrame()
	f:callParserFunction('#vardefine:tabThis',this)
	return tostring(tbl)
end

function p.initialize(settings, class)
	return mw.html.create('div')
		:addClass(classes[class].outer)
		:css({ ['background-color'] = settings.backgroundcolor })
end

function p.makeTab(tbl, class, v, isthis)
	tbl:tag('div')
		:addClass(classes[class].tab)
		:addClass(isthis and classes[class].active or '')
		:wikitext(v)
	return
end

return p
Advertisement