Module:CareerList: Difference between revisions

456 bytes removed ,  12 March 2023
no edit summary
No edit summary
No edit summary
local p = {}
 
function p.maingetSiteConfig(framesiteName)
local configsiteConfig = mw.loadData('МодульModule:CareerList/config')[siteName:lower()]
if not siteConfig then
local args = frame:getParent().args
error('Unknown site: ' .. siteName)
local list = args.list or ''
local output = {}
local site_colors = { -- цвета фона ячеек
website = '#E7E7E7',
studio = '#DADADA'
}
local color_count = 0
local row_color = {}
local function get_color()
color_count = color_count + 1
if color_count % 2 == 0 then
return '#F3F3F3'
else
return '#FFFFFF'
end
end
return siteConfig
local function get_site_color(site)
end
return site_colors[config[site].type]
 
end
local function get_site_namep.makeLink(sitesiteName, id)
local siteConfig = p.getSiteConfig(siteName)
return config[site].name
local url = siteConfig.url:gsub('%$1', id)
end
return string.format('[[%s|%s]]', url, siteName)
local function get_site_url(site, id)
end
local url = config[site].url
 
return mw.ustring.gsub(url, '%$1', id)
function p.getCellBgColor(siteName)
end
local functionsiteConfig get_alias(alias,= page_titlep.getSiteConfig(siteName)
return siteConfig.type == if alias'studio' and alias'#DADADA' ~=or '#E7E7E7' then
end
return alias
 
function p.getTableHtml(args)
local list = args.list or error('List not specified')
local rows = {}
for _, item in ipairs(list) do
local siteName, id, alias, notes
if type(item) == 'table' then
siteName = item.site or error('Site not specified')
id = item.id or error('ID not specified')
alias = item.alias or mw.title.getCurrentTitle().text
notes = item.notes or 'N/A'
else
returnerror('Invalid page_titlelist item')
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 functiontableHtml get_notes= string.format(notes)[[
<table style="width:100%%;border-collapse:collapse;">
if notes and notes ~= '' then
return<tr notesstyle="background-color:#F2F2F2;">
<th style="background-color:#F2F2F2;">Website/Studio</th>
else
return 'N <th style="background-color:#F2F2F2;">Link</A'th>
<th style="background-color:#F2F2F2;">Alias</th>
end
<th style="background-color:#F2F2F2;">Notes</th>
end
</tr>
for row in mw.ustring.gmatch(list, '%{%{CareerList%|(.+)%}%}') do
local cells = {} %s
</table>
local values = mw.text.split(row, '|')
]], table.concat(rows))
local site = mw.ustring.lower(values[2])
return tableHtml
local id = values[3]
end
local alias = values[4]
 
local notes = values[5]
function p.main(frame)
local page_title = mw.title.getCurrentTitle().text
local args = frame:getParent().args
if not config[site] then
return p.getTableHtml(args)
error('Invalid site: ' .. site)
end
local site_color = get_site_color(site)
table.insert(row_color, site_color)
table.insert(cells, '<td style="background-color:' .. site_color .. '; text-align:center;">' .. get_site_name(site) .. '</td>')
table.insert(cells, '<td style="background-color:' .. get_color() .. ';"><a href="' .. get_site_url(site, id) .. '">' .. get_alias(alias, page_title) .. '</a></td>')
table.insert(cells, '<td style="background-color:' .. get_color() .. ';">' .. get_notes(notes) .. '</td>')
table.insert(output, '<tr>' .. table.concat(cells) .. '</tr>')
end
local header = args.header or ''
local style = 'style="background-color:#F2F2F2;"'
local table_header = '<table class="wikitable" style="width:100%;">' ..
'<tr ' .. style .. '><th colspan="3">' .. header .. '</th></tr>' ..
'<tr ' .. style .. '><th>' .. config.website.name .. '</th><th>' .. config.studio.name .. '</th><th>Notes</th></tr>'
local table_footer = '</table>'
return table_header .. table.concat(output) .. table_footer
end