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

From Team Fortress Wiki
Jump to: navigation, search
Line 26: Line 26:
  
 
function p.all_except(frame)
 
function p.all_except(frame)
     local args, count = get_args_and_count(frame)
+
     args, count = get_args_and_count(frame)
 
     assert(count >= 1) -- Must provide at least one "except" class
 
     assert(count >= 1) -- Must provide at least one "except" class
 
     assert(count <= 2) -- Dictionary strings only support up to two exceptions
 
     assert(count <= 2) -- Dictionary strings only support up to two exceptions
Line 33: Line 33:
  
 
function p.classes(frame)
 
function p.classes(frame)
     local args, count = get_args_and_count(frame)
+
     args, count = get_args_and_count(frame)
 
     assert(count >= 1) -- Must provide at least one class
 
     assert(count >= 1) -- Must provide at least one class
 
     assert(count <= 5) -- Dictionary strings only support up to five classes
 
     assert(count <= 5) -- Dictionary strings only support up to five classes

Revision as of 06:16, 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_and_count(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

    return args, count
end

function p.all(frame)
    return common_string{'infobox-used-by-all'}
end

function p.all_except(frame)
    args, count = get_args_and_count(frame)
    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

return p