Module:NFL Draft
Jump to navigation
Jump to search
File:Lua-Logo.svg | This module depends on the following other modules: |
Implements Template:NFLDraft-row, Template:NFLDraft-header and Template:NFLDraft-footer.
-- this module implements -- [[Template:NFLDraft-row]] -- [[Template:NFLDraft-header]] -- [[Template:NFLDraft-footer]] local p = {} local afbpositions = require('Module:American football positions')._main local yesno = require('Module:Yesno') local row_colors = { ["compensatory"] = "d9e9f9", ["supplemental"] = "ffdddd", ["expansion"] = "a9f5d0", ["resolution"] = "ccf9cc" } local doubledagger = "[[File:Double-dagger-14-plain.png|alt=double-dagger|link=]]" local function anchor(value) if value and value ~= '' then return '<span class="anchor" id="' .. value .. '"></span>' end return '' end local function sortname(first, last, link, nolink) last = last or '' first = first or '' link = link or '' local name = first .. ' ' .. last if not (nolink or (first == '-') or (last == '-')) then if link ~= '' then name = '[[' .. link .. '|' .. name .. ']]' else name = '[[' .. name .. ']]' end end name = '<span class=vcard><span class=fn>' .. name .. '</span></span>' return '<span data-sort-value="' .. mw.text.encode(last .. ',' .. first) .. ">" .. name .. '</span>' end local function get_round_color(round, numrounds) -- make sure numbers are within bounds round = tonumber(round) or -1 numrounds = tonumber(numrounds) or 7 numrounds = numrounds < 7 and 7 or numrounds numrounds = numrounds > 32 and 32 or numrounds -- linear color scale from F00 to F0A local c = {"F00", "F30", "F50", "F80", "FB0", "FE0", "FF0", "CF0", "9F0", "6F0", "4F0", "1F0", "0F1", "0F4", "0F6", "0F9", "0FC", "0FF", "0EF", "0BF", "08F", "05F", "03F", "00F", "20F", "50F", "70F", "A0F", "D0F", "F0F", "F0D", "F0A"} -- affine map from [1, numrounds] to [1, #c] local r = math.floor(1.5 + (round - 1) * (#c - 1) / (numrounds - 1)) return c[r] or "fff" end function p._row(args) local rowtype = 'none' for k,v in ipairs({'resolution', 'expansion', 'supplemental', 'compensatory'}) do if yesno(v) then rowtype = v end end local rowcolor = row_colors[rowtype] local root = {} local txt = '' table.insert(root,'|-' .. (rowcolor and 'style="background:#' .. rowcolor .. '"' or '')) if not yesno(args['undrafted']) then local pickstyle = 'text-align:center;' table.insert(root,'|style="background:#' .. get_round_color(args['round'], args['numberofrounds']) .. '"|') txt = (args['round'] or '{{{round}}}') if yesno(args['firstpickinround']) then txt = txt .. anchor('Round_' .. (args['round'] or '')) end if yesno(args['compensatory']) then txt = '|style="text-align:center;font-weight:bold;"| ' .. txt .. '*' pickstyle = pickstyle .. 'background-color:unset;' elseif yesno(args['supplemental']) then txt = '|style="text-align:center;font-weight:bold;"| ' .. txt .. '^' pickstyle = pickstyle .. 'background-color:unset;' elseif yesno(args['expansion']) then txt = '|style="text-align:center;font-weight:bold;"| ' .. txt .. '¤' pickstyle = pickstyle .. 'background-color:unset;' elseif yesno(args['resolution']) then txt = '|style="text-align:center;font-weight:bold;"| ' .. txt .. '×' pickstyle = pickstyle .. 'background-color:unset;' else txt = '! ' .. txt end table.insert(root,txt) txt = args['picknum'] or '{{{picknum}}}' if tonumber(txt) == 1 then txt = '[[List of first overall National Football League draft picks|1]]' elseif tonumber(txt) == 2 then txt = '[[List of second overall National Football League draft picks|1]]' elseif yesno(args['lastpick']) then txt = '[[Mr. Irrelevant|' .. txt ']]' end txt = anchor('Pick_' .. (args['picknum'] or '')) .. txt table.insert(root,'!scope=row style="font-weight:bold;' .. pickstyle .. '"|' .. txt) end txt = args['team'] or '{{{team}}}' if args['draftyear'] then txt = '[[' .. args['draftyear'] .. ' ' .. (args['teamdab'] or txt) .. ' season|' .. txt .. ']]' elseif args['teamdab'] then txt = '[[' .. args['teamdab'] .. '|' .. args['team'] .. ']]' end table.insert(root,'| ' .. txt) txt = '' if args['last'] then local style = '' local name = sortname(args['first'], args['last'], args['dab'], (args['playerpageexists'] == 'no') and 1 or nil) .. (yesno(args['hof']) and doubledagger or '') .. (yesno(args['probowl']) and '<sup>†</sup>' or '') if yesno(args['hof']) then style = 'style="background:#FFCC00"|' elseif yesno(args['probowl']) then style = 'style="background:#faecc8"|' end txt = style .. name end table.insert(root,'|' .. txt) txt = '' if args['position'] then txt = afbpositions(args['position'], false) if args['position2'] then txt = txt .. '/' .. afbpositions(args['position2'], false) end end table.insert(root,'| ' .. txt) txt = '' if args['college'] and args['college']:lower() ~= 'university' then if args['collegelink'] then if yesno(args['cfb page exists']) then txt = '[[' .. (args['collegeyear'] or '{{{collegeyear}}}') .. ' ' .. (args['collegeteam'] or '') .. ' football team|' .. args['collegelink'] .. ']]' else txt = mw.getCurrentFrame():expandTemplate{ title = 'cfb link', args = { ['year'] = args['collegeyear'] or '{{{collegeyear}}}', ['team'] = args['collegeteam'] or '{{{collegeteam}}}', ['school'] = args['college'] or '{{{college}}}', ['title'] = args['collegelink'] or '{{{collegelink}}}' } } end else txt = '[[' .. args['college'] .. ']]' end end table.insert(root,'| ' .. txt) txt = '' if args['college'] and args['college']:lower() ~= 'university' then if args['conference'] then txt = args['conference'] else local cfbconf = require('Module:College football conference')._main txt = cfbconf(args['collegeyear'], args['college']) end txt = 'style="text-align:center"|' .. txt end table.insert(root,'|' .. txt) txt = '' if args['note'] then txt = '<small>' .. args['note'] .. '</small>' end table.insert(root,'|' .. txt) return table.concat(root, '\n') end local function abbr(a, d) return '<abbr title="' .. d .. '">' .. a .. '</abbr>' end function p._header(args) local root = {} local style = 'scope=col style="background:#A8BDEC;%s"' table.insert(root, '<span></span>\n{| class="wikitable sortable plainrowheaders" border="1"') if args['caption'] then table.insert(root, '|+ ' .. args['caption']) end table.insert(root, '|-') local cstyle = string.format(style,'width:3px;') local pstyle = string.format(style, '') local nstyle = string.format(style, args['noteswidth'] and 'width:' .. args['noteswidth'] .. ';' or '') local oteam if not yesno(args['undrafted']) then table.insert(root, '! ' .. cstyle .. ' class="unsortable" |') table.insert(root, '! ' .. pstyle .. ' | ' .. abbr('Rnd.', 'Draft round')) table.insert(root, '! ' .. pstyle .. ' | ' .. abbr('Pick No.', 'Overall selection number')) oteam = abbr('NFL team', 'Team which made selection') else oteam = abbr('Original NFL team', 'Team which signed the player after the draft') end table.insert(root, '! ' .. pstyle .. ' | ' .. oteam) table.insert(root, '! ' .. pstyle .. ' | Player') table.insert(root, '! ' .. pstyle .. ' | ' .. abbr('Pos.', 'Football position played')) table.insert(root, '! ' .. pstyle .. ' | ' .. abbr('College', 'Most recent college attended')) table.insert(root, '! ' .. pstyle .. ' | ' .. abbr('Conf.', 'Athletic conference of most recent college')) table.insert(root, '! ' .. nstyle .. ' class="unsortable" | Notes') table.insert(root, '|-') return table.concat(root, '\n') end function p._footer() return '|-\n|}' end function p.row(frame) local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame) return p._row(args) end function p.header(frame) local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame) return p._header(args) end function p.footer(frame) return p._footer() end return p