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 cfg = mw.loadData('Module:CareerList/config')
local cfg = mw.loadData('Module:CareerList/config')


local function getSiteLink(site)
-- функция для определения ссылки на сайт
site = mw.ustring.lower(site)
local function getSiteLink(site, id)
if cfg[site] then
local url = cfg[site].url or ''
return cfg[site].url:gsub('$1', id)
local id = cfg[site].id or ''
return url:gsub('$1', id)
end
end
end


local function makeCell(args, bgcolor)
-- функция для создания ячейки таблицы
local site = args.site or ''
local function makeCell(row, bg)
local cell = {}
local id = args.id or ''
local site = row.site:lower()
local alias = args.alias or mw.title.getCurrentTitle().text
local notes = args.notes or 'N/A'

local link = getSiteLink(site):gsub('$1', id)
-- Ячейка 1
local bg = (site == 'Website') and '#E7E7E7' or '#DADADA'
cell[1] = mw.html.create('td')
local rowbg = (bgcolor == '#FFFFFF') and '#F3F3F3' or '#FFFFFF'
:css('background-color', cfg[site].bg[bg])
return string.format([[
:wikitext(cfg[site].text)
<tr style="background-color: %s;">
<td style="background-color: %s;">%s</td>
-- Ячейка 2
<td style="background-color: %s;"><a href="%s">%s</a></td>
cell[2] = mw.html.create('td')
<td>%s</td>
:wikitext('[[' .. row.site .. '|' .. row.alias .. ']]')
<td>%s</td>

</tr>
-- Ячейка 3
]], bgcolor, bg, site, rowbg, link, alias, alias, notes)
cell[3] = mw.html.create('td')
:wikitext('[[' .. getSiteLink(site, row.id) .. '|' .. row.id .. ']]')

-- Ячейка 4
cell[4] = mw.html.create('td')
:wikitext(row.alias == '' and mw.title.getCurrentTitle().text or row.alias)

-- Ячейка 5
cell[5] = mw.html.create('td')
:wikitext(row.notes == '' and 'N/A' or row.notes)

return cell
end
end


function p.table(frame)
function p.main(frame)
local list = frame.args.list
local args = frame.args
if not list then
local list = args.list or ''
return ''
local title = args.title or ''
local bgcolor = '#F2F2F2'
end
local rows = ''

for row in mw.ustring.gmatch(list, '{{CareerListCell(.-)}}') do
-- Разбиение на строки
local rows = mw.text.split(list, '\n')
rows = rows .. makeCell(mw.text.split(row, '|'), bgcolor)
bgcolor = (bgcolor == '#FFFFFF') and '#F3F3F3' or '#FFFFFF'
local cells = {}

-- Создание ячеек
for i, row in ipairs(rows) do
local values = mw.text.split(row, '|')
local bg = i % 2 == 0 and 2 or 1
cells[i] = makeCell({
site = values[1],
id = values[2],
alias = values[3] or '',
notes = values[4] or ''
}, bg)
end

-- Создание таблицы
local html = mw.html.create()
html
:tag('table')
:addClass('wikitable careerlist')
:css('background-color', '#F2F2F2')
:css('width', '100%')
:css('max-width', 'none')
:css('table-layout', 'fixed')
:wikitext('\n|-')

-- Заголовок таблицы
for i, header in ipairs(cfg.header) do
html
:tag('th')
:css('background-color', '#F2F2F2')
:wikitext(header)
end

-- Строки таблицы
for i, row in ipairs(cells) do
html:wikitext('\n|-')
for j, cell in ipairs(row) do
html:addChild(cell)
end
end
return string.format([[
end
<table class="wikitable" style="width: 100%; margin: 1em 0; background-color: %s;">

<caption>%s</caption>
return tostring(html)
<tr>
<th style="width: 15%;">Type</th>
<th style="width: 35%;">Name</th>
<th style="width: 35%;">Alias</th>
<th style="width: 15%;">Notes</th>
</tr>
%s
</table>
]], bgcolor, title, rows)
end
end



Revision as of 02:17, 13 March 2023

Documentation for this module may be created at Module:CareerList/doc

local p = {}

local cfg = mw.loadData('Module:CareerList/config')

local function getSiteLink(site)
    site = mw.ustring.lower(site)
    local url = cfg[site].url or ''
    local id = cfg[site].id or ''
    return url:gsub('$1', id)
end

local function makeCell(args, bgcolor)
    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 link = getSiteLink(site):gsub('$1', id)
    local bg = (site == 'Website') and '#E7E7E7' or '#DADADA'
    local rowbg = (bgcolor == '#FFFFFF') and '#F3F3F3' or '#FFFFFF'
    return string.format([[
        <tr style="background-color: %s;">
            <td style="background-color: %s;">%s</td>
            <td style="background-color: %s;"><a href="%s">%s</a></td>
            <td>%s</td>
            <td>%s</td>
        </tr>
    ]], bgcolor, bg, site, rowbg, link, alias, alias, notes)
end

function p.main(frame)
    local args = frame.args
    local list = args.list or ''
    local title = args.title or ''
    local bgcolor = '#F2F2F2'
    local rows = ''
    for row in mw.ustring.gmatch(list, '{{CareerListCell(.-)}}') do
        rows = rows .. makeCell(mw.text.split(row, '|'), bgcolor)
        bgcolor = (bgcolor == '#FFFFFF') and '#F3F3F3' or '#FFFFFF'
    end
    return string.format([[
        <table class="wikitable" style="width: 100%; margin: 1em 0; background-color: %s;">
            <caption>%s</caption>
            <tr>
                <th style="width: 15%;">Type</th>
                <th style="width: 35%;">Name</th>
                <th style="width: 35%;">Alias</th>
                <th style="width: 15%;">Notes</th>
            </tr>
            %s
        </table>
    ]], bgcolor, title, rows)
end

return p