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

From Team Fortress Wiki
Jump to: navigation, search
Line 5: Line 5:
 
end
 
end
  
function p.classes(frame)
+
function get_args(frame)
    local first = nil
+
     local args = {}
    local count = -1
+
     for _, arg in ipairs(frame.args) do
     local args = frame.args
+
         args.insert(arg)
     for _, arg in ipairs(args) do
 
         first = first or arg
 
        count = count + 1
 
 
     end
 
     end
     if first == nil then
+
     if #args > 0 then return args end
        args = frame:getParent().args
+
 
        for _, arg in ipairs(args) do
+
    for _, arg in ipairs(frame:getParent().args) do
            first = first or arg
+
        args.insert(arg)
            count = count + 1
 
        end
 
 
     end
 
     end
 
+
 
 +
    return args
 +
end
 +
 
 +
function p.classes(frame)
 +
    local args = p.get_args(frame)
 +
 
 +
    local first = args.remove(1)
 
     if first == '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 first == 'all-except' then
         return common_string{'infobox-used-by-all-except-' .. count, unpack(args)}
+
         return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)}
 
     else
 
     else
         return common_string{'infobox-used-by-' .. count, unpack(args)}
+
         return common_string{'infobox-used-by-' .. #args, unpack(args)}
 
     end
 
     end
 
end
 
end
  
 
return p
 
return p

Revision as of 06:29, 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
        args.insert(arg)
    end
    if #args > 0 then return args end

    for _, arg in ipairs(frame:getParent().args) do
        args.insert(arg)
    end

    return args
end

function p.classes(frame)
    local args = p.get_args(frame)

    local first = args.remove(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