Module:Events: Difference between revisions
From Deepspace Lore
More actions
Created page with "local p = {} -- Store event data into Bucket, called via Template:EventStore function p.store(frame) local args = frame.args -- Split characters string on ; into a table local characters = {} if args.characters and args.characters ~= "" then for c in args.characters:gmatch("[^;]+") do table.insert(characters, c:match("^%s*(.-)%s*$")) -- trim whitespace end end bucket("events").put({ name = args.name..." |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | 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 | -- Store event data into Bucket, called via Template:EventStore | ||
function p.store(frame) | function p.store( frame ) | ||
local args = frame.args | local args = frame.args | ||
local characters = resolveCharacters( args.characters ) | |||
local characters = | |||
bucket("events").put({ | bucket("events").put({ | ||
| Line 17: | Line 44: | ||
label = args.label or "", | label = args.label or "", | ||
type = args.type or "", | type = args.type or "", | ||
subtype = args.subtype or "", | |||
image = args.image or "", | image = args.image or "", | ||
start = args.start or "", | start = args.start or "", | ||
| Line 27: | Line 55: | ||
end | end | ||
-- Render | -- Render events list as a wikitable | ||
function p.list(frame) | function p.list( frame ) | ||
local args = frame.args | local args = frame.args | ||
local | local results = bucket("events") | ||
.select("name", "label", "type", " | .select("name", "label", "type", "subtype", "start", "end", "description") | ||
.orderBy("start", "desc") | .orderBy("start", "desc") | ||
.run() | |||
if not results or #results == 0 then | if not results or #results == 0 then | ||
| Line 52: | Line 68: | ||
end | end | ||
local out = {} | local out = {} | ||
table.insert(out, '{| class="wikitable sortable"') | table.insert( out, '{| class="wikitable sortable"' ) | ||
table.insert(out, '! Name !! Type !! | table.insert( out, '! Name !! Type !! Subtype !! Start !! End !! Description' ) | ||
for _, row in ipairs(results) do | for _, row in ipairs( results ) do | ||
local | 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 | end | ||
table.insert( out, "|-" ) | |||
table.insert( out, string.format( | |||
table.insert(out, "|-") | |||
table.insert(out, string.format( | |||
"| %s || %s || %s || %s || %s || %s", | "| %s || %s || %s || %s || %s || %s", | ||
link, | |||
row.type, | row.type or "", | ||
row.subtype or "", | |||
row.start, | row.start or "", | ||
row["end"], | row["end"] or "", | ||
row.description or "" | row.description or "" | ||
)) | )) | ||
end | end | ||
table.insert(out, "|}") | table.insert( out, "|}" ) | ||
return table.concat(out, "\n") | return table.concat( out, "\n" ) | ||
end | end | ||
return p | return p | ||
Revision as of 01:22, 25 April 2026
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