Module:InfoboxMinimal: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
-- Module:InfoboxMinimal | -- Module:InfoboxMinimal | ||
local p = {} | local p = {} | ||
local function | local function blank(s) return not s or mw.text.trim(tostring(s)) == '' end | ||
local function get(inv, par, key) return (inv and inv[key]) or (par and par[key]) end | |||
local function addRow(root, label, data) | |||
if blank(data) then return end | |||
local tr = root:tag('tr') | |||
local function addRow( | |||
if | |||
local tr = | |||
tr:tag('th'):attr('scope','row'):addClass('infobox-label'):wikitext(label or '') | tr:tag('th'):attr('scope','row'):addClass('infobox-label'):wikitext(label or '') | ||
tr:tag('td'):addClass('infobox-data'):wikitext(data) | tr:tag('td'):addClass('infobox-data'):wikitext(data) | ||
| Line 17: | Line 13: | ||
function p.infobox(frame) | function p.infobox(frame) | ||
local | local inv = frame.args -- args set in #invoke (wrapper template) | ||
local | local par = frame:getParent() and frame:getParent().args or {} -- args from the calling page | ||
local classes = 'infobox' | local classes = 'infobox' | ||
local bodyclass = get( | local bodyclass = get(inv, par, 'bodyclass') | ||
if not | if not blank(bodyclass) then classes = classes .. ' ' .. bodyclass end | ||
local root = mw.html.create('table'):addClass(classes):attr('role','presentation') | local root = mw.html.create('table'):addClass(classes):attr('role','presentation') | ||
local title = get( | local title = get(inv, par, 'title') or get(inv, par, 'name') or mw.title.getCurrentTitle().baseText | ||
root:tag('caption'):addClass('infobox-title'):wikitext(title) | root:tag('caption'):addClass('infobox-title'):wikitext(title) | ||
-- scan generously; stops naturally on blank data | |||
for i = 1, 100 do | for i = 1, 100 do | ||
addRow(root, get(inv, par, 'label'..i), get(inv, par, 'data'..i)) | |||
end | end | ||