Module:Utilities

From mcr

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

local p = {}

function p.process_param(param)

	s = mw.text.trim( param )

	s = string.gsub( s, '%s*,%s*', ',' )
	s = string.gsub( s, ',+', ',' )
	if ( string.match( s, ',$' ) ) then
		s = string.sub( s, 1, #s - 1 )
	end
	if ( string.find( s, ',' ) == 1 ) then
		length = 0 - #s + 1
		s = string.sub( s, length )
	end
	if #s == 0 then
		return ''
	end

	return mw.text.split( s, ",", true )
end

function p.parseMultiple(frame)

	items = p.process_param(frame.args[1])

	table.sort( items, lowercompare )

	links = {}
	for k,v in pairs(items) do
		links[k] = frame:expandTemplate{ title = frame.args[2], args = { v } }
	end

	return table.concat( links, frame.args[3] );
end

function lowercompare(a,b)
	return string.lower(a) < string.lower(b)
end

return p