Modul:Saison
Die Dokumentation für dieses Modul kann unter Modul:Saison/Doku erstellt werden
-- Erstellt Links zur Vor- und Folgesaison aus dem Titel
local function addSeasonLinks(box, titel)
-- Saison aus dem Titel auslesen
local jahr1, jahr2 = titel:match("Saison%s+(%d%d%d%d)/(%d%d)")
if not jahr1 or not jahr2 then
return
end
jahr1 = tonumber(jahr1)
jahr2 = tonumber(jahr2)
-- Vor- und Folgesaison berechnen
local vor1 = jahr1 - 1
local vor2 = (jahr2 - 1) % 100
local folge1 = jahr1 + 1
local folge2 = (jahr2 + 1) % 100
local vorsaison = string.format("Saison %d/%02d", vor1, vor2)
local folgesaison = string.format("Saison %d/%02d", folge1, folge2)
-- Zeile hinzufügen
box
:tag("tr")
:tag("td")
:attr("colspan", "2")
:wikitext(
"[[" .. vorsaison .. "|←" .. vorsaison .. "]]" ..
" · " ..
"[[" .. folgesaison .. "|" .. folgesaison .. "➜]]"
)
:done()
:done()
end
local p = {}
-- Erstellt eine Zeile der Infobox
local function addRow(box, label, value)
if value and value ~= "" then
box
:tag("tr")
:tag("th")
:wikitext(label)
:done()
:tag("td")
:wikitext(value)
:done()
:done()
end
end
-- Liste der möglichen Felder
local fields = {
{"table_place", "Tabellen Platz"},
{"points", "Punkte"},
{"goals", "Tore"},
{"coach", "Trainer"},
{"date_start", "Erste Runde"},
{"date_finish", "Letzte Runde"},
}
-- Hauptfunktion
function p.main(frame)
-- Parameter der Vorlage holen
local args = frame:getParent().args
-- Grundparameter
local titel = args.titel or ""
local bild = args.bild or ""
local bildbeschreibung = args.bildbeschreibung or ""
-- Tabelle erstellen
local box = mw.html.create("table")
:addClass("infobox")
-- Titel
if titel ~= "" then
box
:tag("caption")
:wikitext(titel)
:done()
end
-- Bild
if bild ~= "" then
box
:tag("tr")
:tag("td")
:attr("colspan", "2")
:addClass("infobox-bild")
:wikitext("[[Datei:" .. bild .. "|250px]]")
:done()
:done()
-- Bildbeschreibung
if bildbeschreibung ~= "" then
box
:tag("tr")
:tag("td")
:attr("colspan", "2")
:addClass("infobox-bild")
:wikitext(bildbeschreibung)
:done()
:done()
end
end
-- Alle Felder automatisch hinzufügen
for _, field in ipairs(fields) do
local parameter = field[1]
local label = field[2]
local value = args[parameter]
addRow(box, label, value)
end
addSeasonLinks(box, titel)
-- HTML zurückgeben
return tostring(box)
end
return p