Module:Tabs

-- credits to Virtual YouTuber Wiki -- -*- mode: Lua; lua-indent-level: 4; -*- -- Syntax: -- -- local p = {} local getArgs = require('Module:Arguments').getArgs

function p.main(frame) local tabs = p.realMain(getArgs(frame, {wrappers = 'Template:Tabs'})) local result = '' for i, v in ipairs(tabs) do       result = result .. frame:expandTemplate{title = 'Tabs/Render', args = v}   end return result end

function p.getTabContent(args, i, selected_tab) local mode = 'complex' local input = args['tab' .. tostring(i)] if not input then input = args[i] mode = 'simple' end if not input then return false end

if mode == 'complex' then -- complex mode: just return the input return input end if selected_tab == i then -- simple mode; tab selected: return bolded text return ' .. mw.text.encode(input) .. '   end

-- simple mode; tab not selected input = mw.text.nowiki(input) -- escape if i == 1 then -- first tab: link to the parent page return  .. input ..  end

-- not the first tab if selected_tab == 1 then -- we are in the "main" page: link to a subpage return  .. input ..  else -- we are in a subpage: link to a sibling page return  .. input ..  end end

function p.realMain(args) args['select'] = tonumber(args['select']) if not args['select'] then args['select'] = 1 end local result = {} -- If the first tab is selected, render a short line if args['select'] == 1 then table.insert(result, {line = 1}) end -- Render each individual tab local currentTab = 1 while true do       local selectedInt = (args['select'] == currentTab) and 1 or 0 local content = p.getTabContent(args, currentTab, args['select']) if not content then break end table.insert(result, {content = content, selected = selectedInt}) currentTab = currentTab + 1 end -- If the last tab is selected, render a short line if args['select'] == currentTab - 1 then table.insert(result, {line = 1}) end return result end

return p