Module:IconUtils

De Eco - Wiki Français
Aller à :navigation, rechercher

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)

    if not args.id or args.id == '' then
        return "Module:IconUtils 'id' must be specified."
    end

    local Icon = args.id .. "_Icon.png"
    local IconSize = args.size ~= '' and args.size or 28
    local IconStyle = args.style ~= '' and args.style or '1'

    -- Déterminer DisplayName
    local DisplayName = args.name
    if not DisplayName or DisplayName == '' then
        local Item = Utils.ItemSearchByID(args.id)
        if Item and Item.Name then
            local lang = Utils.getLanguageName()
            DisplayName = Item.Name[lang]
                      or Item.Name["French"]
                      or Item.Name["English"]
                      or args.id
        else
            DisplayName = args.id
        end
    end

    -- Gestion du link
    local IconLink = ""
    if args.link and args.link ~= '' then
        IconLink = '[[' .. args.link .. ']]'
    end

    local text = IconLink ~= '' and IconLink or DisplayName
    local IconTextLine = "  " .. text
    local IconTextBr = "<br>" .. text

    if IconStyle == '1' then
        return "[[file:"..Icon.."|"..IconSize.."px|link="..IconLink.."]]"
    end
    if IconStyle == '2' then
        return "[[file:"..Icon.."|"..IconSize.."px|link="..IconLink.."]]" .. IconTextLine
    end
    if IconStyle == '3' then
        return "[[file:"..Icon.."|"..IconSize.."px|link="..IconLink.."]]" .. IconTextBr
    end
    if IconStyle == '4' then
        return '<div class="IconFrame">[[file:'..Icon.."|"..IconSize.."px|link="..IconLink.."]]" .. IconTextBr .. "</div>"
    end
end

return p