Jump to content

Module:OOO/Variants: Difference between revisions

From Out of Ore Wiki
Created page with "local DATA = require('Module:OOO/Data') local p = {} local function esc(s) return mw.text.nowiki(tostring(s or '')) end 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 -- Forward a small set of per-tab overrides if present, like image3=..., description2=... local passthrough_keys = { 'image', 'description', 'dimensions', 'class' } func..."
(No difference)

Revision as of 19:40, 12 October 2025

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

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

local function esc(s) return mw.text.nowiki(tostring(s or '')) end

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

-- Forward a small set of per-tab overrides if present, like image3=..., description2=...
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 the 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 }
    entries[#entries+1] = esc(label) .. '=\n' .. content .. '\n'
    i = i + 1
  end

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

  local html = '<div class="ooo-infobox-tabwrap"><tabber>\n'
             .. table.concat(entries, '|-|\n')
             .. '</tabber></div>'

  -- Attach styles
  html = html .. frame:extensionTag('templatestyles', '', { src = 'Template:OOOInfoBoxTabber/styles.css' })
  return html
end

return p