« 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 5 : Ligne 5 :
     local args = Utils.normalise(param)
     local args = Utils.normalise(param)


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


     -- nom à afficher : si name fourni, on l'utilise, sinon fallback via Utils.ItemNameFromID
     -- 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)


    -- nom du fichier
     local Icon = args.id .. "_Icon.png"
     local Icon = args.id .. "_Icon.png"
    -- taille et style par défaut
     local IconSize = args.size or 28
     local IconSize = args.size or 28
     local IconStyle = args.style or "1"
     local IconStyle = args.style or "1"


    -- préparation du lien
     local IconLink = ""
     local IconLink = ""
     if args.link == "1" then
     if args.link == "1" then
Ligne 23 : Ligne 28 :
     end
     end


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


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


return p
return p

Version du 16 novembre 2025 à 11:21

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

    -- récupère le nom automatiquement selon la langue (FR → EN → ID)
    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
        -- fallback simple
        wikitext = "[[File:" .. Icon .. "|" .. IconSize .. "px" .. (IconLink ~= "" and "|link=" .. IconLink or "") .. "]]"
    end

    return wikitext
end

return p