Module:CareerList: Difference between revisions

508 bytes removed ,  12 March 2023
no edit summary
No edit summary
No edit summary
local p = {}
 
-- Load the configuration file
function p.getSiteConfig(siteName)
local siteConfigcfg = mw.loadData('Module:CareerList/config')[siteName:lower()]
 
if not siteConfig then
-- Function to build a row of the table
error('Unknown site: ' .. siteName)
function buildRow(site, id, alias, notes, index)
-- Determine the row color
local color
if notsite siteConfig== '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
return siteConfig
-- Build the row
local tableHtmlrow = string.format([[
cfg.rowTemplate,
%scolor,
site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg,
</table>site,
cfg.siteUrls[site][1],
cfg.siteUrls[site][2]:gsub('$1', id),
alias == item.alias'' orand mw.title.getCurrentTitle().text or alias,
notes == item.notes'' orand 'N/A' or notes
)
return siteConfigrow
end
 
-- Main function
function p.makeLink(siteName, id)
function p.main(frame)
local siteConfig = p.getSiteConfig(siteName)
-- Get the template parameters
local url = siteConfig.url:gsub('%$1', id)
local args = frame:getParent().args
return string.format('[[%s|%s]]', url, siteName)
end
-- Get the list parameter
 
function p.getCellBgColor(siteName)
local siteConfig = p.getSiteConfig(siteName)
return siteConfig.type == 'studio' and '#DADADA' or '#E7E7E7'
end
 
function p.getTableHtml(args)
local list = args.list or error('List not specified')
local rows = {}
for-- _,Split itemthe in ipairs(list) dointo rows
local rows = mw.text.split(list, '%s*' .. cfg.rowSeparator .. '%s*')
local siteName, id, alias, notes
if type(item) == 'table' then
-- Build the table
siteName = item.site or error('Site not specified')
local index = 1
id = item.id or error('ID not specified')
local tableContent = ''
alias = item.alias or mw.title.getCurrentTitle().text
for _, row in ipairs(rows) do
notes = item.notes or 'N/A'
local params = mw.text.split(row, '%s*|%s*')
else
if #params >= 3 error('Invalid list item')then
local site = <td>%s</td>params[1]
local id = <td>%s</td>params[2]
local alias = params[3]
local notes = params[4] or ''
tableContent = tableContent .. buildRow(site, id, alias, notes, index)
</tr>index = index + 1
end
local link = p.makeLink(siteName, id)
local cellBgColor = p.getCellBgColor(siteName)
local rowBgColor = #rows % 2 == 0 and '#FFFFFF' or '#F3F3F3'
table.insert(rows, string.format([[
<tr style="background-color:%s;">
<td style="background-color:%s;">%s</td>
<td style="background-color:%s;">%s</td>
<td>%s</td>
<td>%s</td>
</tr>
]], rowBgColor, cellBgColor, siteName, cellBgColor, link, alias, notes))
end
local tableHtml = string.format([[
-- Build the table
<table style="width:100%%;border-collapse:collapse;">
local tableHtml = string.format(cfg.tableTemplate, tableContent)
<tr style="background-color:#F2F2F2;">
<th style="background-color:#F2F2F2;">Website/Studio</th>
<th style="background-color:#F2F2F2;">Link</th>
<th style="background-color:#F2F2F2;">Alias</th>
<th style="background-color:#F2F2F2;">Notes</th>
</tr>
%s
</table>
]], table.concat(rows))
return tableHtml
end
 
function p.main(frame)
local args = frame:getParent().args
return p.getTableHtml(args)
end