Difference between revisions of "Module:Infobox cabinet members"
Jump to navigation
Jump to search
test>Zackmann08 (Adding below) |
test>Zackmann08 (adding overrides for labels) |
||
| Line 70: | Line 70: | ||
:tag('tr') | :tag('tr') | ||
:tag('th') | :tag('th') | ||
| − | :wikitext('Office') | + | :wikitext(args.office_label or 'Office') |
:tag('th') | :tag('th') | ||
| − | :wikitext('Name') | + | :wikitext(args.name_label or 'Name') |
:tag('th') | :tag('th') | ||
| − | :wikitext('Party') | + | :wikitext(args.party_label or 'Party') |
:tag('th') | :tag('th') | ||
| − | :wikitext('Term') | + | :wikitext(args.term_label or 'Term') |
:tag('tr') | :tag('tr') | ||
:tag('td') | :tag('td') | ||
Revision as of 18:26, 21 September 2018
| 40x40px | This module is rated as ready for general use. It has reached a mature form and is thought to be 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. |
Usage
See: Template:Infobox cabinet members
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'
if args.caption then
args.caption = '<br />' .. tostring(
mw.html.create('span')
:cssText(args.captionstyle)
:wikitext(args.caption)
)
end
if args.topcaption then
args.topcaption = '<br />' .. tostring(
mw.html.create('span')
:cssText(args.topcaptionstyle)
:wikitext(args.topcaption)
)
end
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(require('Module:InfoboxImage').InfoboxImage{args = {
image = args.topimage,
size = args.topimagesize,
sizedefault = 'frameless',
upright = 1,
alt = args.topimagealt
}} .. (args.topcaption or '')
)
: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'])
:tag('tr'):tag('td')
:attr('colspan', columns)
:css('text-align', 'center')
:wikitext(require('Module:InfoboxImage').InfoboxImage{args = {
image = args.image,
size = args.imagesize,
sizedefault = 'frameless',
upright = 1,
alt = args.imagealt
}} .. (args.caption or '')
)
:tag('tr')
:tag('th')
:wikitext(args.office_label or 'Office')
:tag('th')
:wikitext(args.name_label or 'Name')
:tag('th')
:wikitext(args.party_label or 'Party')
:tag('th')
:wikitext(args.term_label or '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
num = tonumber(num)
table.insert(officeNums, num)
end
local n,l = k:match('^name(%d+)([a-z])$')
if 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 i > 1 then
root:tag('tr')
:tag('td')
:attr('colspan',columns)
:css('background','#D1D1D1')
end
local r = subRows[num] or {}
table.sort(r)
local row = root:tag('tr')
row:tag('td')
:attr('rowspan', r and (#r > 1) and #r or nil)
:wikitext(args['office' .. num])
local subrow = 1
for j, l in ipairs(r) do
if subrow > 1 then
row:tag('tr')
end
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])
subrow = subrow + 1
end
end
if args.below then
root:tag('tr')
:tag('td')
:attr('colspan', columns)
:css('border-top', '#D1D1D1 2px solid')
:wikitext(args.below)
end
return tostring(root)
end
return p