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
    if v ~= nil and tostring(v) ~= '' then has = true break end
      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
    if value ~= nil and tostring(value) ~= '' then
      local label, value, tip = r[1], r[2], r[3]
      add_row(tbl, label, value, tip)
      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} and compact/expanded modes
-- 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')


local dims_mode = (args.dimensions or ''):lower() -- "compact" or "expanded"
add_group(box, 'Dimensions', {
if dims_mode == '' then dims_mode = 'compact' end  -- default: compact line
  {'Overall', join_dims(size_w, size_l, size_h, U.m), 'Width × Length × Height'},
  {'Note',    size_note},
})


if dims_mode == 'compact' then
  local function fmt(x) return x and tostring(x) or '' end
  local compact = nil
  if size_w or size_l or size_h then
    compact = table.concat({fmt(size_w), '×', fmt(size_l), (size_h and '×' or ''), fmt(size_h)}, '')
    compact = mw.text.trim(compact)
    if compact ~= '' then compact = compact .. U.m end
  end
  add_group(box, 'Dimensions', {
    {'Overall', compact, 'Width × Length × Height'},
    {'Note',    size_note},
  })
else
  add_group(box, 'Dimensions', {
    {'Width',  with_unit(size_w, U.m), 'Measured outer width'},
    {'Length', with_unit(size_l, U.m), 'Measured outer length'},
    {'Height', with_unit(size_h, U.m), 'Measured to highest point'},
    (tonumber(size_w) and tonumber(size_l))
      and {'Area', with_unit(tonumber(size_w)*tonumber(size_l), U.m2)}
      or nil,
    {'Note', size_note},
  })
end


   out:node(box)
   out:node(box)