Fandom

Civilization

Module:TemplateUtils

6,858pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

local p = {}
 
-------------------------------
------- ExplodeForeach --------
-------------------------------
-- Arguments are as follow :
--1 = template name
--2 = a string to process
--3 = that string's separators
--delim = the delimiter between the resulting templates 
function p.ExplodeForeach(frame)
	local args = frame:getParent().args
	if args[2] == nil then return "" end
 
	local template = args[1]
	local inputs = mw.text.split( args[2], args[3])
	local delimiter = args.delim
 
	for i = 1, #inputs do
		if not (inputs[i] == "") then -- No empty strings will be processed
			inputs[i] = frame:expandTemplate{ title = template, args = { inputs[i] } }
		end
	end
 
	return table.concat( inputs, delimiter)
end
 
function p.Link(s, suffix)
	return "[["..s.." ("..suffix..")|"..s.."]]"
end
 
function p.RecreateTable(inputTable)
	local outputTable = {}
	for k,v in pairs(inputTable) do
		outputTable[k] = v
	end
	return outputTable
end
 
function p.LinkAll(t, suffix)
	t = p.RecreateTable(t)
	for i = 1, #t do
		t[i] = p.Link(t[i], suffix)
	end
	return table.concat(t,"<br/>")
end
 
function p.PreProcess(frame,s)
	return (frame and frame.preprocess and frame:preprocess(s)) or s
end
 
function p.UnpackArgs(args)
	return unpack(p.RecreateTable(args))
end
 
function p.Error(text)
	return string.format("<div class='error'>Error: %s</div>",text)
end
 
function p.CleanPageName(frame)
    local str = string.gsub(frame.args[1], " %(.*","")
    return str
end
 
return p

Also on Fandom

Random Wiki