Module:ModuleShowVariantsOrSingle: Difference between revisions

From The First Descendant Wiki
No edit summary
No edit summary
Tag: Reverted
Line 15: Line 15:


function p.processData(frame)
function p.processData(frame)
     if frame.args.count == nil then
     if frame:getParent().args.count == nil then
         return "ERROR: Module:ModuleShowVariantsOrSingle not passed a count. Please tell us on Discord!"
         return "ERROR: Module:ModuleShowVariantsOrSingle not passed a count. Please tell us on Discord!"
     end
     end
   
 
     local result = ""
     local result = ""
     if tonumber(frame.args.count) > 1 then
     if tonumber(frame:getParent().args.count) > 1 then
         result = moreThanOne(frame.args.module_name)
         result = moreThanOne(frame.args.module_name)
     end
     end
Line 26: Line 26:
     local count = 0
     local count = 0


     for k, v in pairs(frame.args) do
     for k, v in pairs(frame:getParent().args) do
         if v ~= '' then
         if v ~= '' then
             count = count + 1
             count = count + 1

Revision as of 22:22, 5 June 2024

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

------------------------------------
-- Modules can have variants, or they can be one of a kind.
-- It doesn't make sense to show all the variant fluff if a module is one of a kind.

local p = {}


local function moreThanOne(module_name)
    local variants_chapter = "== Variants ==\n{{Template:ModuleTableCompareLevels|module_name=" .. module_name .. "}}\n\n"
    local variant_details_chapter = "== Variant Details ==\n"
    return variants_chapter .. variant_details_chapter
end



function p.processData(frame)
    if frame:getParent().args.count == nil then
        return "ERROR: Module:ModuleShowVariantsOrSingle not passed a count. Please tell us on Discord!"
    end

    local result = ""
    if tonumber(frame:getParent().args.count) > 1 then
        result = moreThanOne(frame.args.module_name)
    end

    local count = 0

    for k, v in pairs(frame:getParent().args) do
        if v ~= '' then
            count = count + 1
        end
    end

    return frame:preprocess(count)
end

return p