Module:Project infobox
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Project infobox/doc
-- The infobox behind {{Project}}. The wiki has no ParserFunctions, so the
-- optional rows are left out here rather than with {{#if:}}.
local p = {}
local rows = {
{ 'status', 'Status' },
{ 'type', 'Type' },
{ 'maintainers', 'Maintainers' },
{ 'started', 'Started' },
{ 'platform', 'Runs on' },
{ 'source', 'Source' },
{ 'docs', 'Docs' },
}
local function value(args, key)
local v = args[key]
if v then
v = mw.text.trim(v)
if v ~= '' then
return v
end
end
return nil
end
function p.main(frame)
local args = frame:getParent().args
local title = mw.title.getCurrentTitle()
local name = value(args, 'name') or title.text
local box = mw.html.create('table'):addClass('pb-project')
box:tag('tr'):tag('th'):attr('colspan', '2'):addClass('pb-project-title'):wikitext(name)
local image = value(args, 'image')
if image then
local cell = box:tag('tr'):tag('td'):attr('colspan', '2'):addClass('pb-project-image')
cell:wikitext(string.format('[[File:%s|%s|alt=%s]]', image, value(args, 'image_size') or '120px', name))
local caption = value(args, 'caption')
if caption then
cell:tag('div'):addClass('pb-project-caption'):wikitext(caption)
end
end
for _, row in ipairs(rows) do
local v = value(args, row[1])
if v then
local tr = box:tag('tr')
tr:tag('th'):attr('scope', 'row'):wikitext(row[2])
tr:tag('td'):wikitext(v)
end
end
local out = frame:extensionTag('templatestyles', '', { src = 'Template:Project/styles.css' }) .. tostring(box)
-- Only articles are listed, so the template's own page and its docs stay out.
if title.namespace == 0 then
out = out .. '[[Category:Projects]]'
local category = value(args, 'category')
if category then
out = out .. '[[Category:' .. category .. ']]'
end
end
return out
end
return p