Module:Infobox MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Undo revision 136715 by Ganaram inukshuk (talk) (links to sisters broke)
Tag: Undo
Ganaram inukshuk (talk | contribs)
Added code for a multisection-multilink infobox (with test code); intended to decouple the 8-link infobox from infobox-mos
Line 351: Line 351:


end
end


function p.build(title, structure_entries, et_entries, adjacent_links, xenpaper_links)
function p.build(title, structure_entries, et_entries, adjacent_links, xenpaper_links)
Line 439: Line 441:
s = s .. '|}</div>'
s = s .. '|}</div>'
return s
return s
end
-- Multisection multilink infobox
function p.build_multisection_multilink(title, sections, adjacent_links)
-- Boilerplate stuff
local s = '<div style="\n'
.. "border: 1px solid #999;\n"
.. "margin: 0;\n"
.. "margin-left: 1em;\n"
.. "margin-bottom: 0.5em;\n"
.. "padding: 0.5em;\n"
.. "background-color: #f0f0f0;\n"
.. "min-width: 15em;\n"
.. "float: right;\n"
.. "max-width: 100%;\n"
.. "overflow: auto;\n"
.. '">\n'
.. '{| width="100%" style="border-collapse: collapse;"\n'
.. '|+ style="font-weight: bold; text-align: center;" | '
-- Adjacent links
-- Links surround the title, forming a 3x3 grid as such:
-- [Link 1] [Link 2] [Link 3]
-- [Link 4] [Title ] [Link 5]
-- [Link 6] [Link 7] [Link 8]
-- - 1: prev_A, prev_B
-- - 2: prev_B
-- - 3: next_A, prev_B
-- - 4: prev_A, 
-- - 5: next_A, 
-- - 6: prev_A, next_B
-- - 7: next_B, 
-- - 8: next_A, next_B
s = s .. '<table style="width: 100%; margin: 0"><tr>'
.. '<td style="width: 15%; text-align: left; white-space: nowrap; font-size: smaller">'
.. (adjacent_links[1] or "")
.. '</td>'
.. '<td style="\n'
.. 'width: 50%; padding-left: 1em; padding-right: 1em; text-align: center; font-size: smaller">'
.. (adjacent_links[2] or "")
.. '\n</td><td style="width: 15%; text-align: right; white-space: nowrap; font-size: smaller">'
.. (adjacent_links[3] or "")
.. '</td>'
.. '\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'
-- Build up sections
for _, section in ipairs(sections) do
local header = section[1]
local entries = section[2]
-- Section header
s = s .. '|-\n'
    .. '|colspan="2" style="text-align:center;"| <b>' .. (header or "") .. '</b>\n'
   
    -- Section entries
    for _, entry in ipairs(entries) do
if #entry > 1 then
local caption = entry[1]
local text = entry[2]
s = s
.. "|-\n"
.. '| style="text-align:right; padding-right: 0.25em" | '
.. caption
.. "\n"
.. '| style="background-color: white; padding-left: 0.25em; font-weight: bold" | '
.. text
.. "\n"
elseif #entry == 1 then
local text = entry[1]
s = s .. "|-\n" .. '| colspan="2" style="text-align: center;" | ' .. text .. "\n"
end
end
end
-- End of infobox
s = s .. "|}</div>"
return s
end
function p.tester()
local adjacent_links = { "4L 1s", "5L 1s", "6L 1s", "4L 2s", "6L 2s", "4L 3s", "5L 3s", "6L 3s" }
local section_1_entries = {
{"Brightest mode", "LLLsLLs"},
{"Period (cents)", "2\1 (1200¢)"},
{"Bright generator range", "4\7 (685.7¢) to 3\5 (720¢)"},
{"Dark generator range", "2\5 (480¢) to 3\7 (514.3¢)"}
}
local section_2_entries = {
{"Name", "diatonic"},
{"Prefix", "dia-"},
{"Abbrev.", "dia."}
}
local section_3_entries = {
{"Parent MOS", "2L 3s"},
{"Sister MOS", "2L 5s"},
{"Daughter MOSes", "7L 5s, 5L 7s"}
}
local section_4_entries = {
{"Supersoft (L:s = 4:3)", "15\\26 (692.3¢)"},
{"Soft (L:s = 3:2)", "11\\19 (694.7¢)"},
{"Semisoft (L:s = 5:3)", "18\\31 (696.8¢)"},
{"Basic (L:s = 2:1)", "7\\12 (700¢)"},
{"Semihard (L:s = 5:2)", "17\\29 (703.4¢)"},
{"Hard (L:s = 3:1)", "10\\17 (705.9¢)"},
{"Superhard (L:s = 4:1)", "13\\22 (709.1¢)"},
}
local sections = {
{"Scale structure", section_1_entries},
{"TAMNAMS information", section_2_entries},
{"Related scales", section_3_entries},
{"Simple equal tunings", section_4_entries},
}
return p.build_multisection_multilink("5L 2s (2/1-equivalent)", sections, adjacent_links)
end
end


return p
return p