Module:PHL sports team/testtable: Difference between revisions

Content deleted Content added
Undid revision 945133066 by McVahl (talk)
update doc for aliases
Line 3:
local mod = 'PHL sports team'
 
local function labelsget_aliases(t, a, d, tname)
local lblsca, ia, ita = '', '', {}
forlocal ka, textd in= pairs(div)a[t], dod[t]
local lbl = mw.html.create(''):tag('span'):css('display', 'inline-block'):css('width', '30px'):cssText(style).wikitext(text)
if a then
table.insert(lbls, tostring(lbl))
for k, aka in pairs(a) do ca = ca .. string.format('<br>(%s)', aka) end
end
return lbls
if d then
table.sort(d, function (a, b) return a < b end)
for k, inst in pairs(d) do
if type(k) == 'string' then
ia = ia .. string.format('<br>• %s (%s)', inst, k)
if tname then table.insert(ita, string.format('{{%s|%s|inst=%s}}', tname, t, k)) end
end
end
end
table.sort(ita, function (a, b) return a < b end)
return { c = ca, i = ia, it = ita }
end
 
local function table_row_all(frame, lt, ta, c)
local res = mw.html.create('')
Line 30 ⟶ 43:
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('{{#invoke:%s|name|%s|2}}', mod, t)) .. a.i)
res:tag('td'):wikitext(fmain or '—')
res:tag('td'):attr('align', 'right'):wikitext(frt or '—')
Line 38 ⟶ 51:
end
 
local function get_row_tname(root, row, align, text, tag, it)
local yesno, code = require('Module:Yesno'), '<code><nowiki>' .. text .. '</nowiki></code>'
if yesno(tag or 'y') then
row = root:tag('tr')
end
if it then
for k, ita in pairs(it) do
text = text .. '<br>' .. ita
code = code .. '<br><code><nowiki>' .. ita .. '</nowiki></code>'
end
end
row:tag('td'):attr('align', align):wikitext(text)
row:tag('td'):attr('align', 'left'):wikitext('<code><nowiki>' .. text .. '</nowiki></code>')
return row
end
 
local function table_row_tname(frame, lt, ta, c)
local tname = frame.args['tname'] or 'UAAPteam'
local align = frame.args['align'] or 'left'
Line 64 ⟶ 84:
row:tag('td'):css('border-bottom', '2px solid black'):cssText('style'):attr('rowspan',7):wikitext(t)
row:tag('td'):css('border-bottom', '2px solid black'):cssText('style'):attr('rowspan',7):attr('align', 'center'):wikitext(c[1] and c[1] .. a.c or '—')
row = get_row_tname(root, row, align, rdef, 'n')
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)
row = get_row_tname(root, row, align, rsrt)
row = get_row_tname(root, row, align, rcst)
Line 79 ⟶ 99:
-- build table
local root = mw.html.create('table')
local temp, alias = {}, {}
root:addClass('wikitable sortable')
Line 114 ⟶ 134:
for k, teams in pairs(data) do
if type(teams) ~= 'string' then table.insert(temp, k)
else
if alias[teams] == nil then alias[teams] = {} end
table.insert(lblsalias[teams], tostring(lbl)k)
end
end
Line 121 ⟶ 145:
table.insert(temp, 'XYZ')
 
-- local lbls = labels()
for k, team in pairs(temp) do
local aliases = get_aliases(team, alias, data, tname)
row = root:tag('tr')
if tname == nil then
row:wikitext(table_row_all(frame, lblsteam, teamaliases, data[team] or ''))
else
row:wikitext(table_row_tname(frame, lblsteam, teamaliases, data[team] or ''))
end
end