Module:Infobox: Difference between revisions
From The Kodiak Republic Wiki
Content added Content deleted
(Fix "attempt to index upvalue 'origArgs' (a nil value)") |
(per discussion on the talkpage, now supports |autoheaders=y) |
||
Line 94: | Line 94: | ||
-- Adds a row to the infobox, with either a header cell |
-- Adds a row to the infobox, with either a header cell |
||
-- or a label/data cell combination. |
-- or a label/data cell combination. |
||
if rowArgs.header then |
if rowArgs.header and rowArgs.header ~= '_BLANK_' then |
||
root |
root |
||
:tag('tr') |
:tag('tr') |
||
Line 226: | Line 226: | ||
rowclass = args['imagerowclass' .. tostring(num)] |
rowclass = args['imagerowclass' .. tostring(num)] |
||
}) |
}) |
||
end |
|||
end |
|||
local function preprocessRows() |
|||
-- Gets the union of the header and data argument numbers, |
|||
-- and renders them all in order using addRow. |
|||
local rownums = union(getArgNums('header'), getArgNums('data')) |
|||
table.sort(rownums) |
|||
local lastheader |
|||
for k, num in ipairs(rownums) do |
|||
if args['header' .. tostring(num)] then |
|||
if lastheader then |
|||
args['header' .. tostring(lastheader)] = nil |
|||
end |
|||
lastheader = num |
|||
elseif args['data' .. tostring(num)] and args['data' .. tostring(num)]:gsub('%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]', ''):match('^%S') then |
|||
local data = args['data' .. tostring(num)] |
|||
if data:gsub('%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]', ''):match('%S') then |
|||
lastheader = nil |
|||
end |
|||
end |
|||
end |
|||
if lastheader then |
|||
args['header' .. tostring(lastheader)] = nil |
|||
end |
end |
||
end |
end |
||
Line 324: | Line 348: | ||
renderSubheaders() |
renderSubheaders() |
||
renderImages() |
renderImages() |
||
if args.autoheaders then |
|||
preprocessRows() |
|||
end |
|||
renderRows() |
renderRows() |
||
renderBelowRow() |
renderBelowRow() |
||
Line 473: | Line 500: | ||
return _infobox() |
return _infobox() |
||
end |
end |
||
return p |
return p |