You can edit almost every page by Creating an account and confirming your email.

Module:Hockey team color

From EverybodyWiki Bios & Wiki

This module is currently only used by

{{NHL team color}}

Usage

  • {{#invoke:Hockey team color|color}} in any variation of the color templates.
  • {{#invoke:Hockey team color|function_name}} As a general rule for how the module functions.

Updating team colors

See Module:Hockey team color/data.

Test table

Team12345Contrast
1/24/3
Anaheim Ducks211.03
Arizona CoyotesX8.8316.45
Boston BruinsXX21
Buffalo SabresX14.941.24
Calgary FlamesX4.6512.68
Carolina HurricanesX6.346.18
Chicago BlackhawksXX4.65
Colorado Avalanche10.062.77
Columbus Blue JacketsX16.052.61
Dallas StarsX6.228.84
Detroit Red WingsX4.654.65
Edmonton OilersXX10.52
Florida PanthersX5.886.02
Los Angeles KingsXX21
Minnesota Wild5.995.18
Montreal CanadiensXX5.99
Nashville PredatorsXX1.73
New Jersey DevilsXX4.65
New York IslandersXX7.84
New York RangersXX6.66
Ottawa SenatorsX4.658.83
Philadelphia FlyersXX2.74
Pittsburgh PenguinsXX21
San Jose SharksX5.198.85
St. Louis BluesX7.827.84
Tampa Bay LightningXX10.72
Toronto Maple LeafsX11.4711.47
Vancouver CanucksXX10.55
Vegas Golden KnightsX10.84.62
Washington CapitalsXX4.65
Winnipeg Jets16.542.95
Free agentXXX15.31
RetiredXXX15.31
The numeric columns are the calculated contrast ratio for the first/second and the fourth/third colors. Anything lower than 3 is very poor contrast and should be changed in the data module. For more information, see Template:Color contrast ratio.



--
-- This module implements (or will be implemented)
-- {{NHL color}}
--
local p = {}

local data_module = "Module:Hockey team color/data"

local function stripwhitespace(text)
	return text:match("^%s*(.-)%s*$")
end

local function get_colors(team, unknown)
	team = stripwhitespace(team or '')
	unknown = unknown or {"DCDCDC", "FFFFFF", "000000", "000000"}
	
	local use_default = {
		[""] = 1,
		["retired"] = 1,
		["free agent"] = 1,
	}

	local colors = nil
	
	if ( team and use_default[team:lower()] ) then
		colors = {"DCDCDC", "FFFFFF", "DCDCDC", "000000"}
	else
		local all_colors = mw.loadData(data_module)
		colors = all_colors[team]
		if ( colors and type(colors) == 'string' ) then
			colors = all_colors[colors]
		end
	end

	return colors or unknown
end

local function team_color(team, num)
	local colors = get_colors(team, nil)

	num = tonumber(num:match('[1-4]') or '0')
	if ( num ) then
		return colors[num]
	else
		return ''
	end
end

function p.color(frame)
	local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
	return team_color(args[1] or '', args[2] or '')
end

return p