Halo Esports Wiki

We are currently performing extensive maintenance to this wiki and as a result there will likely be errors. Please be patient while we work to fix all problems.

READ MORE

Halo Esports Wiki
[checked revision][checked revision]
(Syncing content across wikis)
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local util = require('Module:Util')
+
local util_args = require("Module:ArgsUtil")
  +
local util_text = require('Module:TextUtil')
   
 
local p = {}
 
local p = {}
Line 8: Line 9:
 
for k, v in ipairs(data.replace) do
 
for k, v in ipairs(data.replace) do
 
link = data.targetpage and data.targetpage[k] or string.gsub(title,
 
link = data.targetpage and data.targetpage[k] or string.gsub(title,
util.escape(data.find[k] or data.find[1]),
+
util_text.escape(data.find[k] or data.find[1]),
util.escape(data.replace[k]))
+
util_text.escape(data.replace[k]))
display = data.display and data.display[k] or string.format('View the corresponding %s page',data.tournament[k])
+
display = data.display and data.display[k] or string.format('View the corresponding %s page',(data.tournament and data.tournament[k] or ''))
 
links[k] = string.format('[[%s|%s]]', link, display)
 
links[k] = string.format('[[%s|%s]]', link, display)
 
end
 
end
Line 20: Line 21:
   
 
function p.main(frame)
 
function p.main(frame)
  +
local args = util_args.merge()
if frame == mw.getCurrentFrame() then
 
args = require('Module:ProcessArgs').merge(true)
 
else
 
frame = mw.getCurrentFrame()
 
end
 
 
local sep = args.sep or ','
 
 
 
for k, v in pairs(args) do
 
for k, v in pairs(args) do
args[k] = mw.text.split(args[k],sep)
+
args[k] = util_text.split(args[k], args.sep)
 
for k2, v2 in ipairs(args[k]) do
 
for k2, v2 in ipairs(args[k]) do
 
args[k][k2] = mw.text.trim(v2)
 
args[k][k2] = mw.text.trim(v2)

Latest revision as of 16:40, 18 August 2020

Documentation for this module may be created at Module:CorrespondingPageBox/doc

local util_args = require("Module:ArgsUtil")
local util_text = require('Module:TextUtil')

local p = {}

function p.makeBox(data)
	local title = mw.title.getCurrentTitle().prefixedText
	local links = {}
	for k, v in ipairs(data.replace) do
		link = data.targetpage and data.targetpage[k] or string.gsub(title,
			util_text.escape(data.find[k] or data.find[1]),
			util_text.escape(data.replace[k]))
		display = data.display and data.display[k] or string.format('View the corresponding %s page',(data.tournament and data.tournament[k] or ''))
		links[k] = string.format('[[%s|%s]]', link, display)
	end
	
	local tbl = mw.html.create('div'):addClass('correspondingpagebox')
	tbl:wikitext(table.concat(links,' | '))
	return tostring(tbl)
end

function p.main(frame)
	local args = util_args.merge()
	for k, v in pairs(args) do
		args[k] = util_text.split(args[k], args.sep)
		for k2, v2 in ipairs(args[k]) do
			args[k][k2] = mw.text.trim(v2)
		end
	end
	return p.makeBox(args)
end
return p