Module:CareerList
Documentation for this module may be created at Module:CareerList/doc
local p = {}
-- Load the configuration file
local cfg = mw.loadData('Module:CareerList/config')
-- Function to build a row of the table
function buildRow(site, id, alias, notes, index)
-- Determine the row color
local color
if site == 'Website' then
color = (index % 2 == 1) and cfg.colors.website1 or cfg.colors.website2
else
color = (index % 2 == 1) and cfg.colors.studio1 or cfg.colors.studio2
end
-- Build the row
local row = string.format(
cfg.rowTemplate,
color,
site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg,
site,
cfg.siteUrls[site][1],
cfg.siteUrls[site][2]:gsub('$1', id),
alias == '' and mw.title.getCurrentTitle().text or alias,
notes == '' and 'N/A' or notes
)
return row
end
-- Main function
function p.main(frame)
-- Get the template parameters
local args = frame.args
-- Get the list parameter
local list = args.list or error('List not specified')
-- Split the list into rows
local rows = mw.text.split(list, '%s*' .. cfg.rowSeparator .. '%s*')
-- Build the table
local index = 1
local tableContent = ''
for _, row in ipairs(rows) do
local params = mw.text.split(row, '%s*|%s*')
if #params >= 3 then
local site = params[1]
local id = params[2]
local alias = params[3]
local notes = params[4] or ''
tableContent = tableContent .. buildRow(site, id, alias, notes, index)
index = index + 1
end
end
-- Build the table
local tableHtml = string.format(cfg.tableTemplate, tableContent)
return tableHtml
end
return p