Content deleted Content added
No edit summary
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1:
local p = {}
-- загрузка конфигурационного файла
local config = require('Module:CareerList/config')
 
-- Функция для создания таблицы
-- функция определения ссылки на сайт
local function getSiteLinkp.makeTableTop(site, id)
local headerRow = mw.html.create('tr')
-- проверка наличия значения в конфигурационном файле
:node(mw.html.create('th'):wikitext('site'))
if not config.sites[site] then
:node(mw.html.create('th'):wikitext('id'))
error(string.format('Сайт %s не найден в конфигурационном файле', site))
:node(mw.html.create('th'):wikitext('alias'))
end
:node(mw.html.create('th'):wikitext('notes'))
:done()
-- замена переменной $1 на значение id
 
local url = config.sites[site].url:gsub('%$1', id)
return mw.html.create('table')
:css('width', '100%')
-- возврат ссылки
:node(headerRow)
return string.format('[[%s|%s]]', url, site)
:done()
end
 
-- функцияФункция для создания ячейки таблицы
local function p.makeCell(site, id, aliascellType, notesargs)
local function getColor(index)
-- определение цвета фона ячейки 1
return ((index or 0) % 2 == 0) and '#F3F3F3' or '#FFFFFF'
local bg
end
if site == 'Studio' then
 
bg = '#DADADA'
local function getBackground(site)
elseif site == 'Website' then
local config = mw.loadData('Module:CareerList/config')
bg = '#E7E7E7'
local color = (cellType == 'Studio') and '#DADADA' or '#E7E7E7'
else
return config[site] and color or '#FFFFFF'
error(string.format('Значение site (%s) должно быть "Studio" или "Website"', site))
end
 
local function getAlias(alias, title)
-- определение значения alias
if not alias or alias == '' then
return 'N/A'
alias = config.sites[site].name
end else
return alias
end
-- определение значения notes
end
if notes == '' then
 
notes = 'N/A'
local function getNotes(notes)
end
if not notes or notes == '' then
return 'N/A'
-- создание ячейки
else
local cell = string.format('|-\n| style="background-color: %s;" | %s\n| %s\n| %s\n| %s', bg, site, getSiteLink(site, id), alias, notes)
return notes
return cell end
end
 
if not args.site then
return mw.html.create('tr')
: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
local id = args.id or ''
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)
:css('padding', '8px')
:wikitext(p.getSiteLink(site))
:done()
 
local idCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(id)
:done()
 
local aliasCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(aliasCell)
:done()
 
local notesCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(notesCell)
:done()
 
return mw.html.create('tr')
:css('background-color', getColor(args.rowIndex))
:node(cell)
:node(idCell)
:node(aliasCell)
:node(notesCell)
:done()
end
-- Функция для определения ссылки на сайт
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
return '<strong class="error">Error: </strong>Site parameter is required'
else
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
 
-- Главная функция модуля
function p.main(frame)
local tableTop = p.makeTableTop()
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
 
return p
-- экспорт функций
return {
getSiteLink = getSiteLink,
makeCell = makeCell
}