local p = {}
-- Load theload configuration from a separate file
local cfgconfig = mw.loadData('Module:CareerList/config')
-- Functionhelper function to buildget athe rowconfig ofvalue thefor a tablesite
local function buildRowgetConfigValue(site, id, alias, notes, indexkey)
return config[site] and config[site][key]
-- Determine the row color
end
local color
if site == 'Website' then
-- helper function to format the alias or notes field
color = (index % 2 == 1) and cfg.colors.website1 or cfg.colors.website2
local function formatText(text)
else
return text ~= '' and text or 'N/A'
color = (index % 2 == 1) and cfg.colors.studio1 or cfg.colors.studio2
end
-- helper function to -- Buildgenerate the table row
local function generateTableRow(site, id, alias, notes, rowColor)
local row = string.format( ▼
local siteColor = getConfigValue(site, 'color')
cfg.rowTemplate,
local cellColor = site == 'Website' and '#E7E7E7' or '#DADADA'
local tableHtmlrowStyle = string.format( cfg.tableTemplate'background-color: %s;', tableContentrowColor) ▼
site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg,
local siteStyle = string.format('background-color: %s;', siteColor or cellColor)
site,
local siteName = cfgstring.siteUrls[upper(site][1],)
local url = cfg.siteUrls[getConfigValue(site][2], 'url'):gsub('%$1', id),
▲ local row =return string.format( [[
alias == '' and mw.title.getCurrentTitle().text or alias, ▼
notes<tr style== '' and 'N/A' or notes"%s">
<td style="%s">%s</td>
)
<td style="%s"><a href="%s">%s</a></td>
<td style="%s">%s</td>
return row
<td style="%s">%s</td>
]], rowStyle, siteStyle, siteName, cellColor, url, site, cellColor, alias, cellColor, formatText(notes))
end
-- Mainmain function to generate the table
function p.main(frame)
-- Get the template parameters
local args = frame.args
local noteslist = params[4]args.list or '' ▼
--local Getrows the= list parameter''
local listrowColor = args.list or error('List not specified#FFFFFF')
for row in mw.text.gsplit(list, '%{%{CareerList') do
local params = mw.text.split(row, ' %s*| %s*') ▼
-- Split the list into rows
local site = params[ 12] or ''▼
local rows = mw.text.split(list, '%s*' .. cfg.rowSeparator .. '%s*')
local id = params[ 23] or ''▼
▲ local alias == ''params[4] andor mw.title.getCurrentTitle().text or alias,
-- Build the table
local indexnotes = 1params[5] or ''
tableContentrows = tableContentrows .. buildRowgenerateTableRow(site, id, alias, notes, indexrowColor) ▼
local tableContent = ''
rowColor = rowColor == '#FFFFFF' and '#F3F3F3' or '#FFFFFF'
for _, row in ipairs(rows) do
▲ local params = mw.text.split(row, '%s*|%s*')
if #params >= 3 then
local alias = params[3]
▲ local notes = params[4] or ''
▲ tableContent = tableContent .. buildRow(site, id, alias, notes, index)
index = index + 1
end
end
local tableStyle = 'background-color: #F2F2F2; width: 100%;'
return string.format('<table style="%s">%s</table>', tableStyle, rows)
-- Build the table
▲ local tableHtml = string.format(cfg.tableTemplate, tableContent)
return tableHtml
end
|