Difference between revisions of "Module:Used by"
(Created page with "local p = {} function common_string(args) return mw.getCurrentFrame():expandTemplate{title='Common string', args=args} end function p.classes(frame) local args = frame...") |
(Various improvements/simplifications) |
||
Line 5: | Line 5: | ||
end | end | ||
− | function | + | function get_args(frame) |
− | local args = | + | local args = {} |
− | + | for _, arg in ipairs(frame.args) do | |
− | for _ in | + | table.insert(args, arg) |
− | |||
end | end | ||
− | if | + | if #args > 0 then return args end |
− | + | ||
− | + | for _, arg in ipairs(frame:getParent().args) do | |
− | + | table.insert(args, arg) | |
− | |||
end | end | ||
− | + | ||
− | local | + | return args |
− | + | end | |
+ | |||
+ | function p.classes(frame) | ||
+ | local args = get_args(frame) | ||
+ | |||
+ | if args[1] == 'all' then | ||
return common_string{'infobox-used-by-all'} | return common_string{'infobox-used-by-all'} | ||
− | elseif | + | 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 <= 2, "You must provide at most 2 classes when using 'all-except'.") | |
− | + | return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)} | |
− | |||
− | |||
− | |||
else | 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 | ||
end | end | ||
return p | return p |
Latest revision as of 22:18, 18 March 2023
Parameter | Output |
---|---|
all {{Used by|all}} |
All classes |
all-except (max: 2){{Used by|all-except|Soldier|etc.}} |
All classes (except Soldier) All classes (except Soldier and Pyro) |
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 <= 2, "You must provide at most 2 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