Content deleted Content added
No edit summary
No edit summary
 
(20 intermediate revisions by 2 users not shown)
Line 1:
local p = {}
 
-- Функция для создания таблицы
local function getConfig(site)
function p.makeTableTop()
local config = mw.loadData("Module:CareerList/config")
local headerRow = mw.html.create('tr')
return config[site]
: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%')
:node(headerRow)
:done()
end
 
-- Функция для создания ячейки таблицы
function p.CareerListTop(frame)
function p.makeCell(cellType, args)
local args = frame.args
local listfunction = args.list or ""getColor(index)
return ((index or 0) % 2 == 0) and '#F3F3F3' or '#FFFFFF'
local bgcolor = args.bgcolor or "#F2F2F2"
end
return string.format([[
 
<table class="wikitable" style="background-color:%s;width:100%%;">
local function getBackground(site)
<tr>
local config = mw.loadData('Module:CareerList/config')
<th>Site</th>
local color = (cellType == 'Studio') and '#DADADA' <th>ID</th>or '#E7E7E7'
return config[site] and color or <th>Alias</th>'#FFFFFF'
end
<th>Notes</th>
 
</tr>
local function getAlias(alias, title)
%s
if not alias or </table>alias == '' then
return 'N/A'
]], bgcolor, list)
else
return alias
end
end
 
local function p.CareerListgetNotes(framenotes)
if not notes or notes == '' then
local args = frame.args
local site = args.site orreturn ""'N/A'
else
local id = args.id or ""
return notes
local alias = args.alias or mw.title.getCurrentTitle().text
local notes = args.notes or "N/A"
local config = getConfig(site)
if not config then
return ""
end
end
local url = config.url:gsub("%$1", id)
 
local bgcolor = config.type == "Studio" and "#DADADA" or "#FFFFFF"
if not args.site then
local color = config.type == "Studio" and "#000000" or "#000000"
return stringmw.html.formatcreate([['tr')
<tr style=" :css('background-color:%s;color:%s;">', getColor(args.rowIndex))
:node(mw.html.create('td'):attr('colspan', '4'):wikitext('Invalid arguments. Please see documentation for correct usage.'))
<td><a href="%s">%s</a></td>
<td>%s</td>:done()
end
<td>%s</td>
 
<td>%s</td>
local site = args.site or mw.title.getCurrentTitle().text
</tr>
local id = args.id or ''
]], bgcolor, color, url, config.name, id, alias, notes)
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