Module:Tabber

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 08:32, 26 February 2024 by KojoB (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Tabber/doc

local p = {}

function getArgCount(args)
	i = 0 
	for inc, val in ipairs(args) do 
		i = i + 1
	end
	return i
end

function p.main(frame)
	local parentArgs = frame:getParent().args
	local content = ""
	local namedParameters = false
	
	--Check if the named parameter format is used
	if parentArgs["title1"] and parentArgs["content1"] then
        namedParameters = true
    end
	
    if namedParameters then
        -- Handle named arguments
        local i = 1
        while parentArgs["title" .. i] and parentArgs["content" .. i] do
            if i ~= 1 then
                content = content .. "|-|"
            end
            content = content .. parentArgs["title" .. i] .. "=" .. parentArgs["content" .. i]
            i = i + 1
        end
    else
        -- Handle positional arguments
        for i = 1, getArgCount(parentArgs), 2 do
            if i ~= 1 then
                content = content .. "|-|"
            end
            content = content .. parentArgs[i] .. "=" .. parentArgs[i+1]
        end
    end

	return frame:extensionTag('tabber', content)
end

return p