Module:Soldier: Difference between revisions
Military sidebar: years/battles/ribbons + branch emblems |
Military sidebar: years/battles/ribbons + branch emblems |
||
| Line 1,276: | Line 1,276: | ||
end | end | ||
end | end | ||
-- One table per row so short rows (e.g. 2 ribbons) center like full rows | |||
local out = {} | local out = {} | ||
for _, cells in ipairs(rows) do | for _, cells in ipairs(rows) do | ||
table.insert(out, '{| class="soldier-ribbon-rack"') | |||
table.insert(out, '|-') | table.insert(out, '|-') | ||
for _, file in ipairs(cells) do | for _, file in ipairs(cells) do | ||
| Line 1,284: | Line 1,285: | ||
table.insert(out, '| [[File:' .. file .. '|106px|link=]]') | table.insert(out, '| [[File:' .. file .. '|106px|link=]]') | ||
end | end | ||
table.insert(out, '|}') | |||
end | end | ||
return table.concat(out, '\n') | return table.concat(out, '\n') | ||
end | |||
local function awardGridColspanUnits(rows) | |||
-- LCM of row lengths so 2-cell and 3-cell rows share one table width | |||
local function gcd(a, b) | |||
while b ~= 0 do | |||
a, b = b, a % b | |||
end | |||
return a | |||
end | |||
local function lcm(a, b) | |||
if a == 0 or b == 0 then | |||
return a + b | |||
end | |||
return (a / gcd(a, b)) * b | |||
end | |||
local units = 0 | |||
for _, cells in ipairs(rows) do | |||
local n = #cells | |||
if n > 0 then | |||
units = lcm(units, n) | |||
end | |||
end | |||
return units > 0 and units or 1 | |||
end | end | ||
| Line 1,294: | Line 1,319: | ||
return '' | return '' | ||
end | end | ||
local | local units = awardGridColspanUnits(rows) | ||
local out = { '{| class="wikitable soldier-awards-grid"' } | |||
for _, cells in ipairs(rows) do | for _, cells in ipairs(rows) do | ||
table.insert(out, '|-') | local n = #cells | ||
if n == 0 then | |||
-- skip | |||
else | |||
local span = units / n | |||
table.insert(out, '|-') | |||
for _, cell in ipairs(cells) do | |||
-- Allow <br /> from Wikipedia-style multi-line labels | |||
table.insert(out, '| colspan="' .. tostring(span) .. '" | ' .. cell) | |||
end | |||
end | end | ||
end | end | ||
| Line 1,307: | Line 1,339: | ||
local function formatAwardsLegend(raw) | local function formatAwardsLegend(raw) | ||
raw = | -- Do not run prettyProse/prettyPlace — commas in prose (e.g. statue note) | ||
-- get misread as place names and Title-Cased / rewrapped. | |||
raw = trim(raw) | |||
if raw == '' then | if raw == '' then | ||
return '' | return '' | ||
end | end | ||
local parts = {} | local parts = {} | ||
raw = mw.ustring.gsub(raw, '<br%s*/?>', ';') | raw = mw.ustring.gsub(raw, '<br%s*/?>', ';') | ||
| Line 1,318: | Line 1,351: | ||
part = mw.ustring.gsub(part, '^%*%s*', '') | part = mw.ustring.gsub(part, '^%*%s*', '') | ||
if part ~= '' then | if part ~= '' then | ||
if isAllCapsPhrase(part) then | |||
part = prettyTitle(part, true) | |||
end | |||
table.insert(parts, '* ' .. part) | table.insert(parts, '* ' .. part) | ||
end | end | ||