Module:Position history

From NPOWiki
Jump to navigation Jump to search

Documentation [edit]

This page is a stub - it only covers the very basics of its subject. More information should be added to make the page informative and useful. If no more information is available, the page should be considered for a merge, redirect, or deletion.

Details: documentation to be written

If you can correct the issue, please edit the page to do so, then remove this notice.
Please see Template:Position history for usage information. Use the template rather than invoking the module.

The above documentation is transcluded from Module:Position history/doc.

local datediff = require('Module:Date difference').call
local p = {}

local function argDefault(arg, default)
	if not arg or mw.text.trim(arg) == '' then
		return default or ''
	else
		return arg
	end
end

local function makeCell(content)
	return '\t\t<td>' .. content .. '</td>\n'
end

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

function p.call(args)
	local incumbentString = '&mdash;'
	local html = ''
	local num = 1
	local row, holder, startDate, endDate
	
	repeat
		holder = argDefault(args[num], '{{{' .. num .. '}}}')
		startDate = argDefault(args[num + 1], 'unknown')
		endDate = argDefault(args[num + 2], 'unknown')
		row = '\t<tr>\n'
		if (endDate == 'unknown' or endDate == incumbentString) and num == 1 then
			endDate = incumbentString
			row = '\t<tr style="font-weight:bold;">\n'
		end
		
		row = row .. makeCell(startDate) .. makeCell(holder) .. makeCell(endDate)
		if startDate ~= 'unknown' and endDate ~= 'unknown' then
			if endDate == incumbentString then
				row = row .. makeCell(datediff({ startDate }) .. ' Days')
			else
				row = row .. makeCell(datediff({ startDate, endDate }) .. ' Days')
			end
		else
			row = row .. makeCell('? Days')
		end
		row = row .. '\t</tr>\n'
		html = html .. row
		num = num + 3
	until not args[num]
	
	return html
end

return p