Module:CareerList: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
| ⚫ | |||
-- Функция для получения конфигурации по сайту |
|||
| ⚫ | |||
| ⚫ | |||
return config[site] |
|||
| ⚫ | |||
error(string.format('Не найдена конфигурация для сайта "%s"', site)) |
|||
end |
|||
| ⚫ | |||
end |
end |
||
function p.CareerListTop(frame) |
|||
-- Функция для генерации ссылки по конфигурации |
|||
| ⚫ | |||
local function generateLink(config, id) |
|||
local list = args.list or "" |
|||
| ⚫ | |||
local bgcolor = args.bgcolor or "#F2F2F2" |
|||
return string.format([[ |
|||
| ⚫ | |||
| ⚫ | |||
<th>Site</th> |
|||
| ⚫ | |||
<th>Alias</th> |
|||
<th>Notes</th> |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
]], bgcolor, list) |
|||
end |
end |
||
function p. |
function p.CareerList(frame) |
||
local args = frame |
local args = frame.args |
||
local site = args.site or "" |
|||
local id = args.id or "" |
|||
-- Проверяем передан ли параметр list |
|||
local |
local alias = args.alias or mw.title.getCurrentTitle().text |
||
local notes = args.notes or "N/A" |
|||
| ⚫ | |||
-- Разбиваем список на отдельные строки |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
-- Генерируем HTML-таблицу |
|||
local html = '<table class="wikitable CareerListTable">\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' |
|||
| ⚫ | |||
-- Перебираем каждый элемент списка |
|||
| ⚫ | |||
for _, item in ipairs(items) do |
|||
| ⚫ | |||
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 '') |
|||
-- Получаем конфигурацию для сайта |
|||
| ⚫ | |||
-- Генерируем 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' |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
end |
end |
||
| ⚫ | |||
local bgcolor = config.type == "Studio" and "#DADADA" or "#FFFFFF" |
|||
| ⚫ | |||
local color = config.type == "Studio" and "#000000" or "#000000" |
|||
return |
return string.format([[ |
||
<tr style="background-color:%s;color:%s;"> |
|||
<td><a href="%s">%s</a></td> |
|||
<td>%s</td> |
|||
<td>%s</td> |
|||
<td>%s</td> |
|||
| ⚫ | |||
]], bgcolor, color, url, config.name, id, alias, notes) |
|||
end |
end |
||
Revision as of 22:08, 12 March 2023
Documentation for this module may be created at Module:CareerList/doc
local p = {}
local function getConfig(site)
local config = mw.loadData("Module:CareerList/config")
return config[site]
end
function p.CareerListTop(frame)
local args = frame.args
local list = args.list or ""
local bgcolor = args.bgcolor or "#F2F2F2"
return string.format([[
<table class="wikitable" style="background-color:%s;width:100%%;">
<tr>
<th>Site</th>
<th>ID</th>
<th>Alias</th>
<th>Notes</th>
</tr>
%s
</table>
]], bgcolor, list)
end
function p.CareerList(frame)
local args = frame.args
local site = args.site or ""
local id = args.id or ""
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
local url = config.url:gsub("%$1", id)
local bgcolor = config.type == "Studio" and "#DADADA" or "#FFFFFF"
local color = config.type == "Studio" and "#000000" or "#000000"
return string.format([[
<tr style="background-color:%s;color:%s;">
<td><a href="%s">%s</a></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
]], bgcolor, color, url, config.name, id, alias, notes)
end
return p