Difference between revisions of "Module:Ru Paul's Drag Race tables"
Jump to navigation
Jump to search
blackwiki>Wugapodes (support for two-time queens) |
blackwiki>Wugapodes (fix 2th place problem, allow raw input to ${OUTCOME}) |
||
| Line 16: | Line 16: | ||
local contestantData = {} | local contestantData = {} | ||
for k, v in pairs( frame.args ) do | 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 | end | ||
for k, v in pairs( contestantData ) do | for k, v in pairs( contestantData ) do | ||
| + | -- Final cleanup of the input before rendering table | ||
if not p._inTable(contestantData[k],"nrows") then | if not p._inTable(contestantData[k],"nrows") then | ||
contestantData[k]["nrows"] = 1 | contestantData[k]["nrows"] = 1 | ||
end | end | ||
if not p._inTable(contestantData[k],"place-sort") then | if not p._inTable(contestantData[k],"place-sort") then | ||
| − | contestantData[k][ | + | local place |
| + | if #tostring(contestantData[k]['place']) > 2 then | ||
| + | place = string.match(contestantData[k]['place'],'%d+%D%D') | ||
| + | else | ||
| + | place = p._makePlaceSort(contestantData[k]['place']) | ||
| + | end | ||
| + | contestantData[k]["place-sort"] = place | ||
end | end | ||
| − | + | if #tostring(contestantData[k]['place']) < 3 then | |
| + | contestantData[k]['place'] = p._makePlace(contestantData[k]['place']) | ||
| + | end | ||
end | end | ||
return contestantData | return contestantData | ||
| Line 45: | Line 55: | ||
|[[RuPaul's Drag Race (season ${SEASON})|Season ${SEASON}]] | |[[RuPaul's Drag Race (season ${SEASON})|Season ${SEASON}]] | ||
|<span data-sort-value="${PLACE-SORT}">${PLACE}</span> | |<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 | if tonumber(contestant['nrows']) > 1 then | ||
| Line 75: | Line 92: | ||
function p._makePlace( place ) | function p._makePlace( place ) | ||
| + | local place = tonumber(place) | ||
if place == 1 then | if place == 1 then | ||
return '1st Place' | return '1st Place' | ||
Revision as of 02:51, 11 July 2020
| File:Alpha lowercase.svg | 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
local place
if #tostring(contestantData[k]['place']) > 2 then
place = string.match(contestantData[k]['place'],'%d+%D%D')
else
place = p._makePlaceSort(contestantData[k]['place'])
end
contestantData[k]["place-sort"] = 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}
|[[RuPaul's Drag Race (season ${SEASON})|Season ${SEASON}]]
|<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 .. [=[
|-
|[[RuPaul's Drag Race (season ${SEASON2})|Season ${SEASON2}]]
|<span data-sort-value="${PLACE2-SORT}">${PLACE2}</span>
]=]
if contestant['place2-sort'] == nil then
contestant['place2-sort'] = p._makePlaceSort(contestant['place2'])
end
contestant['place2'] = p._makePlace(contestant['place2'])
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 )
local 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