Content deleted Content added
No edit summary
No edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1:
local p = {}
 
-- Функция для создания таблицы
-- загрузка конфигурационного файла
function p.makeTableTop()
local cfg = mw.loadData('Module:CareerList/config')
local headerRow = mw.html.create('tr')
:node(mw.html.create('th'):wikitext('site'))
:node(mw.html.create('th'):wikitext('id'))
:node(mw.html.create('th'):wikitext('alias'))
:node(mw.html.create('th'):wikitext('notes'))
:done()
 
return mw.html.create('table')
-- функция для определения ссылки на сайт
:css('width', '100%')
local function getSiteLink(site, id)
:node(headerRow)
if cfg[site] then
return cfg[site].url :gsubdone('$1', id)
end
end
 
-- функцияФункция для создания ячейки таблицы
local function p.makeCell(rowcellType, bgargs)
local function getColor(index)
local cell = {}
return ((index or 0) % 2 == 0) and '#F3F3F3' or '#FFFFFF'
local site = row.site:lower()
end
 
local function getBackground(site)
-- Ячейка 1
local config = mw.loadData('Module:CareerList/config')
cell[1] = mw.html.create('td')
local color = (cellType == 'Studio') and '#DADADA' or '#E7E7E7'
:css('background-color', cfg[site].bg[bg])
return config[site] and color or '#FFFFFF'
:wikitext(cfg[site].text)
end
-- Ячейка 2
cell[2] = mw.html.create('td')
:wikitext('[[' .. row.site .. '|' .. row.alias .. ']]')
 
local function getAlias(alias, title)
-- Ячейка 3
if not alias or alias == '' then
cell[3] = mw.html.create('td')
return 'N/A'
:wikitext('[[' .. getSiteLink(site, row.id) .. '|' .. row.id .. ']]')
else
return alias
end
end
 
local function getNotes(notes)
-- Ячейка 4
if not notes or notes == '' then
cell[4] = mw.html.create('td')
return 'N/A'
:wikitext(row.alias == '' and mw.title.getCurrentTitle().text or row.alias)
else
return notes
end
end
 
if not args.site then
-- Ячейка 5
cell[5] = return mw.html.create('tdtr')
:css('background-color', getColor(args.rowIndex))
:wikitext(row.notes == '' and 'N/A' or row.notes)
: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
return cell
local id = args.id or ''
end
local alias = getAlias(args.alias, site)
local notes = getNotes(args.notes)
local background = getBackground(site)
 
local cell = mw.html.create('td')
function p.table(frame)
:css('background-color', background)
local list = frame.args.list
:css('padding', '8px')
if not list then
:wikitext(p.getSiteLink(site))
return ''
:done()
end
 
local idCell = mw.html.create('td')
-- Разбиение на строки
:css('background-color', background)
local rows = mw.text.split(list, '\n')
:css('padding', '8px')
local cells = {}
:wikitext(id)
:done()
 
local aliasCell = mw.html.create('td')
-- Создание ячеек
:css('background-color', background)
for i, row in ipairs(rows) do
local values = mw.text.split :css(row'padding', '|8px')
local bg = i % 2 == 0 and 2 or 1:wikitext(aliasCell)
cells[i] = makeCell :done({)
site = values[1],
id = values[2],
alias = values[3] or '',
notes = values[4] or ''
}, bg)
end
 
local notesCell = mw.html.create('td')
-- Создание таблицы
:css('background-color', background)
local html = mw.html.create()
:css('padding', '8px')
html
:tagwikitext('table'notesCell)
:done()
:addClass('wikitable careerlist')
:css('background-color', '#F2F2F2')
:css('width', '100%')
:css('max-width', 'none')
:css('table-layout', 'fixed')
:wikitext('\n|-')
 
return mw.html.create('tr')
-- Заголовок таблицы
:css('background-color', getColor(args.rowIndex))
for i, header in ipairs(cfg.header) do
html :node(cell)
:tagnode('th'idCell)
:cssnode('background-color', '#F2F2F2'aliasCell)
:wikitextnode(headernotesCell)
:done()
end
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'
for i, row in ipairs(cells) do
else
html:wikitext('\n|-')
forsite j,= cell in ipairssite:lower(row) do
if not mw.loadData('Module:CareerList/config')[site] then
html:addChild(cell)
return '<strong class="error">Error: </strong>Invalid site specified'
else
return p.makeCell(site, id, alias, notes)
end
end
end
 
-- Главная функция модуля
return tostring(html)
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