Module:CareerList: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
PeaceDeadC (talk | contribs) No edit summary |
PeaceDeadC (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
-- |
-- load configuration from a separate file |
||
local |
local config = mw.loadData('Module:CareerList/config') |
||
-- |
-- helper function to get the config value for a site |
||
function |
local function getConfigValue(site, key) |
||
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 generate the table row |
|||
local function generateTableRow(site, id, alias, notes, rowColor) |
|||
| ⚫ | |||
local siteColor = getConfigValue(site, 'color') |
|||
cfg.rowTemplate, |
|||
local cellColor = site == 'Website' and '#E7E7E7' or '#DADADA' |
|||
| ⚫ | |||
| ⚫ | |||
site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg, |
|||
local siteStyle = string.format('background-color: %s;', siteColor or cellColor) |
|||
site, |
|||
local siteName = string.upper(site) |
|||
local url = getConfigValue(site, 'url'):gsub('%$1', id) |
|||
| ⚫ | |||
| ⚫ | |||
<tr style="%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 |
end |
||
-- |
-- main function to generate the table |
||
function p.main(frame) |
function p.main(frame) |
||
-- Get the template parameters |
|||
local args = frame.args |
local args = frame.args |
||
| ⚫ | |||
local rows = '' |
|||
local |
local rowColor = '#FFFFFF' |
||
for row in mw.text.gsplit(list, '%{%{CareerList') do |
|||
| ⚫ | |||
-- Split the list into rows |
|||
| ⚫ | |||
local rows = mw.text.split(list, '%s*' .. cfg.rowSeparator .. '%s*') |
|||
| ⚫ | |||
| ⚫ | |||
-- Build the table |
|||
local |
local notes = params[5] or '' |
||
| ⚫ | |||
local tableContent = '' |
|||
rowColor = rowColor == '#FFFFFF' and '#F3F3F3' or '#FFFFFF' |
|||
for _, row in ipairs(rows) do |
|||
| ⚫ | |||
if #params >= 3 then |
|||
| ⚫ | |||
| ⚫ | |||
local alias = params[3] |
|||
| ⚫ | |||
| ⚫ | |||
index = index + 1 |
|||
end |
|||
end |
end |
||
local tableStyle = 'background-color: #F2F2F2; width: 100%;' |
|||
return string.format('<table style="%s">%s</table>', tableStyle, rows) |
|||
-- Build the table |
|||
| ⚫ | |||
return tableHtml |
|||
end |
end |
||
Revision as of 18:19, 12 March 2023
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