Module:Etraud/Sandbox1: Difference between revisions

From Pixlies
Content added Content deleted
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}

local function addCategory(frame, pronoun)
local category = "Players who use " .. pronoun .. ""
return "[[Category:" .. category .. "]]"
end


function p.pronoun(frame, ...)
function p.pronoun(frame, ...)
Line 16: Line 11:


local selectedPronouns = {}
local selectedPronouns = {}
local categories = {}


for i, arg in ipairs(args) do
for i, arg in ipairs(args) do
if pronouns[arg] then
if pronouns[arg] then
table.insert(selectedPronouns, pronouns[arg])
table.insert(selectedPronouns, pronouns[arg])
frame:preprocess(addCategory(frame, pronouns[arg]))
table.insert(categories, "[[Category:Players who use " .. pronouns[arg] .. "]]")
end
end
end
end
Line 27: Line 23:
return "No valid pronouns specified."
return "No valid pronouns specified."
else
else
return table.concat(selectedPronouns, "/")
return table.concat(selectedPronouns, "/") .. table.concat(categories)
end
end
end
end

Revision as of 06:37, 26 July 2023

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

local p = {}

function p.pronoun(frame, ...)
    local args = {...}

    local pronouns = {
        he = "he",
        she = "she",
        they = "they"
    }

    local selectedPronouns = {}
    local categories = {}

    for i, arg in ipairs(args) do
        if pronouns[arg] then
            table.insert(selectedPronouns, pronouns[arg])
            table.insert(categories, "[[Category:Players who use " .. pronouns[arg] .. "]]")
        end
    end

    if #selectedPronouns == 0 then
        return "No valid pronouns specified."
    else
        return table.concat(selectedPronouns, "/") .. table.concat(categories)
    end
end

return p