Module:OOOInfoBox: Difference between revisions
No edit summary |
No edit summary |
||
| Line 57: | Line 57: | ||
local has = false | local has = false | ||
for _, r in ipairs(rows) do | for _, r in ipairs(rows) do | ||
local v = r[2] | if r then | ||
local v = r[2] | |||
if v ~= nil and tostring(v) ~= '' then | |||
has = true | |||
break | |||
end | |||
end | |||
end | end | ||
if not has then return end | if not has then return end | ||
add_group_header(tbl, header) | add_group_header(tbl, header) | ||
for _, r in ipairs(rows) do | for _, r in ipairs(rows) do | ||
local label, value, tip = r[1], r[2], r[3] | if r then | ||
local label, value, tip = r[1], r[2], r[3] | |||
if value ~= nil and tostring(value) ~= '' then | |||
add_row(tbl, label, value, tip) | |||
end | |||
end | end | ||
end | end | ||
end | |||
-- Compact "W × L × H" builder (returns nil when nothing to show) | |||
local function join_dims(a, b, c, unit) | |||
local parts = {} | |||
if a then parts[#parts+1] = tostring(a) end | |||
if b then parts[#parts+1] = tostring(b) end | |||
if c then parts[#parts+1] = tostring(c) end | |||
if #parts == 0 then return nil end | |||
return table.concat(parts, ' × ') .. (unit or '') | |||
end | end | ||
| Line 152: | Line 169: | ||
}) | }) | ||
-- Dimensions: supports size={x,y,z} | -- Dimensions: supports size={x,y,z} OR flat keys; always compact | ||
local sx, sy, sz | local sx, sy, sz | ||
if data.size and type(data.size) == 'table' then | if data.size and type(data.size) == 'table' then | ||
| Line 162: | Line 179: | ||
local size_note = pick(args, data, 'size_note') | local size_note = pick(args, data, 'size_note') | ||
add_group(box, 'Dimensions', { | |||
{'Overall', join_dims(size_w, size_l, size_h, U.m), 'Width × Length × Height'}, | |||
{'Note', size_note}, | |||
}) | |||
out:node(box) | out:node(box) | ||