Content deleted Content added
No edit summary
No edit summary
 
(34 intermediate revisions by 2 users not shown)
Line 1:
local p = {}
 
-- Функция для создания таблицы
function p.main(frame)
function p.makeTableTop()
local config = mw.loadData('Модуль:CareerList/config')
local argsheaderRow = frame:getParentmw.html.create('tr').args
:node(mw.html.create('th'):wikitext('site'))
local list = args.list or ''
:node(mw.html.create('th'):wikitext('id'))
local output = {}
:node(mw.html.create('th'):wikitext('alias'))
local site_colors = { -- цвета фона ячеек
:node(mw.html.create('th'):wikitext('notes'))
website = '#E7E7E7',
studio = '#DADADA':done()
 
}
return mw.html.create('table')
local color_count = 0
:css('width', '100%')
local row_color = {}
local function get_color :node(headerRow)
color_count = color_count + 1:done()
end
if color_count % 2 == 0 then
 
return '#F3F3F3'
-- Функция для создания ячейки таблицы
else
function p.makeCell(cellType, args)
return '#FFFFFF'
local function getColor(index)
end
return ((index or 0) % 2 == 0) and '#F3F3F3' or '#FFFFFF'
end
 
local function get_site_color(site)
local function getBackground(site)
return site_colors[config[site].type]
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 get_site_name(site)
local function getAlias(alias, title)
return config[site].name
if not alias or alias == '' then
return 'N/A'
else
return alias
end
end
local function get_site_url(site, id)
 
local url = config[site].url
local function getNotes(notes)
return mw.ustring.gsub(url, '%$1', id)
if not notes or notes == '' then
return 'N/A'
else
return notes
end
end
local function get_alias(alias, page_title)
 
if alias and alias ~= '' then
if not args.site then
return alias
elsereturn mw.html.create('tr')
return:css('background-color', page_titlegetColor(args.rowIndex))
:node(mw.html.create('td'):attr('colspan', '4'):wikitext('Invalid arguments. Please see documentation for correct usage.'))
end
:done()
end
 
local function get_notes(notes)
local site = args.site or mw.title.getCurrentTitle().text
if notes and notes ~= '' then
local id = args.id or return notes''
local alias = getAlias(args.alias, site)
else
local notes = getNotes(args.notes)
return 'N/A'
local background = getBackground(site)
end
 
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
for row in mw.ustring.gmatch(list, '%{%{CareerList%|(.+)%}%}') do
end
local cells = {}
 
local values = mw.text.split(row, '|')
-- Главная функция модуля
local site = mw.ustring.lower(values[2])
function p.main(frame)
local id = values[3]
local aliastableTop = values[4]p.makeTableTop()
local notestableRows = values[5]''
for i = 1, 999 do
local page_title = mw.title.getCurrentTitle().text
local result = p.processArgs(frame:getParent())
if not config[site] then
if type(result) == 'string' then
error('Invalid site: ' .. site)
return result
end
elseif not result then
local site_color = get_site_color(site)
break
table.insert(row_color, site_color)
else
table.insert(cells, '<td style="background-color:' .. site_color .. '; text-align:center;">' .. get_site_name(site) .. '</td>')
tableRows = tableRows .. tostring(result)
table.insert(cells, '<td style="background-color:' .. get_color() .. ';"><a href="' .. get_site_url(site, id) .. '">' .. get_alias(alias, page_title) .. '</a></td>')
end
table.insert(cells, '<td style="background-color:' .. get_color() .. ';">' .. get_notes(notes) .. '</td>')
end
table.insert(output, '<tr>' .. table.concat(cells) .. '</tr>')
return tostring(tableTop) .. tableRows .. '</table>'
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