« Module:IconUtils » : différence entre les versions

De Eco - Wiki Français
Aller à :navigation, rechercher
[version vérifiée][version vérifiée]
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 10 : Ligne 10 :
     end
     end


    -- récupère le nom automatiquement selon la langue (FR → EN → ID)
     local name = args.name or Utils.ItemNameFromID(args.id)
     local name = args.name or Utils.ItemNameFromID(args.id)


Ligne 43 : Ligne 42 :
         wikitext = '<div class="IconFrame">[[File:' .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]" .. IconTextBr .. "</div>"
         wikitext = '<div class="IconFrame">[[File:' .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]" .. IconTextBr .. "</div>"
     else
     else
        -- fallback simple
         wikitext = "[[File:" .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]"
         wikitext = "[[File:" .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]"
     end
     end

Version du 16 novembre 2025 à 11:23

La documentation pour ce module peut être créée à Module:IconUtils/doc

local p = {}

function p.main(param)
    local Utils = require('Module:Utils')
    local args = Utils.normalise(param)

    -- vérifie que l'id est fourni
    if not args.id or args.id == '' then
        return "Module:IconUtils : 'id' must be specified."
    end

    local name = args.name or Utils.ItemNameFromID(args.id)

    -- nom du fichier
    local Icon = args.id .. "_Icon.png"

    -- taille et style par défaut
    local IconSize = args.size or 28
    local IconStyle = args.style or "1"

    -- préparation du lien
    local IconLink = ""
    if args.link == "1" then
        IconLink = "[[" .. name .. "]]"
    elseif args.link and args.link ~= "" then
        IconLink = "[[" .. args.link .. "]]"
    end

    -- texte additionnel
    local IconTextLine = IconLink ~= "" and "  " .. IconLink or "  " .. name
    local IconTextBr   = IconLink ~= "" and "<br>" .. IconLink or "<br>" .. name

    -- construit le wikitext en fonction du style
    local wikitext = ""
    if IconStyle == "1" then
        wikitext = "[[File:" .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]"
    elseif IconStyle == "2" then
        wikitext = "[[File:" .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]" .. IconTextLine
    elseif IconStyle == "3" then
        wikitext = "[[File:" .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]" .. IconTextBr
    elseif IconStyle == "4" then
        wikitext = '<div class="IconFrame">[[File:' .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]" .. IconTextBr .. "</div>"
    else
        wikitext = "[[File:" .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]"
    end

    return wikitext
end

return p