(Die Seite wurde neu angelegt: „local p = {} function p.render(frame) local args = frame.args local title = args["title"] or "Rezept" local image = args["image"] local caption = args["caption"] local type = args["type"] or "Speise" local difficulty = tonumber(args["difficulty"]) or 1 local strength = tonumber(args["strength"]) or 1 local categories = args["categories"] local infobox = {} -- Infobox-Header table.insert(infobox, '{| class="wi…“) |
Keine Bearbeitungszusammenfassung |
||
Zeile 17: | Zeile 17: | ||
table.insert(infobox, '|+ ' .. title) | table.insert(infobox, '|+ ' .. title) | ||
-- Bild | -- Bild über die gesamte Breite der Infobox | ||
if image then | if image then | ||
table.insert(infobox, '|-\n| ' .. image) | table.insert(infobox, '|-\n| colspan="2" style="text-align: center;" | ' .. image) | ||
if caption then | if caption then | ||
table.insert(infobox, '|-\n| ' .. caption) | table.insert(infobox, '|-\n| colspan="2" style="text-align: center;" | ' .. caption) | ||
end | end | ||
end | end | ||
Zeile 55: | Zeile 55: | ||
end | end | ||
mw.smw.set("Has Difficulty=" .. level) | mw.smw.set("Has Difficulty=" .. level) | ||
return table.concat(icons, " ") | return '<div class="icon-row">' .. table.concat(icons, " ") .. '</div>' | ||
end | end | ||
Zeile 65: | Zeile 65: | ||
end | end | ||
mw.smw.set("Has Difficulty=" .. level) | mw.smw.set("Has Difficulty=" .. level) | ||
return table.concat(icons, " ") | return '<div class="icon-row">' .. table.concat(icons, " ") .. '</div>' | ||
end | end | ||
Zeile 75: | Zeile 75: | ||
end | end | ||
mw.smw.set("Has Strength=" .. level) | mw.smw.set("Has Strength=" .. level) | ||
return table.concat(icons, " ") | return '<div class="icon-row">' .. table.concat(icons, " ") .. '</div>' | ||
end | end | ||
Version vom 13. November 2024, 00:38 Uhr
Die Dokumentation für dieses Modul kann unter Modul:RezeptInfobox/Doku erstellt werden
local p = {}
function p.render(frame)
local args = frame.args
local title = args["title"] or "Rezept"
local image = args["image"]
local caption = args["caption"]
local type = args["type"] or "Speise"
local difficulty = tonumber(args["difficulty"]) or 1
local strength = tonumber(args["strength"]) or 1
local categories = args["categories"]
local infobox = {}
-- Infobox-Header
table.insert(infobox, '{| class="wikitable infobox"')
table.insert(infobox, '|+ ' .. title)
-- Bild über die gesamte Breite der Infobox
if image then
table.insert(infobox, '|-\n| colspan="2" style="text-align: center;" | ' .. image)
if caption then
table.insert(infobox, '|-\n| colspan="2" style="text-align: center;" | ' .. caption)
end
end
-- Schwierigkeitsgrad (Icons variieren je nach Typ)
table.insert(infobox, '|-\n! Schwierigkeitsgrad\n| ' .. (type == "Speise" and p.getChefHatIcons(difficulty) or p.getCocktailGlassIcons(difficulty)))
-- Stärke (Alkoholgehalt, angezeigt mit Twemoji12_1f4aa.svg)
table.insert(infobox, '|-\n! Stärke\n| ' .. p.getStrengthIcons(strength))
-- Hinweise für Speisen
if type == "Speise" then
local hints = p.getHints(args)
if hints ~= "" then
table.insert(infobox, '|-\n! Hinweise\n| ' .. hints)
end
end
-- Kategorien
if categories then
table.insert(infobox, '|-\n! Kategorien\n| ' .. categories)
end
table.insert(infobox, '|}')
return table.concat(infobox, "\n")
end
-- Funktion zur Anzeige der Schwierigkeitsgrade (Kochmützen)
function p.getChefHatIcons(level)
local icons = {}
for i = 1, math.min(level, 5) do
table.insert(icons, '[[File:One_chef%27s_hat.png|20px|link=]]')
end
mw.smw.set("Has Difficulty=" .. level)
return '<div class="icon-row">' .. table.concat(icons, " ") .. '</div>'
end
-- Funktion zur Anzeige der Schwierigkeitsgrade (Cocktailgläser)
function p.getCocktailGlassIcons(level)
local icons = {}
for i = 1, math.min(level, 5) do
table.insert(icons, '[[File:Twemoji12_1f378.svg|20px|link=]]')
end
mw.smw.set("Has Difficulty=" .. level)
return '<div class="icon-row">' .. table.concat(icons, " ") .. '</div>'
end
-- Funktion zur Anzeige der Stärke (Alkoholgehalt)
function p.getStrengthIcons(level)
local icons = {}
for i = 1, math.min(level, 5) do
table.insert(icons, '[[File:Twemoji12_1f4aa.svg|20px|link=]]')
end
mw.smw.set("Has Strength=" .. level)
return '<div class="icon-row">' .. table.concat(icons, " ") .. '</div>'
end
-- Funktion zur Erzeugung der Hinweise für Speisen
function p.getHints(args)
local hints = {}
if args["alcohol"] == "ja" then
table.insert(hints, '[[File:MHWS_-_Alcoholism.svg|20px|Mit Alkohol|link=|alt=Mit Alkohol]]')
mw.smw.set("Has RecipeHint=Mit Alkohol")
end
if args["noalcohol"] == "ja" then
table.insert(hints, '[[File:No_alcohol-1.svg|20px|Ohne Alkohol|link=|alt=Ohne Alkohol]]')
mw.smw.set("Has RecipeHint=Ohne Alkohol")
end
if args["vegetarian"] == "ja" then
table.insert(hints, '[[File:Vegetarian-mark.svg|20px|Vegetarisch|link=|alt=Vegetarisch]]')
mw.smw.set("Has RecipeHint=Vegetarisch")
end
if args["vegan"] == "ja" then
table.insert(hints, '[[File:Vegan_friendly_icon.svg|20px|Vegan|link=|alt=Vegan]]')
mw.smw.set("Has RecipeHint=Vegan")
end
return table.concat(hints, "<br>")
end
return p