Module:CareerList: Difference between revisions

From Porn Base Central
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}


local function getConfig(site)
-- Функция для получения конфигурации по сайту
local config = mw.loadData("Module:CareerList/config")
local function getSiteConfig(site)
local config = mw.loadData('Module:CareerList/config')[site:lower()]
return config[site]
if not config then
error(string.format('Не найдена конфигурация для сайта "%s"', site))
end
return config
end
end


function p.CareerListTop(frame)
-- Функция для генерации ссылки по конфигурации
local args = frame.args
local function generateLink(config, id)
local list = args.list or ""
return config.url:gsub('%$1', id)
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
end


function p.main(frame)
function p.CareerList(frame)
local args = frame:getParent().args
local args = frame.args
local site = args.site or ""

local id = args.id or ""
-- Проверяем передан ли параметр list
local list = args.list or error('Не задан список')
local alias = args.alias or mw.title.getCurrentTitle().text
local notes = args.notes or "N/A"

local config = getConfig(site)
-- Разбиваем список на отдельные строки
if not config then
local items = mw.text.split(list, '%s*{{CareerList%s*|')
return ""

-- Генерируем 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
end
local url = config.url:gsub("%$1", id)

local bgcolor = config.type == "Studio" and "#DADADA" or "#FFFFFF"
html = html .. '</table>'
local color = config.type == "Studio" and "#000000" or "#000000"

return html
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
end



Revision as of 01:08, 13 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