Module:Infobox cabinet members
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module depends on the following other modules: |
Usage
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.infobox(frame, args)
if not args then
args = getArgs(frame)
end
mw.logObject(args)
local root = mw.html.create()
local columns = '4'
root = root
:tag('table')
:addClass('infobox')
:css('width', 'auto')
:css('text-align', 'left')
:css('line-height', '1.2em')
:css('margin-left', '1em')
:css('margin-right', '0em')
:css('float', 'right')
:css('clear', 'right')
root
:tag('tr'):tag('td')
:attr('colspan', columns)
:css('text-align', 'center')
:wikitext(args['topimage'])
:tag('tr'):tag('td')
:attr('colspan', columns)
:css('text-align', 'center')
:wikitext(args['topcaption'])
:tag('tr'):tag('th')
:attr('colspan', columns)
:css('line-height','1.5em')
:css('font-size','110%')
:css('background','#DCDCDC')
:css('text-align', 'center')
:wikitext(args['above'])
--TODO: Use infobox image!
:tag('tr'):tag('td')
:attr('colspan', columns)
:css('text-align', 'center')
:wikitext(args['image'])
:tag('tr'):tag('td')
:attr('colspan', columns)
:css('text-align', 'center')
:wikitext(args['caption'])
:tag('tr')
:tag('th')
:wikitext('Office')
:tag('th')
:wikitext('Name')
:tag('th')
:wikitext('Party')
:tag('th')
:wikitext('Term')
:tag('tr')
:tag('td')
:attr('colspan', columns)
:css('background', '#000')
local officeNums = {}
local subRows = {}
for k,v in pairs(args) do
k = tostring(k)
local num = k:match('^office(%d+)$')
if num then
table.insert(officeNums, tonumber(num))
if subRows[tonumber(num)] == nil then subRows[tonumber(num)] = {} end
end
local n,l = k:match('^name(%d)+([a-z])$')
if n and args['office' .. n] then
n = tonumber(n)
if subRows[n] == nil then subRows[n] = {} end
table.insert(subRows[n], l)
end
end
table.sort(officeNums)
mw.logObject(officeNums)
for i, num in ipairs(officeNums) do
num = tonumber(num)
if num > 1 then
root:tag('tr')
:tag('td')
:attr('colspan',columns)
:css('background','#D1D1D1')
end
local r = table.sort(subRows[num] or {})
if r then
local row = root:tag('tr')
row:tag('td')
:attr('rowspan', r and (#r > 1) and #r or nil)
:wikitext(args['office' .. num])
for j, l in ipairs(r) do
row:tag('th')
:css('font-weight', 'bold')
:wikitext(args['name'..num..l])
row:tag('td')
:wikitext(args['party'..num..l])
row:tag('td')
:wikitext(args['term'..num..l])
end
end
end
return tostring(root)
end
return p