Content deleted Content added
No edit summary
No edit summary
 
(33 intermediate revisions by 2 users not shown)
Line 1:
local p = {}
 
-- Функция для создания таблицы
function p.getSiteConfig(siteName)
function p.makeTableTop()
local siteConfig = mw.loadData('Module:CareerList/config')[siteName:lower()]
local headerRow = mw.html.create('tr')
if not siteConfig then
:node(mw.html.create('th'):wikitext('site'))
error('Unknown site: ' .. siteName)
: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.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 siteConfig
end
 
local function p.makeLinkgetNotes(siteName, idnotes)
if not notes or notes == '' then
local siteConfig = p.getSiteConfig(siteName)
return 'N/A'
local url = siteConfig.url:gsub('%$1', id)
else
return string.format('[[%s|%s]]', url, siteName)
return notes
end
end
 
if not args.site then
function p.getCellBgColor(siteName)
return mw.html.create('tr')
local siteConfig = p.getSiteConfig(siteName)
:css('background-color', getColor(args.rowIndex))
return siteConfig.type == 'studio' and '#DADADA' or '#E7E7E7'
: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.getTableHtml(args)
function p.processArgs(frame)
local list = args.list or error('List not specified')
local args = require('Module:Arguments').getArgs(frame, {
local rows = {}
wrappers = 'Template:CareerList'
for _, item in ipairs(list) do
})
local siteName, id, alias, notes
local site = args[1] or ''
if type(item) == 'table' then
local id = args[2] or ''
siteName = item.site or error('Site not specified')
local alias = args[3] or ''
id = item.id or error('ID not specified')
local notes = args[4] or ''
alias = item.alias or mw.title.getCurrentTitle().text
 
notes = item.notes or 'N/A'
if site == '' then
else
return '<strong class="error">Error: </strong>Site parameter is required'
error('Invalid list item')
else
end
site = site:lower()
local link = p.makeLink(siteName, id)
if not mw.loadData('Module:CareerList/config')[site] then
local cellBgColor = p.getCellBgColor(siteName)
return '<strong class="error">Error: </strong>Invalid site specified'
local rowBgColor = #rows % 2 == 0 and '#FFFFFF' or '#F3F3F3'
else
table.insert(rows, string.format([[
return p.makeCell(site, id, alias, notes)
<tr style="background-color:%s;">
<td style="background-color:%s;">%s</td>
<td style="background-color:%s;">%s</td>
<td>%s</td>
<td>%s</td>
</tr>
]], rowBgColor, cellBgColor, siteName, cellBgColor, link, alias, notes))
end
end
local tableHtml = string.format([[
<table style="width:100%%;border-collapse:collapse;">
<tr style="background-color:#F2F2F2;">
<th style="background-color:#F2F2F2;">Website/Studio</th>
<th style="background-color:#F2F2F2;">Link</th>
<th style="background-color:#F2F2F2;">Alias</th>
<th style="background-color:#F2F2F2;">Notes</th>
</tr>
%s
</table>
]], table.concat(rows))
return tableHtml
end
 
-- Главная функция модуля
function p.main(frame)
local argstableTop = frame:getParentp.makeTableTop().args
local tableRows = ''
return p.getTableHtml(args)
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