Module:Tabs

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

local p = {}

-- =p.main({args={link1='foo', link2='bar'}})
p.main = function ( frame )
	-- Either use the args given (for testing), or those of the parent.
	local args = frame.args
	if #args == 0 and mw.getCurrentFrame():getParent() then
		args = mw.getCurrentFrame():getParent().args
	end
	-- Loop through all numbered links given.
	local tabNum = 1
	local finished = false
	local out = ''
	while not finished do
		-- See if the next numbered link is there.
		if args[ 'link' .. tabNum ] ~= nil and args[ 'link' .. tabNum ] ~= '' then
			local link = args[ 'link' .. tabNum ]
			local label = link
			if args[ 'label' .. tabNum ] ~= nil and args[ 'label' .. tabNum ] ~= '' then
				label = args[ 'label' .. tabNum ]
			end
			out = out .. ' <span class="mdl-tabs-tab">[[' .. link .. '|' .. label .. ']]</span>'
			tabNum = tabNum + 1
		else
			finished = true
		end
	end
	local styles = mw.getCurrentFrame():extensionTag( 'templatestyles', nil, { src = 'Module:Tabs/styles.css' } )
	return styles .. '<span class="mdl-tabs">' .. out .. '</span>'
end

return p
Discuss this page