-- This submodule is used to generate the complete color contrast table in-- the documentation for local contrast = local all_colors =
local contrast_mod = require("Module:Color contrast")
local function stripwhitespace(text) return string.match(text, "^%s*(.-)%s*$")end
local function preprocesscitation(text) text = mw.ustring.gsub(text, '%', '\"[%1 %2]\". %3. Retrieved %4.') text = mw.ustring.gsub(text, '%', '[%1 %2]. %3. Retrieved %4.') text = mw.ustring.gsub(text, '%', '\"[%2 %1]\". %3. Retrieved %4.') text = mw.ustring.gsub(text, '%', '[%2 %1]. %3. Retrieved %4.') text = mw.ustring.gsub(text, '%', '\"[%1 %2]\". Retrieved %3.') text = mw.ustring.gsub(text, '%', '[%1 %2]. Retrieved %3.') text = mw.ustring.gsub(text, '%', '\"[%2 %1]\". Retrieved %3.') text = mw.ustring.gsub(text, '%', '[%2 %1]. Retrieved %3.') return textend
local function get_colors(team, unknown) team = stripwhitespace(team or ) unknown = unknown or local use_default = local colors = nil if (team and use_default[string.lower(team)]) then colors = else colors = all_colors[team] if (colors and type(colors)
function contrast.get_colors(team) return get_colors(team)end
local function color_contrast_ratio(hex1, hex2) if(hex1 and hex2) then local r = contrast_mod._ratio if(r > 0) then r = (r > 1) and r or (1/r) r = math.floor(r * 100 + 0.5) / 100 return (r > 1) and r or (1/r) end end return end
function contrast._testtable(args) local teamlist = local aliaslist = local style = args['style'] local data_module = args['data'] or "Module:College color/data" all_colors = mw.loadData(data_module)
-- helper function local function table_row(t, c) local res = mw.html.create() if(c[1]) then res:tag('td'):wikitext(t) else res:tag('td'):wikitext(t .. '
ERROR') end for i=1,3 do res:tag('td') :css('background', c[i] and ('#' .. c[i]) or 'transparent') :wikitext(c[i] and or 'X') end for i=1,3 do local j = math.fmod(i,3) + 1 res:tag('td'):wikitext(color_contrast_ratio(c[i],c[j])) end res:tag('td'):wikitext(color_contrast_ratio(c[1],'FFFFFF')) res:tag('td'):wikitext(color_contrast_ratio(c[1],'000000')) local r = for k, v in pairs(c) do if (type(k)'string' and mw.ustring.match(k, '^ref')) then local rt = mw.ustring.gsub(v, '^%s*https?://(.*)', '%1') or rt = mw.ustring.gsub(rt, '^(.-)/.*', '%1') rt = mw.ustring.gsub(rt, '^www%.(.-)$', '%1') or rt r = r .. '[2] ' end end res:tag('td'):wikitext(r) return tostring(res) end
-- list of teams if(args and args[1]) then for k, team in pairs(args) do if type(k)
'string' then aliaslist[colors] = (aliaslist[colors] or ) .. '
aka ' .. team else table.insert(teamlist, team) end end table.sort(teamlist) table.insert(teamlist, 'Free agent') table.insert(teamlist, 'Retired') end -- build table local root = mw.html.create('table') 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') for i=1,3 do row:tag('th') :addClass('unsortable') :attr('rowspan',2) :wikitext(i) end row:tag('th') :attr('colspan', 5) :wikitext('Contrast') row:tag('th') :attr('rowspan',2) :wikitext('refs') row = root:tag('tr') for i=1,3 do local j = math.fmod(i,3) + 1 row:tag('th'):wikitext(i .. '/' .. j) end row:tag('th'):wikitext('1/w') row:tag('th'):wikitext('1/b') for k, team in pairs(teamlist) do row = root:tag('tr') row:wikitext(table_row(team .. (aliaslist[team] or ), get_colors(team))) end return tostring(root) .. ''end
function contrast._exampletable(frame, args, styletemplate) local teamlist = local style = args['style'] local data_module = args['data'] or "Module:College color/data" all_colors = mw.loadData(data_module) local function stripestyle(frame, in_args) return frame:expandTemplate end
-- list of teams if(args and args[1]) then for k, team in pairs(args) do if type(k)
function contrast.testtable(frame) return frame:preprocess(contrast._testtable(frame.args))end
function contrast.stripetable(frame) return contrast._exampletable(frame,frame.args, 'College stripe style')end
function contrast.header1table(frame) return contrast._exampletable(frame,frame.args, 'NCAA color cell')end
function contrast.header2table(frame) return contrast._exampletable(frame,frame.args, 'NCAA secondary color cell')end
return contrast