Jump to content

Module:Football squad

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ahecht (talk | contribs) at 20:05, 30 March 2022 (remove divs). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This implements Template:Football squad
local p = {}

local getArgs = require('Module:Arguments').getArgs
local Navbox = require('Module:Navbox')

local function notblank(v)
	return mw.ustring.match((v or ''),'%S') ~= nil
end

local function makeError(msg)
	return mw.text.tag('strong', {['class']='error'}, msg)
end

local function listDecode(json, listType)
	local status, plist = pcall(mw.text.jsonDecode, json)
	if not status then
		return makeError('Error decoding ' .. listType .. ' list: ' .. plist)
	end
	
	local outStr = ""
	for k, v in pairs (plist) do
		if not v.name then
			return makeError('Error: Missing name on line ' .. k .. ' of ' .. listType .. ' list.')
		end
		
		local prefix
		if listType == 'manager' then
			prefix = (notblank(v.title) and v.title or 'Manager') .. ": "
		else
			prefix = (notblank(v.no) and (v.no .. ' ') or '')
		end
		
		outStr = outStr .. mw.ustring.format( '* <span class="nowrap agent vcard">%s<span class="fn">%s</span></span>\n', prefix, v.name)
	end
	return outStr
end
			
		
function p.navbox(frame)
	local args = getArgs(frame)
	
	args.name = args.name or "{{{name}}}"
	args.state = args.state or "autocollapse"
	args.teamname = args.teamname or "{{{teamname}}}"
	args.bgcolor = args.bgcolor or "#ccf"
	args.textcolor = args.textcolor or "#000"
	args.bordercolor = args.bordercolor or ""
	args.players = notblank(args.players) and listDecode(args.players, "player") or ''
	args.managers = notblank(args.managers) and listDecode(args.managers, "manager") or ''
	
	args.list1 = args.players .. (args.list1 or args.list or '') .. args.managers
	if args.list1 == '' then args.list1 = '{{{list}}}' end

	args.titlestyle = args.titlestyle or ("background:" .. args.bgcolor .. 
		"; color:" .. args.textcolor .. 
		"; box-shadow: inset 1px 1px 0 " .. args.bordercolor .. ", inset -1px -1px 0 " .. args.bordercolor .. 
		"; width:87%;")
	args.title = args.title or args.teamdisplay or args.teamname
	args.title = "[[" .. args.teamname .. "|<span style=\"color:" .. args.textcolor .. ";\">" .. args.title .. "</span>]] <span style=\"color:" .. args.textcolor .. ";\"> &ndash; current squad</span>"
	
	return Navbox._navbox({
		name       = args.name,
		state      = args.state,
		bodystyle  = nil,
		bodyclass  = "vcard",
		titleclass = "fn org",
		listclass  = "hlist",
		titlestyle = args.titlestyle,
		title      = args.title,
		list1      = args.list1
	})
end

return p