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

Module:Gnoblin: Difference between revisions

From Deepest Lore
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 39: Line 39:
end
end


function p.smartCategory(frame)
local p = {}
    local cat = frame.args[1]
    if not cat or cat == "" then
        return ""
    end


    -- Build category title
--[[
     local title = mw.title.new("Category:" .. cat)
    addParentCategory(subcategory)
    Usage: {{#invoke:YourModuleName|addParentCategory|Woodland Elf}}
    Automatically adds the page to both the subcategory and its parent category 'Elf'
]]
function p.addParentCategory(frame)
     local subcat = frame.args[1] or ""
    subcat = mw.text.trim(subcat)
    if subcat == "" then return "" end


     -- If category exists, use it
     -- Always include the specific subcategory
     if title and title.exists then
     local result = "[[Category:" .. subcat .. "]]"
        return "[[Category:" .. cat .. "]]"
    end


     -- Fallback logic for elf subtypes
     -- Determine parent category
     if mw.ustring.match(cat:lower(), "elf") then
    -- In this example, any subcategory containing "elf" gets parent "Elf"
         return "[[Category:Elf]]"
     if mw.ustring.match(mw.ustring.lower(subcat), "elf") then
         result = result .. "\n[[Category:Elf]]"
     end
     end


    -- Otherwise, no category
     return result
     return ""
end
end


return p
return p

Revision as of 21:40, 30 March 2026

Titles

! colspan="2" class="infobox-subheader" | Not on a character |-



! colspan="2" class="infobox-subheader" | |-

Script error: The function "processTitle" does not exist.
Gnoblin
Script error: The function "processTitle" does not exist.
Gnoblin

local p = {}

function p.processTitle(frame)
    local input = frame.args[1] or ""

    -- Check if input already looks like a {{Title}} template
    if mw.ustring.match(input, "^%s*%{%{%s*[Tt]itle%s*[|}]") then
        return input
    end

   -- Otherwise, expand the template properly
    return frame:expandTemplate{
        title = "Title",
        args = { name = input }
    }
end

function p.stripHouse(frame)
    local name = frame.args[1]
    if not name or name == "" then
        name = mw.title.getCurrentTitle().text
    end

    local prefixes = { "House", "Clan", "Family", "Dynasty" }

    for _, prefix in ipairs(prefixes) do
        local pattern = "^[" .. mw.ustring.sub(prefix,1,1):lower() .. mw.ustring.sub(prefix,1,1):upper() .. "]" ..
                        mw.ustring.sub(prefix,2):lower() .. "%s+"
        name = mw.ustring.gsub(name, pattern, "")
    end

    return name
end

function p.unlink(frame)
    local text = frame.args[1] or ""
    text = mw.ustring.gsub(text, "[%[%]]", "")
    return text
end

local p = {}

--[[ 
    addParentCategory(subcategory)
    Usage: {{#invoke:YourModuleName|addParentCategory|Woodland Elf}}
    Automatically adds the page to both the subcategory and its parent category 'Elf'
]]
function p.addParentCategory(frame)
    local subcat = frame.args[1] or ""
    subcat = mw.text.trim(subcat)
    if subcat == "" then return "" end

    -- Always include the specific subcategory
    local result = "[[Category:" .. subcat .. "]]"

    -- Determine parent category
    -- In this example, any subcategory containing "elf" gets parent "Elf"
    if mw.ustring.match(mw.ustring.lower(subcat), "elf") then
        result = result .. "\n[[Category:Elf]]"
    end

    return result
end

return p
Contents