وحدة:Baseball color
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
This module is used by
- {{Baseball primary color}}, {{Baseball secondary color}}
- {{Baseball alternative primary color}}, {{Baseball alternative secondary color}}
- {{Baseball primary style}}, {{Baseball secondary style}}
- {{Infobox MLB player}}, {{Infobox baseball biography}}
Usage
{{#invoke:Baseball color|color}}
in any of the various color templates{{#invoke:Baseball color|colorcell}}
in the style and infobox templates{{#invoke:Baseball color|colorcell2}}
in the style and infobox templates{{#invoke:Baseball color|check}}
to check to see if a team has defined colors
Updating team colors
See Module:Baseball color/data.
Test table
Team | 1 | 2 | 3 | 4 |
---|---|---|---|---|
Acereros de Monclova | ||||
Adelaide Bite | ||||
Arizona Diamondbacks | ||||
Atlanta Braves | ||||
Baltimore Orioles | ||||
Beijing Tigers | ||||
Boston Red Sox | ||||
Bravos de León | ||||
Bridgeport Bluefish | ||||
Brisbane Bandits | ||||
Canberra Cavalry | ||||
Cangrejeros de Santurce | ||||
Chiba Lotte Marines | ||||
Chicago Cubs | ||||
Chicago White Sox | ||||
Chinatrust Brothers | ||||
Chunichi Dragons | ||||
Cincinnati Reds | ||||
Cleburne Railroaders | ||||
Cleveland Indians | ||||
Colorado Rockies | ||||
Criollos de Caguas | ||||
Detroit Tigers | ||||
Diablos Rojos del México | ||||
Doosan Bears | ||||
Fargo-Moorhead RedHawks | ||||
Florida Marlins | ||||
Fubon Guardians | ||||
Fukuoka SoftBank Hawks | ||||
Gary SouthShore RailCats | ||||
Generales de Durango | ||||
Guangdong Leopards | ||||
Guerreros de Oaxaca | ||||
Hanshin Tigers | ||||
Hanwha Eagles | ||||
Henan Elephants | ||||
Hiroshima Toyo Carp | ||||
Hokkaido Nippon-Ham Fighters aka Hokkaido Nippon Ham Fighters | ||||
Houston Astros | ||||
Indios de Mayagüez | ||||
Jiangsu Pegasus | ||||
KT Wiz | ||||
Kansas City Royals | ||||
Kansas City T-Bones | ||||
Kia Tigers | ||||
LG Twins | ||||
Lamigo Monkeys | ||||
Lancaster Barnstormers | ||||
Leones de Yucatán | ||||
Lincoln Saltdogs | ||||
Long Island Ducks | ||||
Los Angeles Angels | ||||
Los Angeles Angels of Anaheim | ||||
Los Angeles Dodgers | ||||
Lotte Giants | ||||
Melbourne Aces | ||||
Miami Marlins | ||||
Milwaukee Brewers | ||||
Minnesota Twins | ||||
Montreal Expos | ||||
NC Dinos | ||||
New Britain Bees | ||||
New Jersey Jackals | ||||
New York Mets | ||||
New York Yankees | ||||
Nexen Heroes | ||||
Oakland Athletics | ||||
Olmecas de Tabasco | ||||
Orix Buffaloes | ||||
Ottawa Champions | ||||
Pericos de Puebla | ||||
Perth Heat | ||||
Philadelphia Phillies | ||||
Piratas de Campeche | ||||
Pittsburgh Pirates | ||||
Québec Capitales | ||||
Rieleros de Aguascalientes | ||||
Rockland Boulders | ||||
Rojos del Águila de Veracruz | ||||
SK Wyverns | ||||
Saitama Seibu Lions | ||||
Salina Stockade | ||||
Samsung Lions | ||||
San Diego Padres | ||||
San Francisco Giants | ||||
Saraperos de Saltillo | ||||
Seattle Mariners | ||||
Shanghai Golden Eagles | ||||
Sichuan Dragons | ||||
Sioux City Explorers | ||||
Sioux Falls Canaries | ||||
Somerset Patriots | ||||
Southern Maryland Blue Crabs | ||||
St. Louis Cardinals | ||||
St. Paul Saints | ||||
Sugar Land Skeeters | ||||
Sultanes de Monterrey | ||||
Sussex County Miners | ||||
Sydney Blue Sox | ||||
Tampa Bay Rays | ||||
Texas AirHogs | ||||
Texas Rangers | ||||
Tianjin Lions | ||||
Tigres de Quintana Roo | ||||
Tohoku Rakuten Golden Eagles | ||||
Tokyo Yakult Swallows | ||||
Toronto Blue Jays | ||||
Toros de Tijuana | ||||
Trois-Rivières Aigles | ||||
Uni-President 7-Eleven Lions aka Uni-President Lions | ||||
Vaqueros Unión Laguna | ||||
Washington Nationals | ||||
Wichita Wingnuts | ||||
Winnipeg Goldeyes | ||||
Yokohama DeNA BayStars aka Yokohama BayStars | ||||
Yomiuri Giants | ||||
York Revolution | ||||
Free agent | ||||
Retired |
--
-- This module implements
-- {{Baseball primary color}}, {{Baseball secondary color}},
-- {{Baseball alternative primary color}}, {{Baseball alternative secondary color}}
-- {{Baseball primary style}}, {{Baseball secondary style}}
--
local p = {}
local data_module = "Module:Baseball 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", "000000", "DCDCDC", "000000"}
local use_default = {
[""] = 1,
["retired"] = 1,
["free agent"] = 1,
}
local colors = nil
if ( team and use_default[team:lower()] ) then
colors = {"DCDCDC", "000000", "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_check(team, unknown)
local colors = get_colors(team, unknown)
if type(colors) == 'table' then
return 'known'
else
return unknown
end
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
local function team_colorcell(team, borderwidth, bg, fg, bd)
local colors = get_colors(team, nil)
local border = ''
borderwidth = tonumber(borderwidth or '0') or 0
if (borderwidth > 0) then
local bordercolor = stripwhitespace(colors[bd]) or 'FFFFFF'
if bordercolor ~= 'FFFFFF' then
border = 'border:' .. borderwidth .. 'px solid #' .. bordercolor .. ';'
end
end
return 'background-color:#' .. stripwhitespace(colors[bg]) .. ';color:#' .. stripwhitespace(colors[fg]) .. ';' .. border
end
function p.check(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
return team_check(args[1] or '', args[2] or '')
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
function p.colorcell(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
return team_colorcell(args[1] or '', args['border'] or '', 1, 2, 3)
end
function p.colorcell2(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
return team_colorcell(args[1] or '', args['border'] or '', 3, 4, 1)
end
return p