Content deleted Content added
No edit summary
No edit summary
 
(21 intermediate revisions by 2 users not shown)
Line 1:
local p = {}
 
-- Функция для получениясоздания конфигурации по сайтутаблицы
local function getSiteConfigp.makeTableTop(site)
local configheaderRow = mw.loadDatahtml.create('Module:CareerList/configtr')[site:lower()]
:node(mw.html.create('th'):wikitext('site'))
if not config then
:node(mw.html.create('th'):wikitext('id'))
error(string.format('Не найдена конфигурация для сайта "%s"', site))
:node(mw.html.create('th'):wikitext('alias'))
:node(mw.html.create('th'):wikitext('notes'))
:done()
 
return mw.html.create('table')
:css('width', '100%')
:node(headerRow)
:done()
end
 
-- Функция для создания ячейки таблицы
function p.makeCell(cellType, args)
local function getColor(index)
return ((index or 0) % 2 == 0) and '#F3F3F3' or '#FFFFFF'
end
 
local function getBackground(site)
local config = mw.loadData('Module:CareerList/config')
local color = (cellType == 'Studio') and '#DADADA' or '#E7E7E7'
return config[site] and color or '#FFFFFF'
end
 
local function getAlias(alias, title)
if not alias or alias == '' then
return 'N/A'
else
return alias
end
return config
end
 
local function getNotes(notes)
-- Функция для генерации ссылки по конфигурации
if not notes or notes == '' then
local function generateLink(config, id)
return config.url:gsub('%$1N/A', id)
else
return notes
end
end
 
if not args.site then
function p.main(frame)
return mw.html.create('tr')
local args = frame:getParent().args
:css('background-color', getColor(args.rowIndex))
:node(mw.html.create('td'):attr('colspan', '4'):wikitext('Invalid arguments. Please see documentation for correct usage.'))
:done()
end
 
local site = args.site or mw.title.getCurrentTitle().text
-- Проверяем передан ли параметр list
local listid = args.listid or error('Не задан список')
local alias = getAlias(args.alias, site)
local notes = getNotes(args.notes)
local background = getBackground(site)
 
local cell = mw.html.create('td')
-- Разбиваем список на отдельные строки
:css('background-color', background)
local items = mw.text.split(list, '%s*{{CareerList%s*|')
:css('padding', '8px')
:wikitext(p.getSiteLink(site))
:done()
 
local idCell = mw.html.create('td')
-- Генерируем HTML-таблицу
:css('background-color', background)
local html = '<table class="wikitable CareerListTable">\n'
:css('padding', '8px')
html = html .. '<tr style="background-color:#F2F2F2;">\n'
:wikitext(id)
html = html .. '<th style="text-align:left;">Website/Studio</th>\n'
:done()
html = html .. '<th style="text-align:left;">Site</th>\n'
html = html .. '<th style="text-align:left;">ID</th>\n'
html = html .. '<th style="text-align:left;">Alias</th>\n'
html = html .. '<th style="text-align:left;">Notes</th>\n'
html = html .. '</tr>\n'
 
local aliasCell = mw.html.create('td')
-- Перебираем каждый элемент списка
:css('background-color', background)
local i = 1
for _, item in ipairs:css(items)'padding', do'8px')
if item ~= '' then:wikitext(aliasCell)
:done()
local itemArgs = mw.text.split(item, '%|')
local site = mw.text.trim(itemArgs[1] or '')
local id = mw.text.trim(itemArgs[2] or '')
local alias = mw.text.trim(itemArgs[3] or '')
local notes = mw.text.trim(itemArgs[4] or '')
 
local notesCell = mw.html.create('td')
-- Получаем конфигурацию для сайта
:css('background-color', background)
local config = getSiteConfig(site)
:css('padding', '8px')
:wikitext(notesCell)
:done()
 
return mw.html.create('tr')
-- Генерируем HTML-строку для текущего элемента
local rowHtml = :css('<tr style="background-color:', getColor(args..(i%2==0 and '#F3F3F3' or '#FFFFFF'rowIndex))..';">\n'
:node(cell)
rowHtml = rowHtml .. '<td style="background-color:'..(config.type == 'Studio' and '#DADADA' or '#E7E7E7')..';">'..config.type..'</td>\n'
:node(idCell)
rowHtml = rowHtml .. '<td><a href="'..generateLink(config, id)..'">'..config.name..'</a></td>\n'
:node(aliasCell)
rowHtml = rowHtml .. '<td>'..id..'</td>\n'
:node(notesCell)
rowHtml = rowHtml .. '<td>'..(alias ~= '' and alias or config.name)..'</td>\n'
:done()
rowHtml = rowHtml .. '<td>'..(notes ~= '' and notes or 'N/A')..'</td>\n'
end
rowHtml = rowHtml .. '</tr>\n'
-- Функция для определения ссылки на сайт
function p.getSiteLink(site)
local config = mw.loadData('Module:CareerList/config')
site = site:lower()
if config[site] then
local url = config[site].url
local id = mw.text.encode(site.id)
return string.format('[%s %s]', url:gsub('$1', id), site)
else
return site
end
end
 
-- Функция для обработки аргументов
function p.processArgs(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:CareerList'
})
local site = args[1] or ''
local id = args[2] or ''
local alias = args[3] or ''
local notes = args[4] or ''
 
if site == '' then
html = html .. rowHtml
return '<strong class="error">Error: </strong>Site parameter is required'
i = i + 1
else
end
site = site:lower()
if not mw.loadData('Module:CareerList/config')[site] then
return '<strong class="error">Error: </strong>Invalid site specified'
else
return p.makeCell(site, id, alias, notes)
end
end
end
 
-- Главная функция модуля
html = html .. '</table>'
function p.main(frame)
 
local tableTop = p.makeTableTop()
return html
local tableRows = ''
for i = 1, 999 do
local result = p.processArgs(frame:getParent())
if type(result) == 'string' then
return result
elseif not result then
break
else
tableRows = tableRows .. tostring(result)
end
end
return tostring(tableTop) .. tableRows .. '</table>'
end