Content deleted Content added
update doc for aliases |
+table for generic function |
||
Line 1:
local p = {}
local div = { 'short', 'men', 'women', 'boys', 'girls', 'name' }
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]
Line 13 ⟶ 15:
if d then
table.sort(d, function (a, b) return a < b end)
local param = showdiv and 'inst' or 'name'
for k, inst in pairs(d) do
if type(k) == 'string' and string.len(k) ~= 1 then
ia = ia .. string.format('<br>• %s (%s)', inst, k)
if tname then table.insert(ita, string.format('{{%s|%s|
end
end
Line 52 ⟶ 55:
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
local code = '<code><nowiki>' .. text .. '</nowiki></code>'
if it then
for k, ita in pairs(it) do
end
end
row:tag('td'):attr('align', align):wikitext(text)▼
row:tag('td'):attr('align', 'left'):wikitext(code)
▲ row:tag('td'):attr('align', align):wikitext(text)
return row
end
Line 82 ⟶ 85:
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
:attr('rowspan',showdiv and 7 or 3):attr('align', 'center')
:wikitext(c[1] and c[1] .. a.c or '—')
end
▲ 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')
if showdiv then
row = get_row_tname(root, row, align, rwom)▼
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)
Line 123 ⟶ 137:
row:tag('th'):wikitext('Team')
row:tag('th'):wikitext('Code')
row:tag('th'):wikitext('Output')▼
row:tag('th'):wikitext('Usage')
▲ row:tag('th'):wikitext('Output')
end
Line 130 ⟶ 144:
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
local data_module = string.format('Module:%s/%s', mod, args['
local data = mw.loadData(data_module)
for k,
if type(
else
if alias[
table.insert(alias[
end
end
Line 148 ⟶ 162:
local aliases = get_aliases(team, alias, data, tname)
row = root:tag('tr')
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'
local league = args['league'] or 'PBA'
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, 'PBA')
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
▲ row:wikitext(table_row_tname(frame, team, aliases, data[team] or ''))
table.insert(alias[team], k)
end
end
table.sort(temp)
table.insert(temp, '{{{team1}}}')
table.insert(temp, 'XYZ')
row:tag('th'):wikitext('Code')
row:tag('th'):wikitext('Output')
row:tag('th'):wikitext('Usage')
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
|