Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:CatType

From Teriock
Revision as of 13:16, 12 January 2025 by Gpe (talk | contribs)

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

local p = {}

function p.generateCategories(frame)
    local baseCategory = frame.args[1] or ""

    if baseCategory == "" then
        return "Error: No base category provided."
    end

    -- Determine type (either "spells" or "skills")
    local type = baseCategory:match("spells") or baseCategory:match("skills")
    if not type then
        return "Error: Unable to determine type ('spells' or 'skills') from category name."
    end

    -- Replace "spells" or "skills" with "abilities" to determine the immediate parent category
    local abilitiesCategory = baseCategory:gsub(type, "abilities")

    -- Define the parent categories manually or infer based on naming patterns
    local parentCategories = {
        "Parent abilities",
        "Grandparent abilities"
    }

    -- Generate the category tree, replacing "abilities" with the detected type
    local result = {}
    table.insert(result, "[[Category:" .. abilitiesCategory .. "]]")
    for _, parent in ipairs(parentCategories) do
        local categoryWithReplacement = parent:gsub("abilities", type)
        table.insert(result, "[[Category:" .. categoryWithReplacement .. "]]")
    end

    return table.concat(result, "\n")
end

return p