Module:OOO/Variants: Difference between revisions
Appearance
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 edit summary |
||
Line 1: | Line 1: | ||
local DATA = require('Module:OOO/Data') | local DATA = require('Module:OOO/Data') | ||
local p = {} | local p = {} | ||
local function label_for(domain, art, given) | local function label_for(domain, art, given) | ||
Line 10: | Line 8: | ||
end | end | ||
-- | -- allow per-tab overrides like image3=..., description2=..., dimensions4=... | ||
local passthrough_keys = { 'image', 'description', 'dimensions', 'class' } | local passthrough_keys = { 'image', 'description', 'dimensions', 'class' } | ||
function p.tabs(frame) | function p.tabs(frame) | ||
local args = (frame:getParent() or frame).args or {} | local args = (frame:getParent() or frame).args or {} | ||
local domain = args.domain or args.type or 'Buildings' | local domain = args.domain or args.type or 'Buildings' | ||
local align | local align = args.align or 'right' | ||
local entries, i = {}, 1 | local entries, i = {}, 1 | ||
Line 25: | Line 23: | ||
local label = label_for(domain, art, args['label'..i] or args['name'..i]) | local label = label_for(domain, art, args['label'..i] or args['name'..i]) | ||
-- Build args for | -- Build args for OOOInfoBox | ||
local ibx = { art = art, align = align, type = domain } | local ibx = { art = art, align = align, type = domain } | ||
for _, key in ipairs(passthrough_keys) do | for _, key in ipairs(passthrough_keys) do | ||
Line 33: | Line 31: | ||
local content = frame:expandTemplate{ title = 'OOOInfoBox', args = ibx } | local content = frame:expandTemplate{ title = 'OOOInfoBox', args = ibx } | ||
entries[#entries+1] = | |||
-- Collect TabberNeue wikitext part: <label>=<content> | |||
entries[#entries+1] = string.format('%s=\n%s\n', label, content) | |||
i = i + 1 | i = i + 1 | ||
end | end | ||
Line 41: | Line 41: | ||
end | 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' }) | html = html .. frame:extensionTag('templatestyles', '', { src = 'Template:OOOInfoBoxTabber/styles.css' }) | ||
return html | return html |
Revision as of 19:44, 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 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