Module:OOO/Variants: Difference between revisions

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 esc(s) return mw.text.nowiki(tostring(s or '')) end


local function label_for(domain, art, given)
local function label_for(domain, art, given)
Line 10: Line 8:
end
end


-- Forward a small set of per-tab overrides if present, like image3=..., description2=...
-- 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 = args.align  or 'right'
   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 the OOOInfoBox
     -- 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] = esc(label) .. '=\n' .. content .. '\n'
 
    -- 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


   local html = '<div class="ooo-infobox-tabwrap"><tabber>\n'
   -- Force the tabber tag to be parsed by MediaWiki
            .. table.concat(entries, '|-|\n')
  local inner  = table.concat(entries, '|-|\n')
            .. '</tabber></div>'
  local tabber = frame:extensionTag('tabber', inner)


   -- Attach styles
   -- 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