Module:InfoboxMinimal: Difference between revisions
Created page with "-- Module:InfoboxMinimal local p = {} local function isBlank(s) if s == nil then return true end s = tostring(s) return mw.text.trim(s) == '' end local function addRow(tbl, label, data) if isBlank(data) then return end local tr = tbl:tag('tr') tr:tag('th') :attr('scope', 'row') :addClass('infobox-label') :wikitext(label or '') tr:tag('td') :addClass('infobox-data') :wikitext(data) end function p.infobox(frame) -- Prefer parent args so wrapper templat..." |
No edit summary |
||
| Line 1: | Line 1: | ||
-- Module:InfoboxMinimal | -- Module:InfoboxMinimal (patched) | ||
local p = {} | local p = {} | ||
local function isBlank(s) | local function isBlank(s) return not s or mw.text.trim(tostring(s)) == '' end | ||
local function get(args1, args2, key) | |||
-- prefer wrapper (#invoke) args, then parent (template) args | |||
return (args1 and args1[key]) or (args2 and args2[key]) | |||
end | end | ||
| Line 11: | Line 12: | ||
if isBlank(data) then return end | if isBlank(data) then return end | ||
local tr = tbl:tag('tr') | local tr = tbl:tag('tr') | ||
tr:tag('th') | tr:tag('th'):attr('scope','row'):addClass('infobox-label'):wikitext(label or '') | ||
tr:tag('td'):addClass('infobox-data'):wikitext(data) | |||
tr:tag('td') | |||
end | end | ||
function p.infobox(frame) | function p.infobox(frame) | ||
-- | local invokeArgs = frame.args -- from {{#invoke:...| key = value }} | ||
local | local parentArgs = frame:getParent() and frame:getParent().args or {} -- from {{Infobox_Startup|...}} | ||
local classes = 'infobox' | local classes = 'infobox' | ||
if not isBlank( | local bodyclass = get(invokeArgs, parentArgs, 'bodyclass') | ||
if not isBlank(bodyclass) then classes = classes .. ' ' .. bodyclass end | |||
local root = mw.html.create('table') | local root = mw.html.create('table'):addClass(classes):attr('role','presentation') | ||
local title = get(invokeArgs, parentArgs, 'title') or | |||
local title = | get(invokeArgs, parentArgs, 'name') or | ||
root:tag('caption') | mw.title.getCurrentTitle().baseText | ||
root:tag('caption'):addClass('infobox-title'):wikitext(title) | |||
for i = 1, 100 do | for i = 1, 100 do | ||
local label = get(invokeArgs, parentArgs, 'label'..i) | |||
local data = get(invokeArgs, parentArgs, 'data' ..i) | |||
addRow(root, label, data) | |||
end | end | ||