Jump to content

Module:Sports roster

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 15:39, 25 June 2019 (Created page with 'require('Module:No globals') local p = {} local getArgs = require('Module:Arguments').getArgs local function parsePlayer(s, keys) local res = {} for k,v in p...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('Module:No globals')
local p = {}

local getArgs = require('Module:Arguments').getArgs

local function parsePlayer(s, keys)
	local res = {}
	for k,v in pairs(mw.text.split(s, '%s*<[Tt][Dd]%s*')) do
		v = mw.ustring.gsub(v, '%s*</[Tt][Dd]>%s*', '')
		if v:find('^[^>]*class%s*=%s*[\'"][^\'"]*sports%-roster%-([a-z]+)%s*[\'"][^>]*>%s*([^%s].-*)%s*$') then
			local kk =  mw.ustring.gsub(v, '^[^>]*class%s*=%s*[\'"][^\'"]*sports%-roster%-([a-z]+)%s*[\'"][^>]*>%s*([^%s].-*)%s*$', '%1')
			res[kk] = mw.ustring.gsub(v, '^[^>]*class%s*=%s*[\'"][^\'"]*sports%-roster%-([a-z]+)%s*[\'"][^>]*>%s*([^%s].-*)%s*$', '%2')
			keys[kk] = 1
		end
	end
	return keys, res
end

local function getPlayers(args)
	local i = 1
	local res, keys = {}, {}
	local v
	while args[i] ~= nil do
		keys, v = parsePlayer(args[i], keys)
		if k then
			keys[k] = 1
			table.insert(res, v)
		end
		i = i + 1
	end
	return res, keys
end

function p.entry(frame)
	local args = getArgs(frame)
	local res = ''
	for k,v in pairs(args) do
		if type(k) == 'string' then
			res = res .. '<td class="sports-roster-' .. k .. '">' .. v .. '</td>'
		end
	end
end

function p.roster(frame)
	local args = getArgs(frame)
	local players, keys = getPlayers(args)
	local style = 'Module:Sports roster/default'
	if args['style'] and mw.title.new('Module:Sports roster/' .. args['style']) then
		style = 'Module:Sports roster/' .. args['style']
	end
	local p_header = require(style).header
	local p_players = require(style).players_roster
	local p_players = require(style).coaches_roster
	local p_staff = require(style).staff_roster
	local p_footer = require(style).footer
	
	return p_header(args, keys) 
		.. p_players(args, players, keys)
		.. p_coaches(args, keys)
		.. p_staff(args, keys)
		.. p_footer(args, keys)
end

function p.navbox(frame)
	local args = getArgs(frame)
	local players, keys = getPlayers(args)
	local style = 'Module:Sports roster/default'
	if args['style'] and mw.title.new('Module:Sports roster/' .. args['style']) then
		style = 'Module:Sports roster/' .. args['style']
	end
	local p_players = require(style).players_list
	local p_coaches = require(style).coaches_list

	local Navbox = require('Module:Navbox')

	local targs = {}
	targs['name'] = args['name'] or mw.title.getCurrentTitle().text
	targs['title'] = require(style).title(args)
	targs['titlestyle'] = require(style).titlestyle(args)
	targs['listclass'] = 'hlist'
	targs['state'] = args['state'] or 'autocollapse'
	targs['list1'] = p_players(args, players, keys) .. '\n' .. p_coaches(args)
	targs['below'] = require(style).below(args, keys)
	targs['belowstyle'] = targs['below'] and require(style).belowstyle(args) or nil

	return Navbox._navbox(targs)
end

return p