Jump to content

Module:Succession table monarch

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Izno (talk | contribs) at 00:09, 8 December 2022 (use standard wikitable (no reason for custom styles), simplify message use (nil messages simply display nothing, which should cue users in to needing the messages page)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getArgs = require('Module:Arguments').getArgs
local TableTools = require('Module:TableTools')
local messages = mw.loadData('Module:Succession table monarch/messages')

local p = {}

p.fromArgs = function(argElements)
	local mainTag = mw.html.create('table')
		:addClass('wikitable')
		:css('text-align', 'center')
		:tag('tr')
			:tag('th'):wikitext(messages.name):done()
			:tag('th'):wikitext(messages.lifespan):done()
			:tag('th'):wikitext(messages.reignStart):done()
			:tag('th'):wikitext(messages.reignEnd):done()
			:tag('th'):wikitext(messages.notes):done()
			:tag('th'):wikitext(messages.family):done()
			:tag('th'):wikitext(messages.image):done()
			:done()
	
	for _,eachElement in ipairs(argElements) do
		if eachElement.name then
			local namePlainList = ''
			if eachElement.nickname or eachElement.native then
				namePlainList = mw.getCurrentFrame():expandTemplate{
					title = messages.plainlistTemplateName or 'Plainlist',
					args = {'\n' .. 
						table.concat(TableTools.compressSparseArray({
							eachElement.nickname and ('* ' .. tostring(mw.html.create('small'):tag('i'):wikitext(eachElement.nickname))) or nil,
							eachElement.native and ('* ' .. eachElement.native) or nil
					}), '\n')}
				}
			end
			local rowTr = mainTag:tag('tr')
			
			rowTr:tag('td')
					:css('vertical-align: middle;')
					:wikitext(eachElement.name .. namePlainList)
					:done()
				:tag('td')
					:wikitext(eachElement.life)
				:tag('td')
					:wikitext(eachElement.reignstart)
				:tag('td')
					:wikitext(eachElement.reignend)
				:tag('td')
					:wikitext(eachElement.notes)
				:tag('td')
					:wikitext(eachElement.family)
			
			local imageTd = rowTr
				:tag('td')
			if eachElement.image then
				imageTd:tag('span')
					:addClass('photo')
					:wikitext('[[File:' .. eachElement.image .. '|80px|alt=' .. (eachElement.alt or '') .. ']]')
			end
		end
	end
	return tostring(mainTag)
end

p.fromArray = function(args)
	local argElements = TableTools.numData(args, true)
	return p.fromArgs(argElements)
end

p.fromFrame = function(frame)
	local args = getArgs(frame)
	return p.fromArray(args)
end

return p