Jump to content

Module:OOO/Variants

From Out of Ore Wiki
Revision as of 19:44, 12 October 2025 by T-Bone (talk | contribs)

Documentation for this module may be created at Module:OOO/Variants/doc

local DATA = require('Module:OOO/Data')
local p = {}

local function label_for(domain, art, given)
  if given and given ~= '' then return given end
  local rec = DATA.get(domain, art) or {}
  return rec.displayName or tostring(art)
end

-- allow per-tab overrides like image3=..., description2=..., dimensions4=...
local passthrough_keys = { 'image', 'description', 'dimensions', 'class' }

function p.tabs(frame)
  local args    = (frame:getParent() or frame).args or {}
  local domain  = args.domain or args.type or 'Buildings'
  local align   = args.align  or 'right'

  local entries, i = {}, 1
  while true do
    local art = args['art'..i] or args[i]
    if not art then break end

    local label = label_for(domain, art, args['label'..i] or args['name'..i])

    -- Build args for OOOInfoBox
    local ibx = { art = art, align = align, type = domain }
    for _, key in ipairs(passthrough_keys) do
      local v = args[key..i]
      if v and v ~= '' then ibx[key] = v end
    end

    local content = frame:expandTemplate{ title = 'OOOInfoBox', args = ibx }

    -- Collect TabberNeue wikitext part: <label>=<content>
    entries[#entries+1] = string.format('%s=\n%s\n', label, content)
    i = i + 1
  end

  if #entries == 0 then
    return '<strong class="error">OOOVariants: no variants provided</strong>'
  end

  -- Force the tabber tag to be parsed by MediaWiki
  local inner  = table.concat(entries, '|-|\n')
  local tabber = frame:extensionTag('tabber', inner)

  -- Wrap & attach styles
  local html = '<div class="ooo-infobox-tabwrap">' .. tabber .. '</div>'
  html = html .. frame:extensionTag('templatestyles', '', { src = 'Template:OOOInfoBoxTabber/styles.css' })
  return html
end

return p