Module:HelpWantedProjects
From Piñata Journal
More actions
Documentation for this module may be created at Module:HelpWantedProjects/doc
local p = {}
local DATA_PAGE = "Template:Help wanted projects/Data"
local DEFAULT_LIMIT = 3
function p.main(frame)
local limit = tonumber(frame.args.limit) or DEFAULT_LIMIT
local title = mw.title.new(DATA_PAGE)
if not title or not title.exists then
return "<span class='error'>Projects data page missing</span>"
end
local content = title:getContent()
if not content then
return "<span class='error'>No project data</span>"
end
local items = {}
for line in content:gmatch("[^\r\n]+") do
local item = line:match("^%*%s*(.+)")
if item then
table.insert(items, item)
end
end
if #items == 0 then
return ""
end
local out = {}
table.insert(out, "<ul>")
for i = 1, math.min(limit, #items) do
table.insert(out, "<li>" .. items[i] .. "</li>")
end
table.insert(out, "</ul>")
return table.concat(out, "\n")
end
return p