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

From Team Fortress Wiki
Jump to: navigation, search
Line 5: Line 5:
 
end
 
end
  
function get_args_and_count(frame)
+
function p.classes(frame)
 
     local args = frame.args
 
     local args = frame.args
 
     local count = 0
 
     local count = 0
Line 17: Line 17:
 
         end
 
         end
 
     end
 
     end
 
+
 
     return args, count
+
     local first = args.remove(0)
end
+
     count = #args
 
+
    if first == 'all' then
function p.all(frame)
+
        return common_string{'infobox-used-by-all'}
     return common_string{'infobox-used-by-all'}
+
     elseif first == 'all-except' then
end
+
        return common_string{'infobox-used-by-all-except-' .. count, unpack(args)}
 
+
     else
function p.all_except(frame)
+
        return common_string{'infobox-used-by-' .. count, unpack(args)}
     args, count = get_args_and_count(frame)
+
    end
    assert(count >= 1) -- Must provide at least one "except" class
 
    assert(count <= 2) -- Dictionary strings only support up to two exceptions
 
    return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)}
 
end
 
 
 
function p.classes(frame)
 
     args, count = get_args_and_count(frame)
 
    assert(count >= 1) -- Must provide at least one class
 
    assert(count <= 5) -- Dictionary strings only support up to five classes
 
    return common_string{'infobox-used-by-' .. #args, unpack(args)}
 
 
end
 
end
  
 
return p
 
return p

Revision as of 06:18, 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 p.classes(frame)
    local args = frame.args
    local count = 0
    for _ in pairs(args) do 
        count = count + 1 
    end
    if count == 0 then
        args = frame:getParent().args
        for _ in pairs(args) do 
            count = count + 1 
        end
    end
  
    local first = args.remove(0)
    count = #args
    if first == 'all' then
        return common_string{'infobox-used-by-all'}
    elseif first == 'all-except' then
        return common_string{'infobox-used-by-all-except-' .. count, unpack(args)}
    else
        return common_string{'infobox-used-by-' .. count, unpack(args)}
    end
end

return p