Module:Tabber

From RuneRealm Wiki
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Tabber/doc. [edit] [history] [purge]
Module:Tabber's function main is invoked by Template:Tabber.

This module is a helper module to be used by other modules; it may not designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here

FunctionTypeUse
tabber({
{"tab 1 label", "tab 1 content"},
{"tab 2 label", "tab 2 content"},
{"etc", "..."},
})
Table, BooleanReturns a preprocessed string of a <tabber> containing each of the specified tabs.
If preprocess is explicitly set to false the tabber will not be processed and instead return a mw.html object. If it is not specified or set to true the tabber will be preprocessed.

local p = {}

-- Access point for other modules
-- argument format: {{"tab 1 label", "tab 1 content"}, {"tab 2 label", "tab 2 content"}, {"etc", "..."}}
function p.tabber(tabs)
	preprocess = preprocess == nil and true or preprocess -- if no preprocess defined, set to true
	local tabber = ""
	for i, tab in ipairs(tabs) do
		if i > 1 then
			tabber = tabber .. "|-|"
		end
		tabber = tabber .. mw.text.trim(tab[1]) .. '=' .. tab[2]
	end
	return mw.getCurrentFrame():callParserFunction( '#tag', { 'tabber', tabber } )
end

-- [[Template:Tabber]]
function p.main(frame)
	local args = frame:getParent().args
	local i = 1
	local tabs = {}
	while args['tab'..tostring(i)] do
		local tab = 'tab'..tostring(i)
		table.insert(tabs, { args[tab], args[tab..'content'] or ''})
		i = i+1
	end
	return p.tabber(tabs)
end

return p