NeuroWiki hereby wishes Evil Neuro happy 2nd birthday on March 25, 2025!

Module:Tabs

From NeuroWiki
Revision as of 21:24, 14 April 2025 by Selfice (talk | contribs) (Created page with "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 posit...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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