Module:CareerList: Difference between revisions

Jump to navigation Jump to search
744 bytes removed ,  12 March 2023
no edit summary
No edit summary
No edit summary
local p = {}
 
function p.mainCareerList(frame)
-- load configuration from a separate file
local rowsargs = ''frame.args
local config = mw.loadData('Module:CareerList/config')
local siteNamesite = string.upperlower(args.site)
local id = params[3]args.id or ''
local alias = args.alias or args[1]
local notes = params[5]args.notes or 'N/A'
 
-- получаем конфигурацию сайтов
-- helper function to get the config value for a site
local configsites = mw.loadData('Module:CareerList/config')
local function getConfigValue(site, key)
returnlocal config[site]siteData and= configsites[site][key]
end
 
if not siteData then
-- helper function to format the alias or notes field
</tr>return ''
local function formatText(text)
end
return text ~= '' and text or 'N/A'
end
 
-- заменяем переменную $1 в URL на значение id
-- helper function to generate the table row
local url = siteData.url:gsub('%$1', id)
local function generateTableRow(site, id, alias, notes, rowColor)
 
local siteColor = getConfigValue(site, 'color')
-- формируем ссылку
local cellColor = site == 'Website' and '#E7E7E7' or '#DADADA'
local rowStylelink = string.format('background-color:[%s %s;]', rowColorurl, args.site)
 
local siteStyle = string.format('background-color: %s;', siteColor or cellColor)
-- формируем ячейки таблицы
local siteName = string.upper(site)
local urlcells = getConfigValue(site, 'url'):gsub('%$1', id){
siteData.label,
return string.format([[
<tr style="%s">link,
<td style="%s">%s</td>alias,
notes
<td style="%s"><a href="%s">%s</a></td>
end}
<td style="%s">%s</td>
 
<td style="%s">%s</td>
-- возвращаем сформированную строку таблицы
</tr>
return string.format('<table|-\n| style="%s"> || %s</table>', tableStyle|| %s || %s', rowsunpack(cells))
]], rowStyle, siteStyle, siteName, cellColor, url, site, cellColor, alias, cellColor, formatText(notes))
end
 
-- main function to generate the tablep.CareerListTop(frame)
function p.main(frame)
local args = frame.args
local list = args.list or ''
 
local rows = ''
return string.format([=[
local rowColor = '#FFFFFF'
{| class="wikitable"
for row in mw.text.gsplit(list, '%{%{CareerList') do
|+ %s
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 ''
%s]=], args.title or '', list)
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
 

Navigation menu