Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Please sign up or log in to edit the wiki.

Module:Tabber: Difference between revisions

From the Star Citizen Wiki, the fidelity™ encyclopedia
Content deleted Content added
No edit summary
Tag: Manual revert
No edit summary
Line 1: Line 1:
local p = {}
local p = {}


--- Helper function to get table length
--- Helper function to get Tabber length
--- @param table
--- @param table
--- @return int
--- @return int
local function getTableLength( t )
local function getTabberLength( t )
local length = 0
local length = 0
for _, __ in pairs(t) do
for k, _ in pairs(t) do
length = length + 1
if k:find( 'label', 1, true ) then
length = length + 1
end
end
end
return length
return length
Line 18: Line 20:
local tabberContent = {}
local tabberContent = {}


for i = 1, getTableLength( data ) / 2 do
for i = 1, getTabberLength( data ) do
local label = data[ 'label' .. i ]
local label = data[ 'label' .. i ]
if label ~= nil or label ~= '' then
if label ~= nil or label ~= '' then

Revision as of 02:17, 31 May 2023

Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Tabber/doc. Changes can be proposed in the talk page.
Function list
L 6 — getTabberLength
L 19 — p.renderTabber

This module is used by Lua modules to create Tabber layout.


local p = {}

--- Helper function to get Tabber length
--- @param table
--- @return int
local function getTabberLength( t )
	local length = 0
    for k, _ in pairs(t) do
    	if k:find( 'label', 1, true ) then
        	length = length + 1
        end
    end
    return length
end

--- Render Tabber
--- @param table data { label = content }
--- @return string wikitext of Tabber
function p.renderTabber( data )
	local tabberContent = {}

	for i = 1, getTabberLength( data ) do
		local label = data[ 'label' .. i ]
		if label ~= nil or label ~= '' then
			table.insert( tabberContent, table.concat( { '|-|', label, '=', data[ 'content' .. i ] } ) )
		end
	end

	return mw.getCurrentFrame():extensionTag{
        name = 'tabber', content = table.concat( tabberContent )
    }
end

return p