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
-- load configuration from a separate file
local cfg = mw.loadData('Module:CareerList/config')
local config = mw.loadData('Module:CareerList/config')


-- Function to build a row of the table
-- helper function to get the config value for a site
function buildRow(site, id, alias, notes, index)
local function getConfigValue(site, key)
return config[site] and config[site][key]
-- Determine the row color
end
local color

if site == 'Website' then
-- helper function to format the alias or notes field
color = (index % 2 == 1) and cfg.colors.website1 or cfg.colors.website2
local function formatText(text)
else
return text ~= '' and text or 'N/A'
color = (index % 2 == 1) and cfg.colors.studio1 or cfg.colors.studio2
end
end

-- Build the row
-- helper function to generate the table row
local function generateTableRow(site, id, alias, notes, rowColor)
local row = string.format(
local siteColor = getConfigValue(site, 'color')
cfg.rowTemplate,
local cellColor = site == 'Website' and '#E7E7E7' or '#DADADA'
color,
local rowStyle = string.format('background-color: %s;', rowColor)
site == 'Website' and cfg.colors.websiteBg or cfg.colors.studioBg,
local siteStyle = string.format('background-color: %s;', siteColor or cellColor)
site,
cfg.siteUrls[site][1],
local siteName = string.upper(site)
cfg.siteUrls[site][2]:gsub('$1', id),
local url = getConfigValue(site, 'url'):gsub('%$1', id)
return string.format([[
alias == '' and mw.title.getCurrentTitle().text or alias,
notes == '' and 'N/A' or notes
<tr style="%s">
<td style="%s">%s</td>
)
<td style="%s"><a href="%s">%s</a></td>
<td style="%s">%s</td>
return row
<td style="%s">%s</td>
</tr>
]], rowStyle, siteStyle, siteName, cellColor, url, site, cellColor, alias, cellColor, formatText(notes))
end
end


-- Main function
-- main function to generate the table
function p.main(frame)
function p.main(frame)
-- Get the template parameters
local args = frame.args
local args = frame.args
local list = args.list or ''
-- Get the list parameter
local rows = ''
local list = args.list or error('List not specified')
local rowColor = '#FFFFFF'
for row in mw.text.gsplit(list, '%{%{CareerList') do
local params = mw.text.split(row, '|')
-- Split the list into rows
local site = params[2] or ''
local rows = mw.text.split(list, '%s*' .. cfg.rowSeparator .. '%s*')
local id = params[3] or ''
local alias = params[4] or mw.title.getCurrentTitle().text
-- Build the table
local index = 1
local notes = params[5] or ''
rows = rows .. generateTableRow(site, id, alias, notes, rowColor)
local tableContent = ''
rowColor = rowColor == '#FFFFFF' and '#F3F3F3' or '#FFFFFF'
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
end
local tableStyle = 'background-color: #F2F2F2; width: 100%;'
return string.format('<table style="%s">%s</table>', tableStyle, rows)
-- Build the table
local tableHtml = string.format(cfg.tableTemplate, tableContent)
return tableHtml
end
end



Revision as of 21:19, 12 March 2023

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

local p = {}

-- load configuration from a separate file
local config = mw.loadData('Module:CareerList/config')

-- helper function to get the config value for a site
local function getConfigValue(site, key)
    return config[site] and config[site][key]
end

-- helper function to format the alias or notes field
local function formatText(text)
    return text ~= '' and text or 'N/A'
end

-- helper function to generate the table row
local function generateTableRow(site, id, alias, notes, rowColor)
    local siteColor = getConfigValue(site, 'color')
    local cellColor = site == 'Website' and '#E7E7E7' or '#DADADA'
    local rowStyle = string.format('background-color: %s;', rowColor)
    local siteStyle = string.format('background-color: %s;', siteColor or cellColor)
    local siteName = string.upper(site)
    local url = getConfigValue(site, 'url'):gsub('%$1', id)
    return string.format([[
        <tr style="%s">
            <td style="%s">%s</td>
            <td style="%s"><a href="%s">%s</a></td>
            <td style="%s">%s</td>
            <td style="%s">%s</td>
        </tr>
    ]], rowStyle, siteStyle, siteName, cellColor, url, site, cellColor, alias, cellColor, formatText(notes))
end

-- main function to generate the table
function p.main(frame)
    local args = frame.args
    local list = args.list or ''
    local rows = ''
    local rowColor = '#FFFFFF'
    for row in mw.text.gsplit(list, '%{%{CareerList') do
        local params = mw.text.split(row, '|')
        local site = params[2] or ''
        local id = params[3] or ''
        local alias = params[4] or mw.title.getCurrentTitle().text
        local notes = params[5] or ''
        rows = rows .. generateTableRow(site, id, alias, notes, rowColor)
        rowColor = rowColor == '#FFFFFF' and '#F3F3F3' or '#FFFFFF'
    end
    local tableStyle = 'background-color: #F2F2F2; width: 100%;'
    return string.format('<table style="%s">%s</table>', tableStyle, rows)
end

return p