Gears of War Esports Wiki
Gears of War Esports Wiki
m (Protected "Module:Util": Syncing content across wikis ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
m (Syncing content across wikis)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
  +
-- util
 
local m_text = require('Module:Text')
 
local m_text = require('Module:Text')
local util = {}
+
local p = {}
   
function util.makeFootnoteN(n)
+
function p.nowrap(text)
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>'
 
return '<span style="white-space:nowrap;">' .. text .. '</span>'
 
end
 
end
   
function util.escape(link)
+
function p.escape(link)
 
link = link or ''
 
link = link or ''
 
-- because of gsub not letting you have - unescaped
 
-- because of gsub not letting you have - unescaped
Line 47: Line 16:
 
end
 
end
   
function util.dplEscape(link)
+
function p.dplEscape(link)
 
link = link or ''
 
link = link or ''
 
link = string.gsub(link,'%(','\\%(')
 
link = string.gsub(link,'%(','\\%(')
Line 54: Line 23:
 
end
 
end
   
function util.titleTable(title)
+
function p.titleTable(title)
 
local title = title or mw.title.getCurrentTitle().text
 
local title = title or mw.title.getCurrentTitle().text
 
return m_text.split(title,'/')
 
return m_text.split(title,'/')
 
end
 
end
   
function util.concatSubpage(base, extension)
+
function p.concatSubpage(base, extension)
 
-- concatenate the two but don't add a / if the 2nd argument is empty or Overview
 
-- 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
 
if extension == 'Overview' or extension == '' or not extension then
Line 70: Line 39:
 
end
 
end
   
function util.concatSubpages(tbl, extension)
+
function p.concatSubpageSystem(base, extension)
  +
local systems = mw.loadData('Module:Systems')
  +
return p.concatSubpage(base, systems[extension])
 
end
  +
  +
function p.concatSystemSubpage(base, extension)
  +
local systems = mw.loadData('Module:Systems')
  +
return p.concatSubpage(systems[base], extension)
 
end
  +
  +
function p.concatSubpages(tbl, extension)
 
for k, v in pairs(tbl) do
 
for k, v in pairs(tbl) do
tbl[k] = util.concatSubpage(v, extension)
+
tbl[k] = p.concatSubpage(v, extension)
 
end
 
end
 
return
 
return
 
end
 
end
   
function util.serializeNumber(N)
+
function p.serializeNumber(N)
 
local chr = tostring(N):sub(-1)
 
local chr = tostring(N):sub(-1)
 
local lookup = { ['1'] = 'st', ['2'] = 'nd', ['3'] = 'rd' }
 
local lookup = { ['1'] = 'st', ['2'] = 'nd', ['3'] = 'rd' }
Line 83: Line 62:
 
end
 
end
   
return util
+
return p

Latest revision as of 05:48, 31 August 2018

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


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

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

function p.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 p.dplEscape(link)
	link = link or ''
	link = string.gsub(link,'%(','\\%(')
	link = string.gsub(link,'%)','\\%)')
	return link
end

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

function p.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 p.concatSubpageSystem(base, extension)
	local systems = mw.loadData('Module:Systems')
	return p.concatSubpage(base, systems[extension])
end

function p.concatSystemSubpage(base, extension)
	local systems = mw.loadData('Module:Systems')
	return p.concatSubpage(systems[base], extension)
end

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

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

return p