local p =
--------------- Exports ---------------
-- Used by function p.contestant_table(frame) return p._contestant_table(frame)end
-- Used by function p.progressTable(frame) return p._progressTable(frame)end
-- Used by function p.key(frame) return p._key(frame)end
------------------------- Utility Functions -------------------------function p._inTable(t, k) return (t[k] ~= nil)end
function p._sortRows(a,b) return a[1] > b[1] end
function p._revSortRows(a,b) return a[1] < b[1] end
p.colorMap =
------------------------ Contestant table ------------------------function p._contestant_table(frame) local templateFrame = frame:getParent local contestantData = p._getContestantData(templateFrame) ret = [=[ {| class="wikitable sortable" border="2" style="text-align:center;" |+ Contestants of ''All Stars 5'' and their backgrounds ! scope="col"| Contestant ! scope="col"| Age ! scope="col"| Hometown ! scope="col"| Original season(s) ! scope="col"| Original placement(s) ! scope="col"| Outcome ]=] for k, v in pairs(contestantData) do ret = ret .. p._bio_makeRow(contestantData[k]) end return ret .. "|}"end
function p._bio_makeRow(contestant) local rowTemplate = [=[ |- ! scope="row" rowspan="${NROWS}"|[[${NAME}]] |rowspan="$"|$ |rowspan="$"|$ ]=] if string.find(contestant['season'], 'All Stars') ~= nil then rowTemplate = rowTemplate .. "|All Stars $\n" contestant['season-num'] = string.match(contestant['season'], 'All Stars (%d+)') contestant['season'] = nil else rowTemplate = rowTemplate .. "|Season $\n" end rowTemplate = rowTemplate .. [=[ |<span data-sort-value="${PLACE-SORT}">${PLACE}</span> ]=] if contestant['outcome'] ~= nil then rowTemplate = rowTemplate .. '|rowspan="$"|$\n' if #tostring(contestant['outcome']) < 3 then contestant['outcome'] = p._makePlace(contestant['outcome']) end else rowTemplate = rowTemplate .. '|rowspan="$" style="background: #DDF; color: #2C2C2C; vertical-align: middle; text-align: center;" class="no table-no2"|TBA\n' end
if tonumber(contestant['nrows']) > 1 then rowTemplate = rowTemplate .. "|-\n" if string.find(contestant['season2'], 'All Stars') ~= nil then rowTemplate = rowTemplate .. "|All Stars $\n" contestant['season2-num'] = tostring(string.match(contestant['season2'], '%d+')) contestant['season2'] = nil else rowTemplate = rowTemplate .. "|Season $\n" end rowTemplate = rowTemplate .. '|
$\n' if contestant['place2-sort']function p._getContestant(k) return string.match(k, "contestant%-(%d+)")end
function p._getField(k) return string.match(k, "contestant%-%d+%-(.*)")end
function p._getContestantData(frame) local contestantData = for k, v in pairs(frame.args) do -- Read inputs and organize them by contestant if not p._inTable(contestantData, p._getContestant(k)) then contestantData[p._getContestant(k)] = end if p._getField(k) ~= nil then contestantData[p._getContestant(k)][p._getField(k)] = v else contestantData[p._getContestant(k)]["name"] = v end end for k, v in pairs(contestantData) do -- Final cleanup of the input before rendering table if not p._inTable(contestantData[k],"nrows") then contestantData[k]["nrows"] = 1 end if not p._inTable(contestantData[k],"place-sort") then if #tostring(contestantData[k]['place']) > 2 then place = string.match(contestantData[k]['place'],'(%d+)%D%D') else place = contestantData[k]['place'] end contestantData[k]["place-sort"] = p._makePlaceSort(place) end if #tostring(contestantData[k]['place']) < 3 then contestantData[k]['place'] = p._makePlace(contestantData[k]['place']) end end return contestantDataend
function p._makePlaceSort(place) if #tostring(place) < 2 then return '0'..place else return place endend
function p._makePlace(place) place = tonumber(place) if place
2 then return '2nd Place' elseif place
--------------------------------- Contestant progress table ---------------------------------function p._progressTable(frame) local templateFrame = frame:getParent local contestantData = ret = "" for i=1,50 do arg = templateFrame.args[i] if arg
1 then -- First in triplet is contestant name contestantData[arg] = elseif i % 3
nil then break end ret = ret .. rowList[i][2] end return ret .. "|}"end
function p._parseRanks(contestantData) local data = local high = 0 for k,v in pairs(contestantData) do data[k] = data[k][1] = mw.text.split(contestantData[k][1],',%s*') data[k][2] = mw.text.split(contestantData[k][2],',%s*') if #data[k][1] > high then high = #data[k][1] end end return data, highend function p._prog_makeRow(contestant, tableData, width) row = "|-\n! scope='row'| " .. contestant .. "\n" colors = tableData[1] labels = tableData[2] final = 0 for i=1,20 do -- If we've reached the end of the list... if colors[i]
--------------------------- Make key for colors ---------------------------function p._key(frame) local templateFrame = frame:getParent local args = templateFrame.args local ret = local order = mw.text.split(args.order,',%s*') args.order = nil local reverseIndex = for i,v in ipairs(order) do reverseIndex[v] = i end local rowTable = for k,v in pairs(args) do if k ~= 'order' then box = p._makeColorBox(k) text = v .. "\n" row = table.insert(rowTable,row) end end table.sort(rowTable,p._revSortRows) for i=1,20 do if rowTable[i]
function p._makeColorBox(key) local template = ':
' color = p.colorMap[key] return string.gsub(template, 'HEXCODE', color)endreturn p