Module:CareerList

From Porn Base Central
Revision as of 19:48, 12 March 2023 by PeaceDeadC (talk | contribs) (Created page with "local p = {} function p.getConfig(siteName) local siteConfig = mw.loadData("Module:CareerList/config")[siteName] if not siteConfig then error(string.format("Site '%s' not found in configuration file", siteName)) end return siteConfig 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 i...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local p = {}

function p.getConfig(siteName)
    local siteConfig = mw.loadData("Module:CareerList/config")[siteName]
    if not siteConfig then
        error(string.format("Site '%s' not found in configuration file", siteName))
    end
    return siteConfig
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
    return string.sub(url, 1, idPlaceholder - 1) .. id .. string.sub(url, idPlaceholder + string.len(variable))
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
    return tostring(data)
end

return p