Jump to content

Module:PHL sports team/testtable

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by McVahl (talk | contribs) at 08:50, 21 February 2020 (Created page with 'local p = {} local div = { 'short', 'men', 'women', 'boys', 'girls', 'name' } local mod = 'Module:PHL sports team' local function labels() local lbls = {} for...'). 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)
local p = {}
local div = { 'short', 'men', 'women', 'boys', 'girls', 'name' }
local mod = 'Module:PHL sports team'

local function labels()
	local lbls = {}
	for k, text in pairs(div) do
		local lbl = mw.html.create(''):tag('span'):css('display', 'inline-block'):css('width', '30px'):cssText(style).wikitext(text)
		table.insert(lbls, tostring(lbl))
	end
	return lbls
end

local function table_row(frame, l, t, c)
	local res = mw.html.create('')
	
	local fname = frame:preprocess(string.format('{{#invoke:%s|name|%s|short}}<br>', mod, t))
	local frt = frame:preprocess(string.format('{{#invoke:%s|rt|%s|short}}<br>', mod, t))
	local fmain = frame:preprocess(string.format('{{#invoke:%s|main|%s|short}}<br>', mod, t))
	
	for i=3,6 do
		fmain = fmain .. frame:preprocess(string.format('{{#invoke:%s|main|%s|%s}}<br>', mod, t, i))
		frt = frt .. frame:preprocess(string.format('{{#invoke:%s|rt|%s|%s}}<br>', mod, t, i))
		fname = fname .. frame:preprocess(string.format('{{#invoke:%s|name|%s|%s}}<br>', mod, t, i))
	end
	
	fname = fname .. frame:preprocess(string.format('{{#invoke:%s|name|%s|name=Customized Team Name}}<br>', mod, t))
	frt = frt .. frame:preprocess(string.format('{{#invoke:%s|rt|%s|name=Customized Team Name}}<br>', mod, t))
	fmain = fmain .. frame:preprocess(string.format('{{#invoke:%s|main|%s|name=Customized Team Name}}', mod, t))
	
	res:tag('td'):wikitext(t)
	res:tag('td'):attr('align', 'center'):wikitext(c[1] or '—')
	res:tag('td'):wikitext(frame:preprocess(string.format('{{#invoke:%s|name|%s|2}}', mod, t)))
	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

function p._testtable(frame)
	-- build table
	local root = mw.html.create('table')
	local temp = {}
	
	root:addClass('wikitable sortable')
		:css('background', 'transparent')
		:css('font-size', '90%')
		:css('line-height', '100%')
		:cssText(style)
	
	local row = root:tag('tr')
	row:tag('th'):attr('rowspan',2):wikitext('Team')
	row:tag('th'):attr('rowspan',2):wikitext('Code')
	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\'\')')
	
	local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
	local data_module = mod .. '/' .. (args['level'] or 'collegiate')
	local data = mw.loadData(data_module)
	
	for k, teams in pairs(data) do
		table.insert(temp, k)
	end
	
	table.sort(temp)
	table.insert(data, nil)
	table.insert(temp, 'XYZ')

	-- local lbls = labels()
	for k, team in pairs(temp) do
		row = root:tag('tr')
		row:wikitext(table_row(frame, lbls, team, data[team] or ''))
	end

	return tostring(root)
end

function p.testtable(frame)
	return frame:preprocess(p._testtable(frame))
end

return p