Module:Sandbox/LVLGive feedback
Documentation for this module may be created at Module:Sandbox/LVL/doc
local Tabs = {}
-- Helper functions
local function readBool(val)
if val == nil then return false end
if type(val) == 'boolean' then return val end
if type(val) == 'string' then
val = val:lower()
return val == 'true' or val == 'yes' or val == '1'
end
return false
end
local function getDisplayNameFromLink(link)
return link:match('([^/]+)$') or link
end
-- Main function
function Tabs.static(frame)
local args = frame.args or {}
-- Find all tabs
local tabs = {}
local i = 1
while args['name' .. i] or args['link' .. i] do
table.insert(tabs, {
name = args['name' .. i],
link = args['link' .. i],
this = (tonumber(args.This) == i)
})
i = i + 1
end
if #tabs == 0 then
return 'Error: No tabs defined (need at least name1 or link1)'
end
-- Auto-set first tab as active if none specified
if not args.This then
tabs[1].this = true
end
-- Build HTML
local container = mw.html.create('div')
:addClass('tabs-static')
local tablist = mw.html.create('ul')
:addClass('nav nav-tabs tabs tabs' .. #tabs)
for _, tab in ipairs(tabs) do
local display = tab.name or getDisplayNameFromLink(tab.link)
local text = tab.link and ('[[' .. tab.link .. '|' .. display .. ']]') or display
tablist:tag('li')
:addClass(tab.this and 'active' or nil)
:wikitext(text)
end
return container:node(tablist)
end
return Tabs