Module:OOOInfoBox: Difference between revisions
No edit summary |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| 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 98: | Line 115: | ||
local box = mw.html.create('table'):addClass('ooo-infobox') | local box = mw.html.create('table'):addClass('ooo-infobox') | ||
-- optional width (keeps CSS default if omitted) | |||
local w = tonumber((frame:getParent() or frame).args.width) | |||
if w and w >= 240 and w <= 600 then | |||
box:css('width', w .. 'px') | |||
end | |||
-- default is right via CSS; only add class when overriding | |||
local align = trim(args.align) | |||
if align == 'left' then | |||
box:addClass('ooo-infobox--left') | |||
elseif align == 'none' then | |||
box:addClass('ooo-infobox--none') | |||
elseif align == 'center' then | |||
box:addClass('ooo-infobox--center') | |||
end | |||
-- keep optional extra classes | |||
local extra_class = trim(args.class) | |||
if extra_class and extra_class ~= '' then | |||
for c in mw.text.gsplit(extra_class, '%s+') do box:addClass(c) end | |||
end | |||
-- Title | -- Title | ||
| Line 125: | Line 164: | ||
-- Basics | -- Basics | ||
add_group(box, 'General', { | add_group(box, 'General', { | ||
{'Art Number', art}, | |||
{'Category', pick(args, data, 'category')}, | {'Category', pick(args, data, 'category')}, | ||
{'Subcategory',pick(args, data, 'subcategory')}, | {'Subcategory',pick(args, data, 'subcategory')}, | ||
{'Price', pick(args, data, 'price')}, | {'Price', pick(args, data, 'price')}, | ||
{'Domain', domain}, | {'Domain', domain}, | ||
}) | }) | ||
| Line 152: | Line 191: | ||
}) | }) | ||
-- 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 201: | ||
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) | ||