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 mw = require('mw')


function p.getConfig(siteName)
function p.main(frame)
local siteConfig = mw.loadData("Module:CareerList/config")[siteName]
local config = mw.loadData('Модуль:CareerList/config')
local args = frame:getParent().args
if not siteConfig then
local list = args.list or ''
error(string.format("Site '%s' not found in configuration file", siteName))
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
local function get_site_color(site)
return siteConfig
return site_colors[config[site].type]
end

function p.makeUrl(siteName, id)
local siteConfig = p.getConfig(siteName)
local url = siteConfig.url
local variable = siteConfig.variable
local idPlaceholder = string.find(url, variable)
if idPlaceholder == nil then
error(string.format("No id placeholder found in URL for site '%s'", siteName))
end
end
local function get_site_name(site)
return string.sub(url, 1, idPlaceholder - 1) .. id .. string.sub(url, idPlaceholder + string.len(variable))
return config[site].name
end

function p.makeTable(frame)
local data = mw.html.create("table")
data
:addClass("wikitable")
:addClass("sortable")
:addClass("career-new")
:tag("tr")
:tag("th")
:wikitext(frame.args.title or "")
:done()
for _, row in ipairs(frame.args.list or {}) do
local siteName = row.site
local id = row.id
local alias = row.alias or ""
local notes = row.notes or ""
local url = p.makeUrl(siteName, id)
data
:tag("tr")
:tag("td")
:wikitext(row.site)
:done()
:tag("td")
:wikitext(row.id)
:done()
:tag("td")
:wikitext(row.alias)
:done()
:tag("td")
:wikitext(row.notes)
:done()
end
end
local function get_site_url(site, id)
return tostring(data)
local url = config[site].url
end
return mw.ustring.gsub(url, '%$1', id)

end
function p.main(frame)
local function get_alias(alias, page_title)
return p.makeTable(frame)
if alias and alias ~= '' then
return alias
else
return page_title
end
end
local function get_notes(notes)
if notes and notes ~= '' then
return notes
else
return 'N/A'
end
end
for row in mw.ustring.gmatch(list, '%{%{CareerList%|(.+)%}%}') do
local cells = {}
local values = mw.text.split(row, '|')
local site = mw.ustring.lower(values[2])
local id = values[3]
local alias = values[4]
local notes = values[5]
local page_title = mw.title.getCurrentTitle().text
if not config[site] then
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:47, 12 March 2023

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

local p = {}

function p.main(frame)
    local config = mw.loadData('Модуль:CareerList/config')
    local args = frame:getParent().args
    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
    local function get_site_color(site)
        return site_colors[config[site].type]
    end
    local function get_site_name(site)
        return config[site].name
    end
    local function get_site_url(site, id)
        local url = config[site].url
        return mw.ustring.gsub(url, '%$1', id)
    end
    local function get_alias(alias, page_title)
        if alias and alias ~= '' then
            return alias
        else
            return page_title
        end
    end
    local function get_notes(notes)
        if notes and notes ~= '' then
            return notes
        else
            return 'N/A'
        end
    end
    for row in mw.ustring.gmatch(list, '%{%{CareerList%|(.+)%}%}') do
        local cells = {}
        local values = mw.text.split(row, '|')
        local site = mw.ustring.lower(values[2])
        local id = values[3]
        local alias = values[4]
        local notes = values[5]
        local page_title = mw.title.getCurrentTitle().text
        if not config[site] then
            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

return p