Module:Infobox MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Added code for a multisection-multilink infobox (with test code); intended to decouple the 8-link infobox from infobox-mos
Ganaram inukshuk (talk | contribs)
Made multisection-infobox function support 2-link and 0-link case, based on the number of links passed in
Line 444: Line 444:


-- Multisection multilink infobox
-- Multisection multilink infobox
function p.build_multisection_multilink(title, sections, adjacent_links)
-- The following must be passed in:
-- - Title (self-explanatory)
-- - Sections (see comments for details)
-- - Adjacent links; supports 0, 2, or 8 adjacent links
function p.build_multisection(title, sections, adjacent_links)
-- Boilerplate stuff
-- Boilerplate stuff
local s = '<div style="\n'
local s = '<div style="\n'
Line 462: Line 466:
-- Adjacent links
-- Adjacent links
-- Links surround the title, forming a 3x3 grid as such:
-- If there are two adjacent links (such as with edos), then links
-- will be placed on the left and right of the title
-- [Link 1] Title [Link 2]
-- - Link 1 is previous, link 2 is next
-- If there are eight adjacent links (such as with mosses), then
-- links surround the title, forming a 3x3 grid as such:
-- [Link 1] [Link 2] [Link 3]
-- [Link 1] [Link 2] [Link 3]
-- [Link 4] [Title ] [Link 5]
-- [Link 4]   Title [Link 5]
-- [Link 6] [Link 7] [Link 8]
-- [Link 6] [Link 7] [Link 8]
-- - 1: prev_A, prev_B
-- - 1: prev_A, prev_B
Line 474: Line 483:
-- - 7: next_B,   
-- - 7: next_B,   
-- - 8: next_A, next_B
-- - 8: next_A, next_B
s = s .. '<table style="width: 100%; margin: 0"><tr>'
-- Leaving this field nil defaults to only having the title; individual
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
-- links, as with "border" cases (eg, nothing comes before 0edo), can be
.. (adjacent_links[1] or "")
-- left blank.
.. '</td>'
if adjacent_links == nil then
.. '<td style="\n'  
s = s .. title
.. 'width: 50%; padding-left: 1em; padding-right: 1em; text-align: center; font-size: smaller">'
s = s .. '\n'
.. (adjacent_links[2] or "")
elseif #adjacent_links == 2 then
.. '\n</td><td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
local prev_link = adjacent_links[1]
.. (adjacent_links[3] or "")
local next_link = adjacent_links[2]
.. '</td>'  
s = s
.. '\n<tr>'
.. '<table style="width: 100%; margin: 0"><tr>'
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
.. (adjacent_links[4] or "")
.. (prev_link or "")
.. '</td>'
.. "</td>"
.. '<td style="width: 50%; padding-left: 1em; padding-right: 1em; text-align: center">'
.. '<td style="width: 70%; padding-left: 1em; padding-right: 1em; text-align: center">'
.. title
.. title
.. '</td>'
.. "</td>"
.. '<td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
.. '<td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
.. (adjacent_links[5] or "")
.. (next_link or "")
.. '</td>'
.. "</td>"
.. '</tr>'
.. "</tr></table>"
.. '<tr>'
s = s .. '\n'
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
elseif #adjacent_links == 8 then
.. (adjacent_links[6] or "")
s = s .. '<table style="width: 100%; margin: 0"><tr>'
.. '</td><td style="\n'  
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
.. 'width: 50%; padding-left: 1em; padding-right: 1em; text-align: center; font-size: smaller">'
.. (adjacent_links[1] or "")
.. (adjacent_links[7] or "")
.. '</td>'
.. '\n</td>'
.. '<td style="\n'  
.. '<td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
.. 'width: 50%; padding-left: 1em; padding-right: 1em; text-align: center; font-size: smaller">'
.. (adjacent_links[8] or "")
.. (adjacent_links[2] or "")
.. '</td>'
.. '\n</td><td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
.. '</tr>'
.. (adjacent_links[3] or "")
..  '</table>'
.. '</td>'  
s = s .. '\n'
.. '\n<tr>'
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
.. (adjacent_links[4] or "")
.. '</td>'
.. '<td style="width: 50%; padding-left: 1em; padding-right: 1em; text-align: center">'
.. title
.. '</td>'
.. '<td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
.. (adjacent_links[5] or "")
.. '</td>'
.. '</tr>'
.. '<tr>'
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
.. (adjacent_links[6] or "")
.. '</td><td style="\n'  
.. 'width: 50%; padding-left: 1em; padding-right: 1em; text-align: center; font-size: smaller">'
.. (adjacent_links[7] or "")
.. '\n</td>'
.. '<td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
.. (adjacent_links[8] or "")
.. '</td>'
.. '</tr>'
..  '</table>'
s = s .. '\n'
else
s = s .. title
s = s .. '\n'
end
-- Build up sections
-- Build up sections
-- In code, sections are built up as an array of pairs, coded as such:
-- {{"Header", entries}, {"Header", entries}}
-- Each set of entries is also built up as an array of pairs, as such:
-- {{"Caption 1", "Text 1"}, {"Caption 2", "Text 2"}}
-- Sections are written in order in which they appear, as are their
-- respective entries.
-- Section headers may be blank, written as ""
for _, section in ipairs(sections) do
for _, section in ipairs(sections) do
-- Get the header and entries
local header = section[1]
local header = section[1]
local entries = section[2]
local entries = section[2]
Line 584: Line 627:
}
}
return p.build_multisection_multilink("5L 2s (2/1-equivalent)", sections, adjacent_links)
return p.build_multisection("5L 2s (2/1-equivalent)", sections, adjacent_links)
end
end


return p
return p