Module:Tabs
Documentation for this module may be created at Module:Tabs/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local indices = {}
-- Collect valid tab indices
for k, _ in pairs(args) do
local num = k:match('^bt(%d+)$') or k:match('^tab(%d+)$')
if num then indices[tonumber(num)] = true end
end
-- Handle tab sorting
local sorted = {}
for k in pairs(indices) do table.insert(sorted, k) end
table.sort(sorted)
-- Determine the default tab position (based on parameter order)
local default_pos = math.min(tonumber(args.DefaultTab) or 1, #sorted)
-- Build tabber content
local tabberContent = {}
for pos, idx in ipairs(sorted) do
local title = args['bt'..idx] or ''
local content = args['tab'..idx] or ''
table.insert(tabberContent, string.format('|-| %s=%s', title, content))
end
return mw.getCurrentFrame():preprocess(
'<tabber>\n'..table.concat(tabberContent, '\n')..'\n</tabber>'
)
end
-- Add math function compatibility
math.min = math.min or function(a, b) return a < b and a or b end
return p