Module:CareerList
Jump to navigation
Jump to search
Documentation for this module may be created at Module:CareerList/doc
local p = {} -- load configuration from a separate file local config = mw.loadData('Module:CareerList/config') -- helper function to get the config value for a site local function getConfigValue(site, key) return config[site] and config[site][key] end -- helper function to format the alias or notes field local function formatText(text) return text ~= '' and text or 'N/A' end -- helper function to generate the table row local function generateTableRow(site, id, alias, notes, rowColor) local siteColor = getConfigValue(site, 'color') local cellColor = site == 'Website' and '#E7E7E7' or '#DADADA' local rowStyle = string.format('background-color: %s;', rowColor) local siteStyle = string.format('background-color: %s;', siteColor or cellColor) local siteName = string.upper(site) local url = getConfigValue(site, 'url'):gsub('%$1', id) return string.format([[ <tr style="%s"> <td style="%s">%s</td> <td style="%s"><a href="%s">%s</a></td> <td style="%s">%s</td> <td style="%s">%s</td> </tr> ]], rowStyle, siteStyle, siteName, cellColor, url, site, cellColor, alias, cellColor, formatText(notes)) end -- main function to generate the table function p.main(frame) local args = frame.args local list = args.list or '' local rows = '' local rowColor = '#FFFFFF' for row in mw.text.gsplit(list, '%{%{CareerList') do local params = mw.text.split(row, '|') local site = params[2] or '' local id = params[3] or '' local alias = params[4] or mw.title.getCurrentTitle().text local notes = params[5] or '' rows = rows .. generateTableRow(site, id, alias, notes, rowColor) rowColor = rowColor == '#FFFFFF' and '#F3F3F3' or '#FFFFFF' end local tableStyle = 'background-color: #F2F2F2; width: 100%;' return string.format('<table style="%s">%s</table>', tableStyle, rows) end return p