No edit summary |
No edit summary |
||
| Line 25: | Line 25: | ||
local smw_count = tonumber(frame.args.count) | local smw_count = tonumber(frame.args.count) | ||
local result = "" | local result = "" | ||
if | if smw_count > 3 then | ||
result = moreThanOne(frame.args.module_name) | result = moreThanOne(frame.args.module_name) | ||
-- In MediaWiki, args are a table. Named args get a string key, unnamed args get a sequential number key. | -- In MediaWiki, args are a table. Named args get a string key, unnamed args get a sequential number key. | ||
-- Thus, the first unnamed arg will be 1, and we can loop through them all by subtracting the number of named args. | -- Thus, the first unnamed arg will be 1, and we can loop through them all by subtracting the number of named args. | ||
for i=1, | for i=1, smw_count do | ||
result = result .. addChapter(i, frame.args[i]) | result = result .. addChapter(i, frame.args[i]) | ||
end | end | ||
| Line 57: | Line 37: | ||
result = result .. "\n<headertabs />" | result = result .. "\n<headertabs />" | ||
else | else | ||
result = frame.args[1] | result = frame.args[1] | ||
end | end | ||
Revision as of 00:26, 6 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.
-- This script shows or hides all that variant info based on how many unique modules are defined,
-- no having to manually pick a template yourself!
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
local function addChapter(variantID, moduleText)
return "\n= " .. tostring(variantID) .. " =\n" ..moduleText
end
function p.processData(frame)
if frame.args.count == nil then
return "ERROR: Module:ModuleShowVariantsOrSingle not passed a count. Please tell us on Discord!"
end
local smw_count = tonumber(frame.args.count)
local result = ""
if smw_count > 3 then
result = moreThanOne(frame.args.module_name)
-- In MediaWiki, args are a table. Named args get a string key, unnamed args get a sequential number key.
-- Thus, the first unnamed arg will be 1, and we can loop through them all by subtracting the number of named args.
for i=1, smw_count do
result = result .. addChapter(i, frame.args[i])
end
result = result .. "\n<headertabs />"
else
result = frame.args[1]
end
return frame:preprocess(result)
end
return p