Module:ApplyPattern

From Holdfast: Nations At War
Revision as of 14:45, 17 August 2019 by Falo (talk | contribs)
Jump to navigation Jump to search

Custom module to apply either some wiki markup or a template to each item in a comma delimited list. Look at Template:Class for examples.


local p = {}
function p.apply(frame)
	local list = frame.args[1]
	local pattern = frame.args[2]
	local result = ""
	local sep = ','
	
	for entry in {list:match((list:gsub("[^"..sep.."]*"..sep, "([^"..sep.."]*)"..sep)))} do
		result = result .. string.gsub(pattern, '%%pattern%%',entry)
	end
	
    return result
end
return p