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


-- Load the configuration file
function p.getSiteConfig(siteName)
local siteConfig = mw.loadData('Module:CareerList/config')[siteName:lower()]
local cfg = mw.loadData('Module:CareerList/config')

if not siteConfig then
-- Function to build a row of the table
error('Unknown site: ' .. siteName)
function buildRow(site, id, alias, notes, index)
-- Determine the row color
local color
if site == 'Website' then
color = (index % 2 == 1) and cfg.colors.website1 or cfg.colors.website2
else
color = (index % 2 == 1) and cfg.colors.studio1 or cfg.colors.studio2
end
end
return siteConfig
-- Build the row
local row = string.format(
cfg.rowTemplate,
color,
site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg,
site,
cfg.siteUrls[site][1],
cfg.siteUrls[site][2]:gsub('$1', id),
alias == '' and mw.title.getCurrentTitle().text or alias,
notes == '' and 'N/A' or notes
)
return row
end
end


-- Main function
function p.makeLink(siteName, id)
function p.main(frame)
local siteConfig = p.getSiteConfig(siteName)
-- Get the template parameters
local url = siteConfig.url:gsub('%$1', id)
local args = frame.args
return string.format('[[%s|%s]]', url, siteName)
end
-- Get the list parameter

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 list = args.list or error('List not specified')
local rows = {}
for _, item in ipairs(list) do
-- Split the list into rows
local rows = mw.text.split(list, '%s*' .. cfg.rowSeparator .. '%s*')
local siteName, id, alias, notes
if type(item) == 'table' then
-- Build the table
siteName = item.site or error('Site not specified')
local index = 1
id = item.id or error('ID not specified')
local tableContent = ''
alias = item.alias or mw.title.getCurrentTitle().text
for _, row in ipairs(rows) do
notes = item.notes or 'N/A'
local params = mw.text.split(row, '%s*|%s*')
else
error('Invalid list item')
if #params >= 3 then
local site = params[1]
local id = params[2]
local alias = params[3]
local notes = params[4] or ''
tableContent = tableContent .. buildRow(site, id, alias, notes, index)
index = index + 1
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 tableHtml = string.format([[
-- Build the table
<table style="width:100%%;border-collapse:collapse;">
local tableHtml = string.format(cfg.tableTemplate, tableContent)
<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
return tableHtml
end

function p.main(frame)
local args = frame:getParent().args
return p.getTableHtml(args)
end
end



Revision as of 21:04, 12 March 2023

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

local p = {}

-- Load the configuration file
local cfg = mw.loadData('Module:CareerList/config')

-- Function to build a row of the table
function buildRow(site, id, alias, notes, index)
    -- Determine the row color
    local color
    if site == 'Website' then
        color = (index % 2 == 1) and cfg.colors.website1 or cfg.colors.website2
    else
        color = (index % 2 == 1) and cfg.colors.studio1 or cfg.colors.studio2
    end
    
    -- Build the row
    local row = string.format(
        cfg.rowTemplate,
        color,
        site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg,
        site,
        cfg.siteUrls[site][1],
        cfg.siteUrls[site][2]:gsub('$1', id),
        alias == '' and mw.title.getCurrentTitle().text or alias,
        notes == '' and 'N/A' or notes
    )
    
    return row
end

-- Main function
function p.main(frame)
    -- Get the template parameters
    local args = frame.args
    
    -- Get the list parameter
    local list = args.list or error('List not specified')
    
    -- Split the list into rows
    local rows = mw.text.split(list, '%s*' .. cfg.rowSeparator .. '%s*')
    
    -- Build the table
    local index = 1
    local tableContent = ''
    for _, row in ipairs(rows) do
        local params = mw.text.split(row, '%s*|%s*')
        if #params >= 3 then
            local site = params[1]
            local id = params[2]
            local alias = params[3]
            local notes = params[4] or ''
            tableContent = tableContent .. buildRow(site, id, alias, notes, index)
            index = index + 1
        end
    end
    
    -- Build the table
    local tableHtml = string.format(cfg.tableTemplate, tableContent)
    
    return tableHtml
end

return p