Module:Events
From Deepspace Lore
More actions
Documentation for this module may be created at Module:Events/doc
local p = {}
-- Config: full LI roster, update here if new characters are added
local ALL_CHARACTERS = {
"Xavier",
"Zayne",
"Rafayel",
"Sylus",
"Caleb"
}
-- Split a string on a delimiter, trim whitespace from each part
local function splitAndTrim( str, sep )
local result = {}
for part in str:gmatch( "[^" .. sep .. "]+" ) do
local trimmed = part:match( "^%s*(.-)%s*$" )
if trimmed ~= "" then
table.insert( result, trimmed )
end
end
return result
end
-- Resolve characters field: expands "All" to full roster
local function resolveCharacters( raw )
if not raw or raw == "" then
return {}
end
local trimmed = raw:match( "^%s*(.-)%s*$" )
if trimmed == "All" then
return ALL_CHARACTERS
end
return splitAndTrim( raw, ";" )
end
-- Store event data into Bucket, called via Template:EventStore
function p.store( frame )
local args = frame.args
local characters = resolveCharacters( args.characters )
bucket("events").put({
name = args.name or "",
label = args.label or "",
type = args.type or "",
subtype = args.subtype or "",
image = args.image or "",
start = args.start or "",
["end"] = args["end"] or "",
characters = characters,
description = args.description or ""
})
return ""
end
-- Render events list as a wikitable
function p.list( frame )
local args = frame.args
local results = bucket("events")
.select("name", "label", "type", "subtype", "start", "end", "description")
.orderBy("start", "desc")
.run()
if not results or #results == 0 then
return "No events found."
end
local out = {}
table.insert( out, '{| class="wikitable sortable"' )
table.insert( out, '! Name !! Type !! Subtype !! Start !! End !! Description' )
for _, row in ipairs( results ) do
local label = ( row.label and row.label ~= "" ) and row.label or row.name
local name = ( row.name and row.name ~= "" ) and row.name or ""
local link
if name ~= "" then
if label ~= name then
link = "[[" .. name .. "|" .. label .. "]]"
else
link = "[[" .. name .. "]]"
end
else
link = label
end
table.insert( out, "|-" )
table.insert( out, string.format(
"| %s || %s || %s || %s || %s || %s",
link,
row.type or "",
row.subtype or "",
row.start or "",
row["end"] or "",
row.description or ""
))
end
table.insert( out, "|}" )
return table.concat( out, "\n" )
end
return p