Difference between revisions of "Module:Ru Paul's Drag Race tables"
Jump to navigation
Jump to search
blackwiki>Wugapodes (Basic table) |
blackwiki>Wugapodes (age param, fix issue with sort key) |
||
| Line 29: | Line 29: | ||
contestantData[k]["nrows"] = 1 | contestantData[k]["nrows"] = 1 | ||
end | end | ||
| + | if not p._inTable(contestantData[k],"place-sort") then | ||
| + | contestantData[k]["place-sort"] = p._makePlaceSort(contestantData[k]['place']) | ||
| + | end | ||
| + | contestantData[k]['place'] = p._makePlace(contestantData[k]['place']) | ||
end | end | ||
return contestantData | return contestantData | ||
| Line 37: | Line 41: | ||
|- | |- | ||
! scope="row" rowspan="${NROWS}"|[[${NAME}]] | ! scope="row" rowspan="${NROWS}"|[[${NAME}]] | ||
| − | |rowspan="${NROWS}"| | + | |rowspan="${NROWS}"|${AGE} |
|rowspan="${NROWS}"|${HOMETOWN} | |rowspan="${NROWS}"|${HOMETOWN} | ||
|[[RuPaul's Drag Race (season ${SEASON})|Season ${SEASON}]] | |[[RuPaul's Drag Race (season ${SEASON})|Season ${SEASON}]] | ||
| Line 44: | Line 48: | ||
]=] | ]=] | ||
for k, v in pairs( contestant ) do | for k, v in pairs( contestant ) do | ||
| − | rowTemplate = string.gsub(rowTemplate,"${"..k:upper().."}",contestant[k]) | + | mw.log(k:upper()) |
| + | rowTemplate = string.gsub(rowTemplate,"${"..k:upper():gsub('%-','%%-').."}",contestant[k]) | ||
end | end | ||
return rowTemplate | return rowTemplate | ||
| + | end | ||
| + | |||
| + | function p._makePlaceSort( place ) | ||
| + | if #tostring(place) < 2 then | ||
| + | return '0'..place | ||
| + | else | ||
| + | return place | ||
| + | end | ||
| + | end | ||
| + | |||
| + | function p._makePlace( 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 | end | ||
Revision as of 01:49, 11 July 2020
| 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
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
if not p._inTable(contestantData[k],"nrows") then
contestantData[k]["nrows"] = 1
end
if not p._inTable(contestantData[k],"place-sort") then
contestantData[k]["place-sort"] = p._makePlaceSort(contestantData[k]['place'])
end
contestantData[k]['place'] = p._makePlace(contestantData[k]['place'])
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>
|rowspan="${NROWS}" style="background: #DDF; color: #2C2C2C; vertical-align: middle; text-align: center;" class="no table-no2"|TBA
]=]
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 )
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