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 = {}


function p.main(frame)
function p.getSiteConfig(siteName)
local config = mw.loadData('Модуль:CareerList/config')
local siteConfig = mw.loadData('Module:CareerList/config')[siteName:lower()]
if not siteConfig then
local args = frame:getParent().args
error('Unknown site: ' .. siteName)
local list = args.list or ''
local output = {}
local site_colors = { -- цвета фона ячеек
website = '#E7E7E7',
studio = '#DADADA'
}
local color_count = 0
local row_color = {}
local function get_color()
color_count = color_count + 1
if color_count % 2 == 0 then
return '#F3F3F3'
else
return '#FFFFFF'
end
end
end
return siteConfig
local function get_site_color(site)
end
return site_colors[config[site].type]

end
local function get_site_name(site)
function p.makeLink(siteName, id)
local siteConfig = p.getSiteConfig(siteName)
return config[site].name
local url = siteConfig.url:gsub('%$1', id)
end
return string.format('[[%s|%s]]', url, siteName)
local function get_site_url(site, id)
end
local url = config[site].url

return mw.ustring.gsub(url, '%$1', id)
function p.getCellBgColor(siteName)
end
local function get_alias(alias, page_title)
local siteConfig = p.getSiteConfig(siteName)
if alias and alias ~= '' then
return siteConfig.type == 'studio' and '#DADADA' or '#E7E7E7'
end
return alias

function p.getTableHtml(args)
local list = args.list or error('List not specified')
local rows = {}
for _, item in ipairs(list) do
local siteName, id, alias, notes
if type(item) == 'table' then
siteName = item.site or error('Site not specified')
id = item.id or error('ID not specified')
alias = item.alias or mw.title.getCurrentTitle().text
notes = item.notes or 'N/A'
else
else
return page_title
error('Invalid list item')
end
end
local link = p.makeLink(siteName, id)
local cellBgColor = p.getCellBgColor(siteName)
local rowBgColor = #rows % 2 == 0 and '#FFFFFF' or '#F3F3F3'
table.insert(rows, string.format([[
<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 function get_notes(notes)
local tableHtml = string.format([[
<table style="width:100%%;border-collapse:collapse;">
if notes and notes ~= '' then
return notes
<tr style="background-color:#F2F2F2;">
<th style="background-color:#F2F2F2;">Website/Studio</th>
else
return 'N/A'
<th style="background-color:#F2F2F2;">Link</th>
<th style="background-color:#F2F2F2;">Alias</th>
end
<th style="background-color:#F2F2F2;">Notes</th>
end
</tr>
for row in mw.ustring.gmatch(list, '%{%{CareerList%|(.+)%}%}') do
local cells = {}
%s
</table>
local values = mw.text.split(row, '|')
]], table.concat(rows))
local site = mw.ustring.lower(values[2])
return tableHtml
local id = values[3]
end
local alias = values[4]

local notes = values[5]
function p.main(frame)
local page_title = mw.title.getCurrentTitle().text
local args = frame:getParent().args
if not config[site] then
return p.getTableHtml(args)
error('Invalid site: ' .. site)
end
local site_color = get_site_color(site)
table.insert(row_color, site_color)
table.insert(cells, '<td style="background-color:' .. site_color .. '; text-align:center;">' .. get_site_name(site) .. '</td>')
table.insert(cells, '<td style="background-color:' .. get_color() .. ';"><a href="' .. get_site_url(site, id) .. '">' .. get_alias(alias, page_title) .. '</a></td>')
table.insert(cells, '<td style="background-color:' .. get_color() .. ';">' .. get_notes(notes) .. '</td>')
table.insert(output, '<tr>' .. table.concat(cells) .. '</tr>')
end
local header = args.header or ''
local style = 'style="background-color:#F2F2F2;"'
local table_header = '<table class="wikitable" style="width:100%;">' ..
'<tr ' .. style .. '><th colspan="3">' .. header .. '</th></tr>' ..
'<tr ' .. style .. '><th>' .. config.website.name .. '</th><th>' .. config.studio.name .. '</th><th>Notes</th></tr>'
local table_footer = '</table>'
return table_header .. table.concat(output) .. table_footer
end
end



Revision as of 20:59, 12 March 2023

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

local p = {}

function p.getSiteConfig(siteName)
    local siteConfig = mw.loadData('Module:CareerList/config')[siteName:lower()]
    if not siteConfig then
        error('Unknown site: ' .. siteName)
    end
    return siteConfig
end

function p.makeLink(siteName, id)
    local siteConfig = p.getSiteConfig(siteName)
    local url = siteConfig.url:gsub('%$1', id)
    return string.format('[[%s|%s]]', url, siteName)
end

function p.getCellBgColor(siteName)
    local siteConfig = p.getSiteConfig(siteName)
    return siteConfig.type == 'studio' and '#DADADA' or '#E7E7E7'
end

function p.getTableHtml(args)
    local list = args.list or error('List not specified')
    local rows = {}
    for _, item in ipairs(list) do
        local siteName, id, alias, notes
        if type(item) == 'table' then
            siteName = item.site or error('Site not specified')
            id = item.id or error('ID not specified')
            alias = item.alias or mw.title.getCurrentTitle().text
            notes = item.notes or 'N/A'
        else
            error('Invalid list item')
        end
        local link = p.makeLink(siteName, id)
        local cellBgColor = p.getCellBgColor(siteName)
        local rowBgColor = #rows % 2 == 0 and '#FFFFFF' or '#F3F3F3'
        table.insert(rows, string.format([[
            <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
    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 args = frame:getParent().args
    return p.getTableHtml(args)
end

return p