Module:TournamentTabs

-- TournamentTabs local settings = require('Module:SubpageSettings').tournaments local util = require('Module:Util') local pageinfo = require('Module:GetEventPageInfo') local tabs = require('Module:AutomatedTabs')

local p = {} function p.makeArgsIntoTables(args) for key, value in pairs(args) do		if not p.doWeSkip(key) then args[key] = mw.text.split(value,'%s*%f[,%%],%s*') end end end

function p.doWeSkip(key) if settings.dontconvert[key] then return true end for k, v in pairs(settings.dontconvert_patterns) do		if string.find(key, v, 1, true) then return true end end return false end

-- making json function p.jsonFromArgs(args) if args.oldMD == 'Yes' then p.oldMD(args) end local tbl = {} p.jsonRecursion(tbl, args, nil) return tbl end

function p.oldMD(args) -- oldMD is an arg to make a shortcut for every Match Details artificially becoming named -- Match Details & VODs for _, event in ipairs(args.events) do args[event .. '_names_Match Details'] = 'Match Details' end args['names_Match Details'] = 'Match Details' args['events_names_Match Details'] = 'Match Details' return end

function p.jsonRecursion(tbl, args, path) -- names are made ready for output now but links are kept in canonical form until output local thispath = path or 'events' local links = mw.clone(args[thispath]) p.processLinks(links) local names = mw.clone(args[thispath .. '_names'] or links) p.processNames(args, thispath, names, links) tbl.links = links tbl.names = names if args[thispath .. '_nooverview'] ~= 'Yes' then tbl.links[1] = 'Overview' end for k, v in ipairs(links) do		local newpath = tabs.newIndex(path, v)		if args[newpath] and not tbl[v] then tbl[v] = {} p.jsonRecursion(tbl[v],args,newpath) end end -- if we don't specify if it's specificaly not an overview page -- then we probably don't want any subpage for the first tab if args[thispath .. '_nooverview'] ~= 'Yes' then tbl.links[1] = '' end return tbl end

function p.processLinks(links) for k, link in ipairs(links) do		links[k] = settings.lookup[mw.ustring.lower(link)] or link end return end

function p.processNames(args, path, names, links) for key, name in ipairs(names) do names[key] = args[path .. '_names_' .. links[key]] or settings.names[name] or name end return end

-- make navbox args function p.getNavboxData(args) local navboxdata = {} for i, navbox in ipairs(args.navboxes) do		navboxdata[i] = { title = navbox, args = {}, events = args['navbox' .. i .. '_events'] or { showAll = true } }		for k,v in pairs(args['navbox' .. i .. '_keys'] or {}) do navboxdata.args[v] = args['navbox' .. i .. '_values'][v] end end return navboxdata end

-- link manipulation function p.linkAdjustments(args) local tbl = {} tbl.fr = p.linkAdjustments_makeFR(args.titlefind, args.titlereplace) tbl.cd = p.linkAdjustments_makeCD(args.currentdata_pages or {}, args.currentdata_values or {}) return tbl end

function p.linkAdjustments_makeFR(find, replace) -- in case the tournament has different base urls for different sections return find and replace and { find = find, replace = replace } or { find = {}, replace = {} } end

function p.linkAdjustments_makeCD(pages, values) -- current data makes a different subpage from the overview focused local data = {} for k, v in ipairs(pages) do		data[v] = util.concatSubpage(v,values[k]) end return data end

function p.getCategories local title = mw.title.getCurrentTitle if title.nsText == 'Template' then return '' end return end

-- main function p.fromArgs(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end -- process data if not args.events then args.events = args.Overview end p.makeArgsIntoTables(args) local navboxdata = args.navboxes and p.getNavboxData(args) local json = p.jsonFromArgs(args) local linkadjustments = p.linkAdjustments(args) local after = p.getCategories pageinfo.getEventPageInfo(frame) -- for vardefines return tabs.main(json, linkadjustments, navboxdata, args.showCorr and args, args.basepage, after) end

return p