Zuletzt bearbeitet vor 5 Monaten
von Xineohp1506

Modul:RezeptInfobox: Unterschied zwischen den Versionen

(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
 
(14 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 4: Zeile 4:
     local args = frame.args
     local args = frame.args
     local title = args["title"] or "Rezept"
     local title = args["title"] or "Rezept"
    local image = args["image"]
    local caption = args["caption"]
     local type = args["type"] or "Speise"
     local type = args["type"] or "Speise"
    local image = args["image"] ~= "" and args["image"] or p.getDefaultImage(type)
    local caption = args["caption"] ~= "" and args["caption"] or nil
     local difficulty = tonumber(args["difficulty"]) or 1
     local difficulty = tonumber(args["difficulty"]) or 1
     local strength = tonumber(args["strength"]) or 1
     local strength = tonumber(args["strength"]) or 1
Zeile 14: Zeile 14:


     -- Infobox-Header
     -- Infobox-Header
     table.insert(infobox, '{| class="wikitable infobox"')
     table.insert(infobox, '{| class="infobox"')
     table.insert(infobox, '|+ ' .. title)
     table.insert(infobox, '|+ class="infobox-title" | ' .. 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" class="infobox-image" | ' .. image)
         if caption then
         if caption then
             table.insert(infobox, '|-\n| ' .. caption)
             table.insert(infobox, '|-\n| colspan="2" class="infobox-caption" | ' .. caption)
         end
         end
     end
     end


     -- Schwierigkeitsgrad (Icons variieren je nach Typ)
     -- Schwierigkeitsgrad (Icons variieren je nach Typ)
     table.insert(infobox, '|-\n! Schwierigkeitsgrad\n| ' .. (type == "Speise" and p.getChefHatIcons(difficulty) or p.getCocktailGlassIcons(difficulty)))
     table.insert(infobox, '|-\n! class="infobox-label" | Schwierigkeitsgrad\n| class="infobox-data" | ' .. (type == "Speise" and p.getChefHatIcons(difficulty) or p.getCocktailGlassIcons(difficulty)))


     -- Stärke (Alkoholgehalt, angezeigt mit Twemoji12_1f4aa.svg)
     -- Stärke (Alkoholgehalt) nur für Getränke
     table.insert(infobox, '|-\n! Stärke\n| ' .. p.getStrengthIcons(strength))
     if type == "Getränk" then
        table.insert(infobox, '|-\n! class="infobox-label" | Stärke\n| class="infobox-data" | ' .. p.getStrengthIcons(strength))
    end


     -- Hinweise für Speisen
     -- Hinweise (für alle Rezepttypen)
     if type == "Speise" then
     local hints = p.getHints(args)
        local hints = p.getHints(args)
    if hints ~= "" then
        if hints ~= "" then
        table.insert(infobox, '|-\n! class="infobox-label" | Hinweise\n| class="infobox-data infobox-hints" | ' .. hints)
            table.insert(infobox, '|-\n! Hinweise\n| ' .. hints)
        end
     end
     end


     -- Kategorien
     -- Kategorien (in der Infobox anzeigen und als Kategorien setzen)
     if categories then
     if categories then
         table.insert(infobox, '|-\n! Kategorien\n| ' .. categories)
         table.insert(infobox, '|-\n! class="infobox-label" | Kategorien\n| class="infobox-data category" | ' .. categories)
        table.insert(infobox, p.setCategories(categories))
     end
     end


     table.insert(infobox, '|}')
     table.insert(infobox, '|}')
     return table.concat(infobox, "\n")
     return table.concat(infobox, "\n")
end
-- Funktion zum Abrufen des Standardbildes basierend auf dem Typ
function p.getDefaultImage(type)
    if type == "Getränk" then
        return '[[File:DefaultDrinkImage.webp|285px|alt=Standardbild für Getränke]]'
    else
        return '[[File:DefaultFoodImage.webp|285px|alt=Standardbild für Speisen]]'
    end
end
end


Zeile 55: Zeile 65:
     end
     end
     mw.smw.set("Has Difficulty=" .. level)
     mw.smw.set("Has Difficulty=" .. level)
     return table.concat(icons, " ")
     return '<div class="infobox-icons">' .. table.concat(icons, " ") .. '</div>'
end
end


Zeile 65: Zeile 75:
     end
     end
     mw.smw.set("Has Difficulty=" .. level)
     mw.smw.set("Has Difficulty=" .. level)
     return table.concat(icons, " ")
     return '<div class="infobox-icons">' .. table.concat(icons, " ") .. '</div>'
end
end


Zeile 75: Zeile 85:
     end
     end
     mw.smw.set("Has Strength=" .. level)
     mw.smw.set("Has Strength=" .. level)
     return table.concat(icons, " ")
     return '<div class="infobox-icons">' .. table.concat(icons, " ") .. '</div>'
end
end


-- Funktion zur Erzeugung der Hinweise für Speisen
-- Funktion zur Erzeugung der Hinweise für alle Rezepttypen
function p.getHints(args)
function p.getHints(args)
     local hints = {}
     local hints = {}
    -- Alkoholhinweis (ja/nein Switch)
     if args["alcohol"] == "ja" then
     if args["alcohol"] == "ja" then
         table.insert(hints, '[[File:MHWS_-_Alcoholism.svg|20px|Mit Alkohol|link=|alt=Mit Alkohol]]')
         table.insert(hints, '[[File:MHWS_-_Alcoholism.svg|20px|Mit Alkohol|link=|alt=Mit Alkohol]][[Category:Rezept:Mit Alkohol]]')
         mw.smw.set("Has RecipeHint=Mit Alkohol")
         mw.smw.set("Has RecipeHint=Mit Alkohol")
     end
     elseif args["alcohol"] == "nein" then
    if args["noalcohol"] == "ja" then
         table.insert(hints, '[[File:No_alcohol-1.svg|20px|Ohne Alkohol|link=|alt=Ohne Alkohol]][[Category:Rezept:Ohne Alkohol]]')
         table.insert(hints, '[[File:No_alcohol-1.svg|20px|Ohne Alkohol|link=|alt=Ohne Alkohol]]')
         mw.smw.set("Has RecipeHint=Ohne Alkohol")
         mw.smw.set("Has RecipeHint=Ohne Alkohol")
     end
     end
    -- Weitere Hinweise
     if args["vegetarian"] == "ja" then
     if args["vegetarian"] == "ja" then
         table.insert(hints, '[[File:Vegetarian-mark.svg|20px|Vegetarisch|link=|alt=Vegetarisch]]')
         table.insert(hints, '[[File:Vegetarian-mark.svg|20px|Vegetarisch|link=|alt=Vegetarisch]][[Category:Rezept:Vegetarisch]]')
         mw.smw.set("Has RecipeHint=Vegetarisch")
         mw.smw.set("Has RecipeHint=Vegetarisch")
     end
     end
     if args["vegan"] == "ja" then
     if args["vegan"] == "ja" then
         table.insert(hints, '[[File:Vegan_friendly_icon.svg|20px|Vegan|link=|alt=Vegan]]')
         table.insert(hints, '[[File:Vegan_friendly_icon.svg|20px|Vegan|link=|alt=Vegan]][[Category:Rezept:Vegan]]')
         mw.smw.set("Has RecipeHint=Vegan")
         mw.smw.set("Has RecipeHint=Vegan")
     end
     end
     return table.concat(hints, "<br>")
 
     return '<div class="infobox-icons">' .. table.concat(hints, " ") .. '</div>'
end
 
-- Funktion zum Setzen der Kategorien auf der Seite
function p.setCategories(categories)
    local categoryText = ""
    for category in string.gmatch(categories, "[^,]+") do
        categoryText = categoryText .. "[[Category:Rezept:" .. mw.text.trim(category) .. "]]\n"
    end
    return categoryText
end
end


return p
return p

Aktuelle Version vom 18. November 2024, 01:00 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 type = args["type"] or "Speise"
    local image = args["image"] ~= "" and args["image"] or p.getDefaultImage(type)
    local caption = args["caption"] ~= "" and args["caption"] or nil
    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="infobox"')
    table.insert(infobox, '|+ class="infobox-title" | ' .. title)

    -- Bild über die gesamte Breite der Infobox
    if image then
        table.insert(infobox, '|-\n| colspan="2" class="infobox-image" | ' .. image)
        if caption then
            table.insert(infobox, '|-\n| colspan="2" class="infobox-caption" | ' .. caption)
        end
    end

    -- Schwierigkeitsgrad (Icons variieren je nach Typ)
    table.insert(infobox, '|-\n! class="infobox-label" | Schwierigkeitsgrad\n| class="infobox-data" | ' .. (type == "Speise" and p.getChefHatIcons(difficulty) or p.getCocktailGlassIcons(difficulty)))

    -- Stärke (Alkoholgehalt) nur für Getränke
    if type == "Getränk" then
        table.insert(infobox, '|-\n! class="infobox-label" | Stärke\n| class="infobox-data" | ' .. p.getStrengthIcons(strength))
    end

    -- Hinweise (für alle Rezepttypen)
    local hints = p.getHints(args)
    if hints ~= "" then
        table.insert(infobox, '|-\n! class="infobox-label" | Hinweise\n| class="infobox-data infobox-hints" | ' .. hints)
    end

    -- Kategorien (in der Infobox anzeigen und als Kategorien setzen)
    if categories then
        table.insert(infobox, '|-\n! class="infobox-label" | Kategorien\n| class="infobox-data category" | ' .. categories)
        table.insert(infobox, p.setCategories(categories))
    end

    table.insert(infobox, '|}')
    return table.concat(infobox, "\n")
end

-- Funktion zum Abrufen des Standardbildes basierend auf dem Typ
function p.getDefaultImage(type)
    if type == "Getränk" then
        return '[[File:DefaultDrinkImage.webp|285px|alt=Standardbild für Getränke]]'
    else
        return '[[File:DefaultFoodImage.webp|285px|alt=Standardbild für Speisen]]'
    end
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="infobox-icons">' .. 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="infobox-icons">' .. 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="infobox-icons">' .. table.concat(icons, " ") .. '</div>'
end

-- Funktion zur Erzeugung der Hinweise für alle Rezepttypen
function p.getHints(args)
    local hints = {}

    -- Alkoholhinweis (ja/nein Switch)
    if args["alcohol"] == "ja" then
        table.insert(hints, '[[File:MHWS_-_Alcoholism.svg|20px|Mit Alkohol|link=|alt=Mit Alkohol]][[Category:Rezept:Mit Alkohol]]')
        mw.smw.set("Has RecipeHint=Mit Alkohol")
    elseif args["alcohol"] == "nein" then
        table.insert(hints, '[[File:No_alcohol-1.svg|20px|Ohne Alkohol|link=|alt=Ohne Alkohol]][[Category:Rezept:Ohne Alkohol]]')
        mw.smw.set("Has RecipeHint=Ohne Alkohol")
    end

    -- Weitere Hinweise
    if args["vegetarian"] == "ja" then
        table.insert(hints, '[[File:Vegetarian-mark.svg|20px|Vegetarisch|link=|alt=Vegetarisch]][[Category:Rezept: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]][[Category:Rezept:Vegan]]')
        mw.smw.set("Has RecipeHint=Vegan")
    end

    return '<div class="infobox-icons">' .. table.concat(hints, " ") .. '</div>'
end

-- Funktion zum Setzen der Kategorien auf der Seite
function p.setCategories(categories)
    local categoryText = ""
    for category in string.gmatch(categories, "[^,]+") do
        categoryText = categoryText .. "[[Category:Rezept:" .. mw.text.trim(category) .. "]]\n"
    end
    return categoryText
end

return p