Awards rack: no TOC steal; full awards list under ribbons
Wikipedia-style awards grid under ribbon rows
Line 1,211: Line 1,211:
end
end


local function formatAwardsRibbons(raw)
local function splitAwardRows(raw)
raw = trim(raw)
raw = trim(raw)
if raw == '' then
if raw == '' then
return ''
return {}
end
end
local files = {}
local rows = {}
for part in mw.text.gsplit(raw, ';', true) do
for row in mw.text.gsplit(raw, '|||', true) do
part = trim(part)
row = trim(row)
part = mw.ustring.gsub(part, '^[Ff]ile:', '')
if row ~= '' then
if part ~= '' then
local cells = {}
table.insert(files, part)
for cell in mw.text.gsplit(row, ';;', true) do
cell = trim(cell)
if cell ~= '' then
table.insert(cells, cell)
end
end
if #cells > 0 then
table.insert(rows, cells)
end
end
end
end
end
if #files == 0 then
return rows
return ''
end
 
local function formatAwardsRibbons(raw, rowRaw)
-- Prefer explicit Wikipedia row layout when present
local rows = splitAwardRows(rowRaw or '')
if #rows == 0 then
raw = trim(raw)
if raw == '' then
return ''
end
local files = {}
for part in mw.text.gsplit(raw, ';', true) do
part = trim(part)
part = mw.ustring.gsub(part, '^[Ff]ile:', '')
if part ~= '' then
table.insert(files, part)
end
end
if #files == 0 then
return ''
end
-- Fallback: pack ~4 across
local perRow = 4
rows = {}
local cur = {}
for _, file in ipairs(files) do
table.insert(cur, file)
if #cur == perRow then
table.insert(rows, cur)
cur = {}
end
end
if #cur > 0 then
table.insert(rows, cur)
end
end
end
-- Wikipedia-style ribbon rack: centered table, ~4 across, full article width
local perRow = 4
local out = {}
local out = {}
table.insert(out, '{| class="wikitable soldier-ribbon-rack"')
table.insert(out, '{| class="soldier-ribbon-rack"')
for i, file in ipairs(files) do
for _, cells in ipairs(rows) do
if ((i - 1) % perRow) == 0 then
table.insert(out, '|-')
table.insert(out, '|-')
for _, file in ipairs(cells) do
file = mw.ustring.gsub(file, '^[Ff]ile:', '')
table.insert(out, '| [[File:' .. file .. '|106px|link=]]')
end
end
table.insert(out, '| [[File:' .. file .. '|106px|link=]]')
end
end
-- Pad last row so cells align
table.insert(out, '|}')
local rem = #files % perRow
return table.concat(out, '\n')
if rem > 0 then
end
for _ = rem + 1, perRow do
 
table.insert(out, '|')
local function formatAwardsGrid(raw)
local rows = splitAwardRows(raw)
if #rows == 0 then
return ''
end
local out = {}
table.insert(out, '{| class="wikitable soldier-awards-grid"')
for _, cells in ipairs(rows) do
table.insert(out, '|-')
for _, cell in ipairs(cells) do
table.insert(out, '| ' .. cell)
end
end
end
end
Line 1,595: Line 1,646:


function p.awardsSection(frame)
function p.awardsSection(frame)
local ribbons = formatAwardsRibbons(parentArg(frame, 'awards_ribbons'))
local ribbons = formatAwardsRibbons(
local awardsText = formatAwardsLegend(parentArg(frame, 'awards'))
parentArg(frame, 'awards_ribbons'),
if ribbons == '' and awardsText == '' then
parentArg(frame, 'awards_ribbon_rows')
)
local grid = formatAwardsGrid(parentArg(frame, 'awards_grid'))
local extras = formatAwardsLegend(parentArg(frame, 'awards_extra'))
-- Fallback: flat awards list when no grid was extracted
if grid == '' and extras == '' then
extras = formatAwardsLegend(parentArg(frame, 'awards'))
end
if ribbons == '' and grid == '' and extras == '' then
return ''
return ''
end
end
Line 1,609: Line 1,668:
table.insert(parts, ribbons)
table.insert(parts, ribbons)
end
end
if awardsText ~= '' then
if grid ~= '' then
table.insert(parts, grid)
end
if extras ~= '' then
table.insert(parts, '<div class="soldier-awards-list">')
table.insert(parts, '<div class="soldier-awards-list">')
table.insert(parts, awardsText)
table.insert(parts, extras)
table.insert(parts, '</div>')
table.insert(parts, '</div>')
end
end