Module:ProjectBox: Difference between revisions
From Nasqueron Agora
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
-- Module:ProjectInfobox | |||
-- Renders a structured infobox for a project page. | |||
-- Usage: {{#invoke:ProjectInfobox|render}} | |||
local p = {} | local p = {} | ||
local function | -- Split a comma-separated string into a trimmed list. | ||
local function splitList(value) | |||
local items = {} | |||
for item in value:gmatch("[^,]+") do | |||
table.insert(items, mw.text.trim(item)) | |||
end | end | ||
return | return items | ||
end | |||
) | -- Wrap a value in a table cell pair (label / value). | ||
local function row(label, value) | |||
return mw.html.create("tr") | |||
:tag("th"):addClass("project-infobox__label"):wikitext(label):done() | |||
:tag("td"):addClass("project-infobox__value"):wikitext(value):done() | |||
end | |||
-- Render participants as a comma-separated inline list. | |||
local function participantCell(raw) | |||
local names = splitList(raw) | |||
local linked = {} | |||
for _, name in ipairs(names) do | |||
table.insert(linked, "[[User:" .. name .. "|" .. name .. "]]") | |||
end | |||
return table.concat(linked, ", ") | |||
end | end | ||
| Line 14: | Line 34: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local | local group = mw.text.trim(args.group or "") | ||
local project = mw.text.trim(args.project or "") | |||
local participants = mw.text.trim(args.participants or "") | |||
local status = mw.text.trim(args.status or "") | |||
local description = mw.text.trim(args.description or "") | |||
local root = mw.html.create("table"):addClass("project-infobox") | |||
local tbody = root:tag("tbody") | |||
-- | -- Header row: project name as caption | ||
root:tag("caption") | |||
:addClass("project-infobox__title") | |||
:wikitext(project ~= "" and project or "Project") | |||
if group ~= "" then | |||
tbody:node(row("Group", group)) | |||
end | end | ||
if project ~= "" then | |||
tbody:node(row("Project", project)) | |||
end | |||
if status ~= "" then | |||
tbody:node(row("Status", status)) | |||
end | |||
if participants ~= "" then | |||
tbody:node(row("Participants", participantCell(participants))) | |||
end | |||
if description ~= "" then | |||
tbody:tag("tr") | |||
:tag("td") | |||
:attr("colspan", "2") | |||
:addClass("project-infobox__description") | |||
:wikitext(description) | |||
end | |||
return | return tostring(root) | ||
end | end | ||
return p | return p | ||
Latest revision as of 17:52, 9 April 2026
Documentation for this module may be created at Module:ProjectBox/doc
-- Module:ProjectInfobox
-- Renders a structured infobox for a project page.
-- Usage: {{#invoke:ProjectInfobox|render}}
local p = {}
-- Split a comma-separated string into a trimmed list.
local function splitList(value)
local items = {}
for item in value:gmatch("[^,]+") do
table.insert(items, mw.text.trim(item))
end
return items
end
-- Wrap a value in a table cell pair (label / value).
local function row(label, value)
return mw.html.create("tr")
:tag("th"):addClass("project-infobox__label"):wikitext(label):done()
:tag("td"):addClass("project-infobox__value"):wikitext(value):done()
end
-- Render participants as a comma-separated inline list.
local function participantCell(raw)
local names = splitList(raw)
local linked = {}
for _, name in ipairs(names) do
table.insert(linked, "[[User:" .. name .. "|" .. name .. "]]")
end
return table.concat(linked, ", ")
end
function p.render(frame)
local args = frame:getParent().args
local group = mw.text.trim(args.group or "")
local project = mw.text.trim(args.project or "")
local participants = mw.text.trim(args.participants or "")
local status = mw.text.trim(args.status or "")
local description = mw.text.trim(args.description or "")
local root = mw.html.create("table"):addClass("project-infobox")
local tbody = root:tag("tbody")
-- Header row: project name as caption
root:tag("caption")
:addClass("project-infobox__title")
:wikitext(project ~= "" and project or "Project")
if group ~= "" then
tbody:node(row("Group", group))
end
if project ~= "" then
tbody:node(row("Project", project))
end
if status ~= "" then
tbody:node(row("Status", status))
end
if participants ~= "" then
tbody:node(row("Participants", participantCell(participants)))
end
if description ~= "" then
tbody:tag("tr")
:tag("td")
:attr("colspan", "2")
:addClass("project-infobox__description")
:wikitext(description)
end
return tostring(root)
end
return p
