Module:List

From NPOWiki
Revision as of 21:45, 21 August 2020 by Bobogoobo (talk | contribs) (probably not going to use most of these options ever, but here it is)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local p = {}

local function defArg(arg)
	return arg and mw.text.trim(arg) ~= ''
end

function p.main(frame)
	return p.call(frame:getParent().args)
end

function p.call(args)
	local code = ''
	local nowrap = defArg(args.nowrap)
	local sep = '•'
	local spacebefore = true
	local spaceafter = true
	
	if defArg(args.nospace) then
		spacebefore = false
		spaceafter = false
	else
		if defArg(args.nospacebefore) then
			spacebefore = false
		end
		if defArg(args.nospaceafter) then
			spaceafter = false
		end
	end
	if defArg(args.sep) then
		sep = mw.text.trim(args.sep)
	elseif defArg(args.nosep) then
		sep = ''
	end
	if spacebefore then
		sep = ' ' .. sep
	end
	if spaceafter then
		sep = sep .. ' '
	end
	
	for i, arg in ipairs(args) do
		if defArg(arg) then
			if nowrap then
				arg = '<span style="white-space:nowrap;">' .. arg .. '</span>'
			end
			if code == '' then
				code = code .. arg
			else
				code = code .. sep .. arg
			end
		end
	end
	return code
end

return p