Module:List: Difference between revisions

From NPOWiki
Jump to navigation Jump to search
(probably not going to use most of these options ever, but here it is)
 
No edit summary
 
Line 41: Line 41:
for i, arg in ipairs(args) do
for i, arg in ipairs(args) do
if defArg(arg) then
if defArg(arg) then
arg = mw.text.trim(arg)
if nowrap then
if nowrap then
arg = '<span style="white-space:nowrap;">' .. arg .. '</span>'
arg = '<span style="white-space:nowrap;">' .. arg .. '</span>'

Latest revision as of 03:28, 22 August 2020

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 = '&bull;'
	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
			arg = mw.text.trim(arg)
			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