Difference between revisions of "Module:Sports career"
Jump to navigation
Jump to search
blackwiki>Frietjes |
m (9 revisions imported) |
||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 9: | Line 9: | ||
local coach = {} | local coach = {} | ||
local pargs = frame:getParent().args | local pargs = frame:getParent().args | ||
| + | local tracking = '' | ||
local iargs = {} | local iargs = {} | ||
| + | local pmax = tonumber(frame.args['pmax'] or '40') or 40 | ||
| + | local cmax = tonumber(frame.args['cmax'] or '30') or 30 | ||
for k,v in pairs(pargs) do | for k,v in pairs(pargs) do | ||
if type(k) == 'string' and isnotempty(v) then | if type(k) == 'string' and isnotempty(v) then | ||
| Line 22: | Line 25: | ||
end | end | ||
| − | table.sort(player, function (a, b) return a[1] | + | table.sort(player, function (a, b) return a[1] < b[1] end) |
| − | table.sort(coach, function (a, b) return a[1] | + | table.sort(coach, function (a, b) return a[1] < b[1] end) |
local i = 1 | local i = 1 | ||
| Line 50: | Line 53: | ||
iargs['headerstyle'] = 'line-height: 1.2em;text-align: left;' .. (frame.args['headerstyle'] or '') | iargs['headerstyle'] = 'line-height: 1.2em;text-align: left;' .. (frame.args['headerstyle'] or '') | ||
iargs['datastyle'] = 'line-height: 1.2em;text-align: left;' .. (frame.args['teamstyle'] or '') | iargs['datastyle'] = 'line-height: 1.2em;text-align: left;' .. (frame.args['teamstyle'] or '') | ||
| − | + | if #player > pmax then | |
| − | + | tracking = tracking .. (frame.args['pmaxcat'] or '') | |
| + | end | ||
| + | if #coach > cmax then | ||
| + | tracking = tracking .. (frame.args['cmaxcat'] or '') | ||
| + | end | ||
| + | return (frame.args['title'] or 'Career history') .. require('Module:Infobox').infobox(iargs) .. tracking | ||
end | end | ||
| − | return | + | return tracking |
end | end | ||
return p | return p | ||
Latest revision as of 07:30, 28 September 2020
Renders the "Career history" section of Template:Infobox baseball biography
local p = {}
local function isnotempty(s)
return s and s:match('%S')
end
function p.main(frame)
local player = {}
local coach = {}
local pargs = frame:getParent().args
local tracking = ''
local iargs = {}
local pmax = tonumber(frame.args['pmax'] or '40') or 40
local cmax = tonumber(frame.args['cmax'] or '30') or 30
for k,v in pairs(pargs) do
if type(k) == 'string' and isnotempty(v) then
if k:match('^team%d%d*$') then
local num = mw.ustring.gsub(k,'^team(%d%d*)$','%1')
table.insert(player, {tonumber(num) or 0, pargs['years' .. num] or '', v})
elseif k:match('^cteam%d%d*$') then
local num = mw.ustring.gsub(k,'^cteam(%d%d*)$','%1')
table.insert(coach, {tonumber(num) or 0, pargs['cyears' .. num] or '', v})
end
end
end
table.sort(player, function (a, b) return a[1] < b[1] end)
table.sort(coach, function (a, b) return a[1] < b[1] end)
local i = 1
if #player > 0 then
iargs['header' .. i] = frame.args['pheader'] or 'As player:'
i = i + 1
for k,v in ipairs(player) do
if v[2] ~= '' then iargs['label' .. i] = v[2] end
if v[3] ~= '' then iargs['data' .. i] = v[3] end
i = i + 1
end
end
if #coach > 0 then
iargs['header' .. i] = frame.args['cheader'] or 'As coach:'
i = i + 1
for k,v in ipairs(coach) do
if v[2] ~= '' then iargs['label' .. i] = v[2] end
if v[3] ~= '' then iargs['data' .. i] = v[3] end
i = i + 1
end
end
if i > 1 then
iargs['child'] = 'yes'
iargs['labelstyle'] = 'font-weight: normal;' .. (frame.args['yearstyle'] or '')
iargs['headerstyle'] = 'line-height: 1.2em;text-align: left;' .. (frame.args['headerstyle'] or '')
iargs['datastyle'] = 'line-height: 1.2em;text-align: left;' .. (frame.args['teamstyle'] or '')
if #player > pmax then
tracking = tracking .. (frame.args['pmaxcat'] or '')
end
if #coach > cmax then
tracking = tracking .. (frame.args['cmaxcat'] or '')
end
return (frame.args['title'] or 'Career history') .. require('Module:Infobox').infobox(iargs) .. tracking
end
return tracking
end
return p