Module:Sports roster
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This module depends on the following other modules: |
Usage
This module implements {{sports roster}} and {{sports roster/entry}}. Please see {{sports roster}} for usage.
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