Module:Ru Paul's Drag Race tables
Appearance
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This module implements {{Drag Race contestant table}} and {{Drag Race progress table}}. See the code for more details.
local p = {} --p stands for package
function p._getContestant( k )
return string.match( k, "contestant%-(%d+)" )
end
function p._getField( k )
return string.match( k, "contestant%-%d+%-(.*)")
end
function p._inTable( t, k )
return (t[k] ~= nil)
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 contestantData
end
function p.makeRow( contestant )
local rowTemplate = [=[
|-
! scope="row" rowspan="${NROWS}"|[[${NAME}]]
|rowspan="${NROWS}"|${AGE}
|rowspan="${NROWS}"|${HOMETOWN}
]=]
if string.find(contestant['season'], 'All Stars') ~= nil then
rowTemplate = rowTemplate .. "|[[RuPaul's Drag Race All Stars (season ${SEASON-NUM})|''All Stars'' ${SEASON-NUM}]]\n"
contestant['season-num'] = string.match(contestant['season'], 'All Stars (%d+)')
contestant['season'] = nil
else
rowTemplate = rowTemplate .. "|[[RuPaul's Drag Race (season ${SEASON})|Season ${SEASON}]]\n"
end
rowTemplate = rowTemplate .. [=[
|<span data-sort-value="${PLACE-SORT}">${PLACE}</span>
]=]
if contestant['outcome'] ~= nil then
rowTemplate = rowTemplate .. '|rowspan="${NROWS}"|${OUTCOME}\n'
if #tostring(contestant['outcome']) < 3 then
contestant['outcome'] = p._makePlace(contestant['outcome'])
end
else
rowTemplate = rowTemplate .. '|rowspan="${NROWS}" 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 .. "|[[RuPaul's Drag Race All Stars (season ${SEASON2-NUM})|''All Stars'' ${SEASON2-NUM}]]\n"
contestant['season2-num'] = tostring(string.match(contestant['season2'], '%d+'))
contestant['season2'] = nil
else
rowTemplate = rowTemplate .. "|[[RuPaul's Drag Race (season ${SEASON2})|Season ${SEASON2}]]\n"
end
rowTemplate = rowTemplate .. '|<span data-sort-value="${PLACE2-SORT}">${PLACE2}</span>\n'
if contestant['place2-sort'] == nil then
contestant['place2-sort'] = p._makePlaceSort(contestant['place2'])
end
local place
if #tostring(contestant['place2']) > 2 then
place = string.match(contestant['place2'],'(%d+)%D%D')
else
place = contestant['place2']
end
contestant['place2'] = p._makePlace(place)
end
for k, v in pairs( contestant ) do
mw.log(k:upper())
rowTemplate = string.gsub(rowTemplate,"${"..k:upper():gsub('%-','%%-').."}",contestant[k])
end
return rowTemplate
end
function p._makePlaceSort( place )
if #tostring(place) < 2 then
return '0'..place
else
return place
end
end
function p._makePlace( place )
place = tonumber(place)
if place == 1 then
return '1st Place'
elseif place == 2 then
return '2nd Place'
elseif place == 3 then
return'3rd Place'
else
return place .. 'th Place'
end
end
function p.main( 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.makeRow(contestantData[k])
end
return ret .. "|}"
end
return p