Modul:Spiel-Info
Die Dokumentation für dieses Modul kann unter Modul:Spiel-Info/Doku erstellt werden
local p = {}
-- Erstellt eine normale 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
local function addMatchRow(box, label, date, stadium, attendance, result)
if date ~= "" or stadium ~= "" or result ~= "" then
box
:tag("tr")
:tag("th")
:attr("colspan", "4")
:css("text-align", "center")
:css("font-weight", "bold")
:wikitext(label)
:done()
:done()
if date ~= "" then
box
:tag("tr")
:tag("th")
:wikitext("Datum")
:done()
:tag("td")
:wikitext(date)
:done()
:done()
end
if stadium ~= "" then
box
:tag("tr")
:tag("th")
:wikitext("Stadion")
:done()
:tag("td")
:wikitext(stadium)
:done()
:done()
end
if attendance ~= "" then
box
:tag("tr")
:tag("th")
:wikitext("Besucheranzahl")
:done()
:tag("td")
:wikitext(attendance)
:done()
:done()
end
if result ~= "" then
box
:tag("tr")
:tag("th")
:wikitext("Ergebnis")
:done()
:tag("td")
:wikitext(result)
:done()
:done()
end
end
end
-- Liste der normalen Felder
local fields = {
{"coach", "Trainer"},
{"opponent", "Gegner"}
}
-- Hauptfunktion
function p.main(frame)
-- Parameter der Vorlage holen
local args = frame:getParent().args
-- Grundparameter
local titel = args.titel or ""
-- Werte für Hin- und Rückspiel
local date_first_leg = args.date_first_leg or ""
local stadium_first_leg = args.stadium_first_leg or ""
local attendance_first_leg = args.result_first_leg or ""
local result_first_leg= args.result_first_leg or ""
local date_second_leg = args.date_second_leg or ""
local stadium_second_leg = args.stadium_second_leg or ""
local attendance_second_leg = args.result_first_leg or ""
local result_second_leg = args.result_second_leg or ""
-- Prüfen, ob ein Rückspiel vorhanden ist
local has_second_leg =
date_second_leg ~= "" or
stadium_second_leg ~= "" or
attendance_second_leg ~= "" or
result_second_leg ~= ""
-- Tabelle erstellen
local box = mw.html.create("table")
:addClass("infobox")
-- Titel
if titel ~= "" then
box
:tag("caption")
:wikitext(titel)
:done()
end
for _, field in ipairs(fields) do
local parameter = field[1]
local label = field[2]
local value = args[parameter]
addRow(box, label, value)
end
-- Spiele
if has_second_leg then
addRow(box, "Endergebnis", args.result or "")
addMatchRow(
box,
"Hinspiel",
date_first_leg,
stadium_first_leg,
attendance_first_leg,
result_first_leg
)
addMatchRow(
box,
"Rückspiel",
date_second_leg,
stadium_second_leg,
attendance_second_leg,
result_second_leg
)
else
addMatchRow(
box,
"Spiel",
date_first_leg,
stadium_first_leg,
result_first_leg
)
end
-- HTML zurückgeben
return tostring(box)
end
return p