Module:PHL sports team/testtable explained

local yesno = require('Module:Yesno')

local p = local div = local mod = 'PHL sports team'

local function get_aliases(t, a, d, tname, showdiv) local ca, ia, ita = , , local a, d = a[t], d[t] if a then for k, aka in pairs(a) do ca = ca .. string.format('
(%s)', aka) end end if d then table.sort(d, function (a, b) return a < b end) local param = showdiv and 'inst' or 'yr' local yr = for k, inst in pairs(d) do if type(k)

'string' and k ~= 'dab' and k ~= 'link' then ia = ia .. string.format('
• %s (%s)', inst, k) if tname then table.insert(ita, string.format(showdiv and '' or ' (%s)', tname, t, param, showdiv and k or k:sub(1, 4), k:gsub("thru", "–"))) end end end end table.sort(ita, function (a, b) return a < b end) return end

local function table_row_all(frame, t, a, c) local res = mw.html.create() local fname = frame:preprocess(string.format('
', mod, t)) local frt = frame:preprocess(string.format('
', mod, t)) local fmain = frame:preprocess(string.format('
', mod, t)) for i=3,6 do fmain = fmain .. frame:preprocess(string.format('
', mod, t, i)) frt = frt .. frame:preprocess(string.format('
', mod, t, i)) fname = fname .. frame:preprocess(string.format('
', mod, t, i)) end fname = fname .. frame:preprocess(string.format('
', mod, t)) frt = frt .. frame:preprocess(string.format('
', mod, t)) fmain = fmain .. frame:preprocess(string.format('', mod, t)) res:tag('td'):wikitext(t) res:tag('td'):attr('align', 'center'):wikitext(c[1] and c[1] .. a.c or '—') res:tag('td'):wikitext(frame:preprocess(string.format('', mod, t)) .. a.i) res:tag('td'):wikitext(fmain or '—') res:tag('td'):attr('align', 'right'):wikitext(frt or '—') res:tag('td'):wikitext(fname or '—') return tostring(res)end

local function get_row_tname(root, row, align, text, tag, it) if yesno(tag or 'y') then row = root:tag('tr') end local code = '<nowiki>' .. text .. '</nowiki>' if it then for k, ita in pairs(it) do code = code .. '
or <nowiki>' .. ita .. '</nowiki>' text = text .. '
or ' .. ita end end row:tag('td'):attr('align', 'left'):wikitext(code) row:tag('td'):attr('align', align):wikitext(text) return rowend

local function table_row_tname(frame, t, a, c) local tname = frame.args['tname'] or 'UAAPteam' local align = frame.args['align'] or 'left' local rdef = string.format('', tname, t) local rwom = string.format('', tname, t) local rjnr = string.format('', tname, t) local rgrl = string.format('', tname, t) local rins = string.format('', tname, t) local rsrt = string.format('', tname, t) local rcst = string.format('', tname, t) local root = mw.html.create() local row = root:tag('tr') local showdiv = yesno(frame.args.div or 'y') row:tag('td'):css('border-bottom', '2px solid black'):cssText('style') :attr('rowspan',showdiv and 7 or 3):wikitext(t) if showdiv then row:tag('td'):css('border-bottom', '2px solid black'):cssText('style') :attr('rowspan',showdiv and 7 or 3):attr('align', 'center') :wikitext(c[1] and c[1] .. a.c or '—') end row = get_row_tname(root, row, align, rdef, 'n') if showdiv then row = get_row_tname(root, row, align, rwom) row = get_row_tname(root, row, align, rjnr) row = get_row_tname(root, row, align, rgrl) row = get_row_tname(root, row, align, rins, nil, a.it) end row = get_row_tname(root, row, align, rsrt) row = get_row_tname(root, row, align, rcst, nil, not showdiv and a.it) row:css('border-bottom', '2px solid black'):cssText('style') return tostring(root)end

function p._testtable(frame) -- build table local root = mw.html.create('table') local temp, alias =, root:addClass('wikitable sortable') :css('background', 'transparent') :css('font-size', '90%') local row = root:tag('tr') local tname = frame.args['tname'] if (tname

nil) then root:css('line-height', '100%') row:tag('th'):attr('rowspan',2):wikitext('Team') row:tag('th'):attr('rowspan',2):wikitext('Code or
Alias/es') row:tag('th'):attr('rowspan',2):wikitext('School') row:tag('th'):wikitext('Left-sided icon') row:tag('th'):wikitext('Right-sided icon') row:tag('th'):wikitext('No icon') row = root:tag('tr') row:tag('th'):wikitext('(Function: \'\'main\'\')') row:tag('th'):wikitext('(Function: \'\'rt\'\')') row:tag('th'):wikitext('(Function: \'\'name\'\')') else row:tag('th'):wikitext('Team') row:tag('th'):wikitext('Code or
Alias/es') row:tag('th'):wikitext('Usage') row:tag('th'):wikitext('Output') end root:cssText(style) local args = (frame.args[1] ~= nil) and frame.args or frame:getParent.args local data_module = string.format('Module:%s/%s', mod, args['league'] or 'collegiate') local data = mw.loadData(data_module) for k, team in pairs(data) do if type(team) ~= 'string' then table.insert(temp, k) else if alias[team]

nil then alias[team] = end table.insert(alias[team], k) end end table.sort(temp) table.insert(temp, '')-- table.insert(temp, 'XYZ')

for k, team in pairs(temp) do local aliases = get_aliases(team, alias, data, tname, true) row = root:tag('tr') if tname then row:wikitext(table_row_tname(frame, team, aliases, data[team] or )) else row:wikitext(table_row_all(frame, team, aliases, data[team] or )) end end

return tostring(root)end

function p._main(frame) -- build table local root = mw.html.create('table') local args = (frame.args[1] ~= nil) and frame.args or frame:getParent.args local tname = args['tname'] or 'PBA team' or 'MPBL team' local league = args['league'] or 'PBA' or 'MPBL' local temp, alias =, local root = mw.html.create('table') root:addClass('wikitable sortable') :css('background', 'transparent') :css('font-size', '90%') local row = root:tag('tr') local data_module = string.format('Module:%s/%s', mod, league) local data = mw.loadData(data_module) for k, team in pairs(data) do if type(team) ~= 'string' then table.insert(temp, k) else if alias[team]

nil then alias[team] = end table.insert(alias[team], k) end end table.sort(temp) table.insert(temp, '')-- table.insert(temp, 'XYZ')

row:tag('th'):wikitext('Code or
Alias/es') row:tag('th'):wikitext('Usage') row:tag('th'):wikitext('Output')

for k, team in pairs(temp) do local aliases = get_aliases(team, alias, data, tname, yesno(args.div)) row = root:tag('tr') row:wikitext(table_row_tname(frame, team, aliases, data[team] or )) end return tostring(root)end

function p.testtable(frame) frame.args['div'] = 'y' return frame:preprocess(p._testtable(frame))end

function p.main(frame) frame.args['div'] = 'n' return frame:preprocess(p._main(frame))end

return p