Gears of War Esports Wiki
Advertisement

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


local m_text = require('Module:Text')
local util = {}

function util.makeFootnoteN(n)
	if n and n ~= "" then
		return string.format("<sup>%s</sup>", n)
	end
	return ""
end

function util.vsAlign(team1, team2)
	local tbl = mw.html.create("div")
	tbl:css({ width = "100%", display = "table", ["table-layout"] = "fixed" })
	tbl:tag("div")
		:css({ width = "calc(50% - 10px)", ["text-align"] = "right", display = "table-cell" })
		:wikitext(team1)
	:done()
	:tag("div")
		:css({ display = "table-cell", width = "20px", ["text-align"] = "center" })
		:wikitext(" vs ")
	:done()
	:tag("div")
		:css({ width = "calc(50% - 10px)", ["text-align"] = "left", display = "table-cell" })
		:wikitext(team2)
	:done()
		
	return tbl
end

function util.makeHTML(text)
	local tbl = mw.html.create()
		:wikitext(text)
	return tbl
end

function util.nowrap(text)
	return '<span style="white-space:nowrap;">' .. text .. '</span>'
end

function util.escape(link)
	link = link or ''
	-- because of gsub not letting you have - unescaped
	link = string.gsub(link,'%-','%%%-')
	link = string.gsub(link,'%(','%%%(')
	link = string.gsub(link,'%)','%%%)')
	return link
end

function util.dplEscape(link)
	link = link or ''
	link = string.gsub(link,'%(','\\%(')
	link = string.gsub(link,'%)','\\%)')
	return link
end

function util.titleTable(title)
	local title = title or mw.title.getCurrentTitle().text
	return m_text.split(title,'/')
end

function util.concatSubpage(base, extension)
	-- concatenate the two but don't add a / if the 2nd argument is empty or Overview
	if extension == 'Overview' or extension == '' or not extension then
		return base
	elseif base == '' or not base then
		return extension
	else
		return base .. '/' .. extension
	end
end

function util.concatSubpages(tbl, extension)
	for k, v in pairs(tbl) do
		tbl[k] = util.concatSubpage(v, extension)
	end
	return
end

function util.serializeNumber(N)
	local chr = tostring(N):sub(-1)
	local lookup = { ['1'] = 'st', ['2'] = 'nd', ['3'] = 'rd' }
	return chr .. (lookup[chr] or 'th')
end

return util
Advertisement