Module:CareerList: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
PeaceDeadC (talk | contribs) No edit summary |
No edit summary |
||
| Line 61: | Line 61: | ||
end |
end |
||
html = html .. '</table>' |
|||
return html |
return html |
||
Revision as of 20:50, 12 March 2023
Documentation for this module may be created at Module:CareerList/doc
local p = {}
-- Функция для получения конфигурации по сайту
local function getSiteConfig(site)
local config = mw.loadData('Module:CareerList/config')[site:lower()]
if not config then
error(string.format('Не найдена конфигурация для сайта "%s"', site))
end
return config
end
-- Функция для генерации ссылки по конфигурации
local function generateLink(config, id)
return config.url:gsub('%$1', id)
end
function p.main(frame)
local args = frame:getParent().args
-- Проверяем передан ли параметр list
local list = args.list or error('Не задан список')
-- Разбиваем список на отдельные строки
local items = mw.text.split(list, '%s*{{CareerList%s*|')
-- Генерируем HTML-таблицу
local html = '<table class="wikitable CareerListTable">\n'
html = html .. '<tr style="background-color:#F2F2F2;">\n'
html = html .. '<th style="text-align:left;">Website/Studio</th>\n'
html = html .. '<th style="text-align:left;">Site</th>\n'
html = html .. '<th style="text-align:left;">ID</th>\n'
html = html .. '<th style="text-align:left;">Alias</th>\n'
html = html .. '<th style="text-align:left;">Notes</th>\n'
html = html .. '</tr>\n'
-- Перебираем каждый элемент списка
local i = 1
for _, item in ipairs(items) do
if item ~= '' then
local itemArgs = mw.text.split(item, '%|')
local site = mw.text.trim(itemArgs[1] or '')
local id = mw.text.trim(itemArgs[2] or '')
local alias = mw.text.trim(itemArgs[3] or '')
local notes = mw.text.trim(itemArgs[4] or '')
-- Получаем конфигурацию для сайта
local config = getSiteConfig(site)
-- Генерируем HTML-строку для текущего элемента
local rowHtml = '<tr style="background-color:'..(i%2==0 and '#F3F3F3' or '#FFFFFF')..';">\n'
rowHtml = rowHtml .. '<td style="background-color:'..(config.type == 'Studio' and '#DADADA' or '#E7E7E7')..';">'..config.type..'</td>\n'
rowHtml = rowHtml .. '<td><a href="'..generateLink(config, id)..'">'..config.name..'</a></td>\n'
rowHtml = rowHtml .. '<td>'..id..'</td>\n'
rowHtml = rowHtml .. '<td>'..(alias ~= '' and alias or config.name)..'</td>\n'
rowHtml = rowHtml .. '<td>'..(notes ~= '' and notes or 'N/A')..'</td>\n'
rowHtml = rowHtml .. '</tr>\n'
html = html .. rowHtml
i = i + 1
end
end
html = html .. '</table>'
return html
end
return p