Modul:Baseball color
Modul ini dinilai siap digunakan secara umum. Modul ini sudah matang dan diperkirakan bebas dari bug dan siap digunakan pada tempat yang tepat di manapun. Modul ini siap disinggung di halaman-halaman bantuan dan sumber informasi Wikipedia lainnya sebagai pilihan untuk dipelajari para pengguna baru. Untuk mengurangi beban server dan output yang tidak diharapkan, modul ini harus diperlengkapi dengan halaman bak pasir dan kasus uji daripada harus melakukan suntingan coba-dan-salah berulang-ulang. |
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
sunting{{#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
suntingSee Module:Baseball color/data.
Test table
suntingTeam | 1 | 2 | 3 | 4 |
---|---|---|---|---|
Acereros de Monclova | ||||
Adelaide Bite | ||||
Arizona Diamondbacks | ||||
Atlanta Braves | ||||
Baltimore Orioles | ||||
Beijing Tigers | ||||
Boston Red Sox | ||||
Brisbane Bandits | ||||
Broncos de Reynosa | ||||
Brother Elephants aka Chinatrust Brothers | ||||
Canberra Cavalry | ||||
Chiba Lotte Marines | ||||
Chicago Cubs | ||||
Chicago White Sox | ||||
Chunichi Dragons | ||||
Cincinnati Reds | ||||
Cleveland Indians | ||||
Colorado Rockies | ||||
Delfines de Ciudad del Carmen aka Delfines del Carmen | ||||
Detroit Tigers | ||||
Diablos Rojos del México | ||||
Doosan Bears | ||||
EDA Rhinos | ||||
Florida Marlins | ||||
Fukuoka SoftBank Hawks | ||||
Guangdong Leopards | ||||
Guerreros de Oaxaca | ||||
Hanshin Tigers | ||||
Hanwha Eagles | ||||
Hiroshima Toyo Carp | ||||
Hokkaido Nippon Ham Fighters | ||||
Houston Astros | ||||
Jiangsu Hopestars | ||||
KT Wiz | ||||
Kansas City Royals | ||||
Kia Tigers | ||||
LG Twins | ||||
Lamigo Monkeys | ||||
Leones de Yucatán | ||||
Los Angeles Angels of Anaheim | ||||
Los Angeles Dodgers | ||||
Lotte Giants | ||||
Melbourne Aces | ||||
Miami Marlins | ||||
Milwaukee Brewers | ||||
Minnesota Twins | ||||
Montreal Expos | ||||
NC Dinos | ||||
New York Mets | ||||
New York Yankees | ||||
Nexen Heroes | ||||
Oakland Athletics | ||||
Olmecas de Tabasco | ||||
Orix Buffaloes | ||||
Pericos de Puebla | ||||
Perth Heat | ||||
Petroleros de Minatitlán | ||||
Philadelphia Phillies | ||||
Piratas de Campeche | ||||
Pittsburgh Pirates | ||||
Rieleros de Aguascalientes | ||||
Rojos del Águila de Veracruz | ||||
SK Wyverns | ||||
Saitama Seibu Lions | ||||
Samsung Lions | ||||
San Diego Padres | ||||
San Francisco Giants | ||||
Saraperos de Saltillo | ||||
Seattle Mariners | ||||
Shanghai Golden Eagles | ||||
Sichuan Dragons | ||||
St. Louis Cardinals | ||||
Sultanes de Monterrey | ||||
Sydney Blue Sox | ||||
Tampa Bay Rays | ||||
Texas Rangers | ||||
Tianjin Lions | ||||
Tigres de Quintana Roo | ||||
Tohoku Rakuten Golden Eagles | ||||
Tokyo Yakult Swallows | ||||
Toronto Blue Jays | ||||
Toros de Tijuana | ||||
Uni-President 7-Eleven Lions aka Uni-President Lions | ||||
Vaqueros Laguna | ||||
Washington Nationals | ||||
Yokohama DeNA BayStars aka Yokohama BayStars | ||||
Yomiuri Giants | ||||
dmedia T-REX | ||||
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 = borderwidth or ''
if (borderwidth ~= '') then
border = 'border:' .. borderwidth .. 'px solid #' .. stripwhitespace(colors[bd]) .. ';'
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