Module:Infobox: Difference between revisions
mNo edit summary |
update todo; switch from array to associative array for row content; may break dependent templates |
||
| Line 6: | Line 6: | ||
local p = {} | local p = {} | ||
-- TODO ( | -- TODO (medium priority): | ||
-- - Allow for headerless data rows and dataless header rows. | |||
-- - Allow for headerless data rows and dataless header rows | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 22: | Line 20: | ||
local rows = args["Rows" ] | local rows = args["Rows" ] | ||
local footer_row = args["Footer"] | local footer_row = args["Footer"] | ||
local name = args["name"] | local name = args["name"] | ||
-- Nested helper function | -- Nested helper function | ||
| Line 67: | Line 65: | ||
-- Produces a row in the infobox | -- Produces a row in the infobox | ||
function infobox_row(row_content) | function infobox_row(row_content) | ||
local header = row_content["Header"] | |||
local data = row_content["Data" ] | |||
if #row_content > 1 then | if #row_content > 1 then | ||
local lines = {} | local lines = {} | ||
table.insert(lines, '|-') | table.insert(lines, '|-') | ||
table.insert(lines, '| style="text-align: right; padding-right: 0.25em;" | ' .. | table.insert(lines, '| style="text-align: right; padding-right: 0.25em;" | ' .. header) | ||
table.insert(lines, '| style="background-color: white; padding-left: 0.25em; font-weight: bold;" | ' .. | table.insert(lines, '| style="background-color: white; padding-left: 0.25em; font-weight: bold;" | ' .. data) | ||
return table.concat(lines, "\n") | return table.concat(lines, "\n") | ||
| Line 77: | Line 78: | ||
local lines = {} | local lines = {} | ||
table.insert(lines, '|-') | table.insert(lines, '|-') | ||
table.insert(lines, '| colspan="2" style="text-align: center;" | ' .. | table.insert(lines, '| colspan="2" style="text-align: center;" | ' .. data) | ||
return table.concat(lines, "\n") | return table.concat(lines, "\n") | ||
| Line 107: | Line 108: | ||
-- Infobox boilerplate | -- Infobox boilerplate | ||
table.insert(lines, [[<div style=" | table.insert(lines, | ||
[[<div style=" | |||
border: 1px solid #999; | border: 1px solid #999; | ||
margin: 0; | margin: 0; | ||
| Line 146: | Line 148: | ||
-- End of infobox | -- End of infobox | ||
table.insert(lines, "|}</div>") | table.insert(lines, "|}") | ||
table.insert(lines, "</div>") | |||
return table.concat(lines, "\n") | return table.concat(lines, "\n") | ||
| Line 244: | Line 247: | ||
-- These functions are kept in the meantime to support older infoboxes and WILL | -- These functions are kept in the meantime to support older infoboxes and WILL | ||
-- be entirely deleted later! Please switch to the new functions! | -- be entirely deleted later! Please switch to the new functions! | ||
-- Helper function; preprocess infobox rows from old format to new format | |||
function p.preprocess_entries(entries) | |||
local processed = {} | |||
for i = 1, #entries do | |||
local entry = entries[i] | |||
if #entry == 1 then | |||
table.insert(processed, { ["Header"] = entry[1] }) | |||
elseif #entry == 2 then | |||
table.insert(processed, { ["Header"] = entry[1], ["Data"] = entry[2] }) | |||
end | |||
end | |||
return processed | |||
end | |||
-- Original function signature, kept for legacy support (for now). | -- Original function signature, kept for legacy support (for now). | ||
| Line 250: | Line 268: | ||
["Adjacent Links"] = { (prev_link or ""), (next_link or "") }, | ["Adjacent Links"] = { (prev_link or ""), (next_link or "") }, | ||
["Title"] = title, | ["Title"] = title, | ||
["Rows"] = entries, | ["Rows"] = p.preprocess_entries(entries), | ||
} | } | ||
| Line 261: | Line 279: | ||
["Adjacent Links"] = adjacent_links, | ["Adjacent Links"] = adjacent_links, | ||
["Title"] = title, | ["Title"] = title, | ||
["Rows"] = entries, | ["Rows"] = p.preprocess_entries(entries), | ||
} | } | ||