Module:CareerList: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
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..." |
PeaceDeadC (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
local mw = require('mw') |
|||
function p.getConfig(siteName) |
function p.getConfig(siteName) |
||
| Line 52: | Line 53: | ||
end |
end |
||
return tostring(data) |
return tostring(data) |
||
end |
|||
function p.main(frame) |
|||
return p.makeTable(frame) |
|||
end |
end |
||
Revision as of 16:56, 12 March 2023
Documentation for this module may be created at Module:CareerList/doc
local p = {}
local mw = require('mw')
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
function p.main(frame)
return p.makeTable(frame)
end
return p