Leaguepedia | League of Legends Esports Wiki
Advertisement

Documentation for this module may be created at Module:FLLinks/doc

local util_args = require('Module:ArgsUtil')
local util_text = require('Module:TextUtil')
local util_title = require('Module:TitleUtil')
local TAB_NAMES = mw.loadData('Module:SubpageSettings').tournaments
local lang = mw.getLanguage('en')

local h = {}
local p = {}
function p.main(frame)
	local args = util_args.merge()
	
	local basepage = args.basepage
	if not basepage then
		error('Missing basepage!')
	end
	local tabs = h.getLinks(args.tabs, basepage)
	local streams = h.getStreams(args.streams, args.streamnames)
	return h.makeOutput(basepage, tabs, streams)
end

function h.getLinks(argLinks, basepage)
	if not argLinks then
		return { links = {}, names = {} }
	else
		local extensions = util_text.split(argLinks)
		local names = {}
		local links = {}
		for k, v in ipairs(extensions) do
			local tab = TAB_NAMES.lookup[lang:lc(v)] or v
			names[#names+1] = TAB_NAMES.names[tab]
			links[#links+1] = util_title.concatSubpage(basepage, tab)
		end
		return { links = links, names = names }
	end
end

function h.getStreams(argLinks, argNames)
	local links = util_text.split(argLinks or '')
	local names = h.getStreamNames(argNames, #links)
	return { links = links, names = names }
end

function h.getStreamNames(names, len)
	if names then
		return util_text.split(argNames or '')
	elseif len == 1 then
		return { 'Stream' }
	else
		local output = {}
		for k = 1, len do
			output[#output+1] = 'Stream ' .. k
		end
		return output
	end
end

function h.makeOutput(basepage, tabs, streams)
	local output = mw.html.create('div')
		:addClass('fl-bottom')
	h.printLinks(output, tabs.links, tabs.names)
	h.printStreams(output, streams.links, streams.names)
	return output
end

function h.printLinks(output, links, names)
	for i, v in ipairs(links) do
		local content = util_text.intLink(v, names[i])
		h.printOneLink(output, content)
	end
end

function h.printStreams(output, links, names)
	for i, v in ipairs(links) do
		local content = util_text.extLink(v, names[i])
		h.printOneLink(output, content)
	end
end

function h.printOneLink(output, content)
	output:tag('div')
		:addClass('fl-bottom-link')
		:wikitext(content)
end

return p
Advertisement