Module:Tabs

-- -*- 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 k, v in pairs(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 = {} local i = 1 while true do       local selected = (args['select'] == i)        local content = p.getTabContent(args, i, args['select']) if not content then break end result[i] = {content = content, selected = selected and 1 or 0} i = i + 1 end return result end

return p