Difference between revisions of "Module:Used by/Sandbox"

From Team Fortress Wiki
Jump to: navigation, search
Line 22: Line 22:
 
     local args = get_args(frame)
 
     local args = get_args(frame)
  
     local first = args.remove(1)
+
     local first = table.remove(args, 1)
 
     if first == 'all' then
 
     if first == 'all' then
 
         return common_string{'infobox-used-by-all'}
 
         return common_string{'infobox-used-by-all'}

Revision as of 06:30, 18 March 2023

Documentation for this module may be created at Module:Used by/Sandbox/doc

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)

    local first = table.remove(args, 1)
    if first == 'all' then
        return common_string{'infobox-used-by-all'}
    elseif first == 'all-except' then
        return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)}
    else
        return common_string{'infobox-used-by-' .. #args, unpack(args)}
    end
end

return p