local p = {}
-- Load the configuration file
function p.getSiteConfig(siteName)
local siteConfigcfg = mw.loadData('Module:CareerList/config')[siteName:lower()]
-- 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
color = (index % 2 == 1) and cfg.colors.studio1 or cfg.colors.studio2
end
-- Build the row
local tableHtmlrow = string.format( [[▼
cfg.rowTemplate,
site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg,
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▼
)
end
-- Main function
function p.makeLink(siteName, id)
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*')
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)
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>
]], 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>
]], table.concat(rows))
return tableHtml
end
▲ local args = frame:getParent().args
return p.getTableHtml(args)
end
|