Module:Infobox: Difference between revisions
move preprocess function as a nested function; refactor link-detector code |
Add infobox class |
||
| (4 intermediate revisions by one other user not shown) | |||
| Line 7: | Line 7: | ||
local p = {} | local p = {} | ||
-- TODO (medium priority): | -- TODO (medium priority): | ||
-- - Use templatestyles | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 131: | Line 132: | ||
-- Infobox boilerplate | -- Infobox boilerplate | ||
table.insert(lines, | table.insert(lines, | ||
[[<div style=" | [[<div class="infobox" style=" | ||
border: 1px solid #999; | border: 1px solid #999; | ||
margin: 0; | margin: 0; | ||
| Line 212: | Line 213: | ||
local is_upper_lower_links_present = | local is_upper_lower_links_present = | ||
any_keys_present(args, upper_links) or any_keys_present(args, lower_links) | any_keys_present(args, upper_links) or any_keys_present(args, lower_links) | ||
local is_side_links_present = any_keys_present(args, side_links) | |||
-- Build adjacent_links | -- Build adjacent_links | ||
-- Links from args are removed, as they're stored in a separate table | |||
local adjacent_links = {} | local adjacent_links = {} | ||
if is_upper_lower_links_present then | if is_upper_lower_links_present then | ||
| Line 219: | Line 222: | ||
for _, key in ipairs(upper_links) do | for _, key in ipairs(upper_links) do | ||
table.insert(adjacent_links, args[key] or "") | table.insert(adjacent_links, args[key] or "") | ||
args[key] = nil | |||
end | end | ||
-- Middle row of links | -- Middle row of links | ||
for _, key in ipairs(side_links) do | for _, key in ipairs(side_links) do | ||
table.insert(adjacent_links, args[key] or "") | table.insert(adjacent_links, args[key] or "") | ||
args[key] = nil | |||
end | end | ||
-- Bottom row of links | -- Bottom row of links | ||
for _, key in ipairs(lower_links) do | for _, key in ipairs(lower_links) do | ||
table.insert(adjacent_links, args[key] or "") | table.insert(adjacent_links, args[key] or "") | ||
args[key] = nil | |||
end | end | ||
elseif is_side_links_present then | |||
-- Left and right links only | -- Left and right links only | ||
for _, key in ipairs(side_links) do | for _, key in ipairs(side_links) do | ||
table.insert(adjacent_links, args[key] or "") | table.insert(adjacent_links, args[key] or "") | ||
args[key] = nil | |||
end | end | ||
end | end | ||
args["Adjacent Links"] = adjacent_links | args["Adjacent Links"] = adjacent_links | ||
-- Preprocess rows | -- Preprocess rows | ||