Difference between revisions of "Module:Used by"
(Various improvements/simplifications) |
m |
||
Line 27: | Line 27: | ||
table.remove(args, 1) -- Remove the 'all-except' argument | table.remove(args, 1) -- Remove the 'all-except' argument | ||
assert(#args >= 1, "You must provide at least 1 class when using 'all-except'.") | assert(#args >= 1, "You must provide at least 1 class when using 'all-except'.") | ||
− | assert(#args <= | + | assert(#args <= 3, "You must provide at most 3 classes when using 'all-except'.") |
return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)} | return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)} | ||
else | else |
Latest revision as of 19:43, 30 April 2024
Parameter | Output |
---|---|
all {{Used by|all}} |
All classes |
all-except (max: 3){{Used by|all-except|Soldier|etc.}} |
All classes (except Soldier) All classes (except Soldier and Pyro) All classes (except Soldier, Pyro, and Engineer) |
classname (max: 5){{Used by|Soldier|etc.}} |
Soldier Soldier, Pyro Soldier, Pyro, Engineer Soldier, Pyro, Engineer, Demoman Soldier, Pyro, Engineer, Demoman, Heavy |
local p = {} function common_string(args) return mw.getCurrentFrame():expandTemplate{title='Common string', args=args} end function get_args(frame) local args = {} for _, arg in ipairs(frame.args) do table.insert(args, arg) end if #args > 0 then return args end for _, arg in ipairs(frame:getParent().args) do table.insert(args, arg) end return args end function p.classes(frame) local args = get_args(frame) if args[1] == 'all' then return common_string{'infobox-used-by-all'} elseif args[1] == 'all-except' then table.remove(args, 1) -- Remove the 'all-except' argument assert(#args >= 1, "You must provide at least 1 class when using 'all-except'.") assert(#args <= 3, "You must provide at most 3 classes when using 'all-except'.") return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)} else assert(#args >= 1, "You must provide at least 1 class when using this function.") assert(#args <= 5, "You must provide at most 5 classes when using this function.") return common_string{'infobox-used-by-' .. #args, unpack(args)} end end return p