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 = table.remove(args, 1)
+
     if table[0] == 'all' then
    if first == 'all' then
 
 
         return common_string{'infobox-used-by-all'}
 
         return common_string{'infobox-used-by-all'}
     elseif first == 'all-except' then
+
     elseif table[0] == 'all-except' then
 +
        table.remove(args, 1) -- Remove the 'all-except' argument
 
         return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)}
 
         return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)}
 
     else
 
     else

Revision as of 06:31, 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)

    if table[0] == 'all' then
        return common_string{'infobox-used-by-all'}
    elseif table[0] == 'all-except' then
        table.remove(args, 1) -- Remove the 'all-except' argument
        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